1 /** 2 * Copyright (C) 2013 Flowroute LLC (flowroute.com) 3 * 4 * This file is part of Kamailio, a free SIP server. 5 * 6 * This file is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version 10 * 11 * 12 * This file is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * 21 */ 22 23 #ifndef _JANSSONRPC_REQUEST_H_ 24 #define _JANSSONRPC_REQUEST_H_ 25 26 #include "janssonrpc_io.h" 27 #include "janssonrpc_server.h" 28 29 #define JSONRPC_DEFAULT_HTABLE_SIZE 500 30 #define JSONRPC_MAX_ID 1000000 31 #define RETRY_MAX_TIME 60000 /* milliseconds */ 32 33 typedef enum { 34 RPC_REQUEST, 35 RPC_NOTIFICATION 36 } rpc_type; 37 38 typedef struct jsonrpc_request jsonrpc_request_t; 39 struct jsonrpc_request { 40 rpc_type type; 41 int id; 42 jsonrpc_request_t *next; /* pkg */ 43 jsonrpc_server_t* server; /* shm */ 44 jsonrpc_req_cmd_t* cmd; /* shm */ 45 json_t* payload; 46 struct event* timeout_ev; /* pkg */ 47 struct event* retry_ev; /* pkg */ 48 int retry; 49 unsigned int ntries; 50 unsigned int timeout; 51 }; 52 53 extern jsonrpc_request_t* request_table[JSONRPC_DEFAULT_HTABLE_SIZE]; 54 55 jsonrpc_request_t* create_request(jsonrpc_req_cmd_t* cmd); 56 void print_request(jsonrpc_request_t* req); 57 jsonrpc_request_t* pop_request(int id); 58 unsigned int requests_using_server(jsonrpc_server_t* server); 59 void free_request(jsonrpc_request_t* req); 60 int schedule_retry(jsonrpc_request_t* req); 61 62 int jsonrpc_send(str conn, jsonrpc_request_t* req, bool notify_only); 63 void fail_request(int code, jsonrpc_request_t* req, char* error_str); 64 65 #endif /* _JSONRPC_H_ */ 66