diff --git a/src/modules/jsonrpcc/jsonrpc.c b/src/modules/jsonrpcc/jsonrpc.c index 006c2ef24c9..fcaa1db4b3f 100644 --- a/src/modules/jsonrpcc/jsonrpc.c +++ b/src/modules/jsonrpcc/jsonrpc.c @@ -32,23 +32,24 @@ #include "jsonrpc.h" -jsonrpc_request_t * request_table[JSONRPC_DEFAULT_HTABLE_SIZE] = {0}; +jsonrpc_request_t *request_table[JSONRPC_DEFAULT_HTABLE_SIZE] = {0}; int next_id = 1; -jsonrpc_request_t* get_request(int id); -int store_request(jsonrpc_request_t* req); +jsonrpc_request_t *get_request(int id); +int store_request(jsonrpc_request_t *req); -jsonrpc_request_t* build_jsonrpc_request(char *method, json_object *params, char *cbdata, int (*cbfunc)(json_object*, char*, int)) +jsonrpc_request_t *build_jsonrpc_request(char *method, json_object *params, + char *cbdata, int (*cbfunc)(json_object *, char *, int)) { - if (next_id>JSONRPC_MAX_ID) { + if(next_id > JSONRPC_MAX_ID) { next_id = 1; } else { next_id++; } jsonrpc_request_t *req = pkg_malloc(sizeof(jsonrpc_request_t)); - if (!req) { + if(!req) { LM_ERR("Out of memory!"); return 0; } @@ -57,20 +58,22 @@ jsonrpc_request_t* build_jsonrpc_request(char *method, json_object *params, char req->cbdata = cbdata; req->next = NULL; req->timer_ev = NULL; - if (!store_request(req)) + if(!store_request(req)) return 0; req->payload = json_object_new_object(); json_object_object_add(req->payload, "id", json_object_new_int(next_id)); - json_object_object_add(req->payload, "jsonrpc", json_object_new_string("2.0")); - json_object_object_add(req->payload, "method", json_object_new_string(method)); + json_object_object_add( + req->payload, "jsonrpc", json_object_new_string("2.0")); + json_object_object_add( + req->payload, "method", json_object_new_string(method)); json_object_object_add(req->payload, "params", params); return req; } -json_object* build_jsonrpc_notification(char *method, json_object *params) +json_object *build_jsonrpc_notification(char *method, json_object *params) { json_object *req = json_object_new_object(); json_object_object_add(req, "jsonrpc", json_object_new_string("2.0")); @@ -90,19 +93,19 @@ int handle_jsonrpc_response(json_object *response) json_object_object_get_ex(response, "id", &_id); id = json_object_get_int(_id); - if (!(req = get_request(id))) { + if(!(req = get_request(id))) { json_object_put(response); return -1; } json_object_object_get_ex(response, "result", &result); - if (result) { + if(result) { req->cbfunc(result, req->cbdata, 0); } else { json_object *error = NULL; json_object_object_get_ex(response, "error", &error); - if (error) { + if(error) { req->cbfunc(error, req->cbdata, 1); } else { LM_ERR("Response received with neither a result nor an error.\n"); @@ -110,7 +113,7 @@ int handle_jsonrpc_response(json_object *response) } } - if (req->timer_ev) { + if(req->timer_ev) { close(req->timerfd); event_del(req->timer_ev); pkg_free(req->timer_ev); @@ -121,25 +124,27 @@ int handle_jsonrpc_response(json_object *response) return 1; } -int id_hash(int id) { +int id_hash(int id) +{ return (id % JSONRPC_DEFAULT_HTABLE_SIZE); } -jsonrpc_request_t* get_request(int id) { +jsonrpc_request_t *get_request(int id) +{ int key = id_hash(id); jsonrpc_request_t *req, *prev_req = NULL; req = request_table[key]; - while (req && req->id != id) { + while(req && req->id != id) { prev_req = req; - if (!(req = req->next)) { + if(!(req = req->next)) { break; }; } - if (req && req->id == id) { - if (prev_req != NULL) { - prev_req-> next = req->next; + if(req && req->id == id) { + if(prev_req != NULL) { + prev_req->next = req->next; } else { request_table[key] = NULL; } @@ -148,23 +153,25 @@ jsonrpc_request_t* get_request(int id) { return 0; } -void void_jsonrpc_request(int id) { +void void_jsonrpc_request(int id) +{ get_request(id); } -int store_request(jsonrpc_request_t* req) { +int store_request(jsonrpc_request_t *req) +{ int key = id_hash(req->id); - jsonrpc_request_t* existing; + jsonrpc_request_t *existing; - if ((existing = request_table[key])) { /* collision */ - jsonrpc_request_t* i; - for(i=existing; i; i=i->next) { - if (i == NULL) { + if((existing = request_table[key])) { /* collision */ + jsonrpc_request_t *i; + for(i = existing; i; i = i->next) { + if(i == NULL) { i = req; LM_ERR("!!!!!!!"); return 1; } - if (i->next == NULL) { + if(i->next == NULL) { i->next = req; return 1; } @@ -174,4 +181,3 @@ int store_request(jsonrpc_request_t* req) { } return 1; } - diff --git a/src/modules/jsonrpcc/jsonrpc.h b/src/modules/jsonrpcc/jsonrpc.h index 9aa0aeb026f..f0f2b6772f9 100644 --- a/src/modules/jsonrpcc/jsonrpc.h +++ b/src/modules/jsonrpcc/jsonrpc.h @@ -34,18 +34,19 @@ typedef struct jsonrpc_request jsonrpc_request_t; -struct jsonrpc_request { +struct jsonrpc_request +{ int id, timerfd; jsonrpc_request_t *next; - int (*cbfunc)(json_object*, char*, int); + int (*cbfunc)(json_object *, char *, int); char *cbdata; json_object *payload; - struct event *timer_ev; + struct event *timer_ev; }; -json_object* build_jsonrpc_notification(char *method, json_object *params); -jsonrpc_request_t* build_jsonrpc_request(char *method, json_object *params, char *cbdata, int (*cbfunc)(json_object*, char*, int)); +json_object *build_jsonrpc_notification(char *method, json_object *params); +jsonrpc_request_t *build_jsonrpc_request(char *method, json_object *params, + char *cbdata, int (*cbfunc)(json_object *, char *, int)); int handle_jsonrpc_response(json_object *response); void void_jsonrpc_request(int id); #endif /* _JSONRPC_H_ */ - diff --git a/src/modules/jsonrpcc/jsonrpc_io.c b/src/modules/jsonrpcc/jsonrpc_io.c index 81627659fb1..064bfa53833 100644 --- a/src/modules/jsonrpcc/jsonrpc_io.c +++ b/src/modules/jsonrpcc/jsonrpc_io.c @@ -41,20 +41,30 @@ #include "jsonrpc.h" #include "netstring.h" -#define CHECK_MALLOC_VOID(p) if(!p) {LM_ERR("Out of memory!"); return;} -#define CHECK_MALLOC(p) if(!p) {LM_ERR("Out of memory!"); return -1;} +#define CHECK_MALLOC_VOID(p) \ + if(!p) { \ + LM_ERR("Out of memory!"); \ + return; \ + } +#define CHECK_MALLOC(p) \ + if(!p) { \ + LM_ERR("Out of memory!"); \ + return -1; \ + } -struct jsonrpc_server { +struct jsonrpc_server +{ char *host; - int port, socket, status, conn_attempts; + int port, socket, status, conn_attempts; struct jsonrpc_server *next; struct event *ev; struct itimerspec *timer; }; -struct jsonrpc_server_group { +struct jsonrpc_server_group +{ struct jsonrpc_server *next_server; - int priority; + int priority; struct jsonrpc_server_group *next_group; }; @@ -64,32 +74,31 @@ struct jsonrpc_server_group *server_group; void socket_cb(int fd, short event, void *arg); void cmd_pipe_cb(int fd, short event, void *arg); -int set_non_blocking(int fd); -int parse_servers(char *_servers, struct jsonrpc_server_group **group_ptr); -int connect_servers(struct jsonrpc_server_group *group); -int connect_server(struct jsonrpc_server *server); -int handle_server_failure(struct jsonrpc_server *server); +int set_non_blocking(int fd); +int parse_servers(char *_servers, struct jsonrpc_server_group **group_ptr); +int connect_servers(struct jsonrpc_server_group *group); +int connect_server(struct jsonrpc_server *server); +int handle_server_failure(struct jsonrpc_server *server); /* module config from jsonrpc_mod.c */ -int _jsonrpcc_max_conn_retry = 0; /* max retries to connect. -1 forever 0 none */ +int _jsonrpcc_max_conn_retry = + 0; /* max retries to connect. -1 forever 0 none */ -int jsonrpc_io_child_process(int cmd_pipe, char* _servers) +int jsonrpc_io_child_process(int cmd_pipe, char *_servers) { - if (parse_servers(_servers, &server_group) != 0) - { + if(parse_servers(_servers, &server_group) != 0) { LM_ERR("servers parameter could not be parsed\n"); return -1; } event_init(); - + struct event pipe_ev; set_non_blocking(cmd_pipe); event_set(&pipe_ev, cmd_pipe, EV_READ | EV_PERSIST, cmd_pipe_cb, &pipe_ev); event_add(&pipe_ev, NULL); - if (!connect_servers(server_group)) - { + if(!connect_servers(server_group)) { LM_WARN("failed to connect to any servers\n"); } @@ -97,10 +106,10 @@ int jsonrpc_io_child_process(int cmd_pipe, char* _servers) return 0; } -void timeout_cb(int fd, short event, void *arg) +void timeout_cb(int fd, short event, void *arg) { LM_ERR("message timeout\n"); - jsonrpc_request_t *req = (jsonrpc_request_t*)arg; + jsonrpc_request_t *req = (jsonrpc_request_t *)arg; json_object *error = json_object_new_string("timeout"); void_jsonrpc_request(req->id); close(req->timerfd); @@ -110,37 +119,37 @@ void timeout_cb(int fd, short event, void *arg) pkg_free(req); } -int result_cb(json_object *result, char *data, int error) +int result_cb(json_object *result, char *data, int error) { - struct jsonrpc_pipe_cmd *cmd = (struct jsonrpc_pipe_cmd*)data; + struct jsonrpc_pipe_cmd *cmd = (struct jsonrpc_pipe_cmd *)data; pv_spec_t *dst = cmd->cb_pv; pv_value_t val; - const char* res = json_object_get_string(result); + const char *res = json_object_get_string(result); - val.rs.s = (char*)res; + val.rs.s = (char *)res; val.rs.len = strlen(res); val.flags = PV_VAL_STR; dst->setf(0, &dst->pvp, (int)EQ_T, &val); int n; - if (error) { + if(error) { n = route_get(&main_rt, cmd->err_route); } else { n = route_get(&main_rt, cmd->cb_route); } struct action *a = main_rt.rlist[n]; - tmb.t_continue(cmd->t_hash, cmd->t_label, a); + tmb.t_continue(cmd->t_hash, cmd->t_label, a); free_pipe_cmd(cmd); return 0; } -int (*res_cb)(json_object*, char*, int) = &result_cb; +int (*res_cb)(json_object *, char *, int) = &result_cb; void cmd_pipe_cb(int fd, short event, void *arg) @@ -153,7 +162,7 @@ void cmd_pipe_cb(int fd, short event, void *arg) json_object *params; /* struct event *ev = (struct event*)arg; */ - if (read(fd, &cmd, sizeof(cmd)) != sizeof(cmd)) { + if(read(fd, &cmd, sizeof(cmd)) != sizeof(cmd)) { LM_ERR("failed to read from command pipe: %s\n", strerror(errno)); return; } @@ -162,33 +171,32 @@ void cmd_pipe_cb(int fd, short event, void *arg) params = json_tokener_parse(cmd->params); - if (cmd->notify_only) { + if(cmd->notify_only) { payload = build_jsonrpc_notification(cmd->method, params); } else { - req = build_jsonrpc_request(cmd->method, params, (char*)cmd, res_cb); - if (req) + req = build_jsonrpc_request(cmd->method, params, (char *)cmd, res_cb); + if(req) payload = req->payload; } - if (!payload) { - LM_ERR("Failed to build jsonrpc_request_t (method: %s, params: %s)\n", cmd->method, cmd->params); + if(!payload) { + LM_ERR("Failed to build jsonrpc_request_t (method: %s, params: %s)\n", + cmd->method, cmd->params); goto error; } - char *json = (char*)json_object_get_string(payload); + char *json = (char *)json_object_get_string(payload); bytes = netstring_encode_new(&ns, json, (size_t)strlen(json)); struct jsonrpc_server_group *g; int sent = 0; - for (g = server_group; g != NULL; g = g->next_group) - { + for(g = server_group; g != NULL; g = g->next_group) { struct jsonrpc_server *s, *first = NULL; - for (s = g->next_server; s != first; s = s->next) - { - if (first == NULL) first = s; - if (s->status == JSONRPC_SERVER_CONNECTED) { - if (send(s->socket, ns, bytes, 0) == bytes) - { + for(s = g->next_server; s != first; s = s->next) { + if(first == NULL) + first = s; + if(s->status == JSONRPC_SERVER_CONNECTED) { + if(send(s->socket, ns, bytes, 0) == bytes) { sent = 1; break; } else { @@ -197,17 +205,19 @@ void cmd_pipe_cb(int fd, short event, void *arg) } g->next_server = s->next; } - if (sent) { + if(sent) { break; } else { - LM_WARN("Failed to send on priority group %d... proceeding to next priority group.\n", g->priority); + LM_WARN("Failed to send on priority group %d... proceeding to next " + "priority group.\n", + g->priority); } } - if (sent && req) { + if(sent && req) { int timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); - if (timerfd == -1) { + if(timerfd == -1) { LM_ERR("Could not create timerfd."); goto error; } @@ -218,10 +228,9 @@ void cmd_pipe_cb(int fd, short event, void *arg) itime->it_interval.tv_sec = 0; itime->it_interval.tv_nsec = 0; - itime->it_value.tv_sec = JSONRPC_TIMEOUT/1000; + itime->it_value.tv_sec = JSONRPC_TIMEOUT / 1000; itime->it_value.tv_nsec = (JSONRPC_TIMEOUT % 1000) * 1000000; - if (timerfd_settime(timerfd, 0, itime, NULL) == -1) - { + if(timerfd_settime(timerfd, 0, itime, NULL) == -1) { LM_ERR("Could not set timer."); pkg_free(itime); goto error; @@ -229,15 +238,16 @@ void cmd_pipe_cb(int fd, short event, void *arg) pkg_free(itime); struct event *timer_ev = pkg_malloc(sizeof(struct event)); CHECK_MALLOC_VOID(timer_ev); - event_set(timer_ev, timerfd, EV_READ, timeout_cb, req); + event_set(timer_ev, timerfd, EV_READ, timeout_cb, req); if(event_add(timer_ev, NULL) == -1) { - LM_ERR("event_add failed while setting request timer (%s).", strerror(errno)); + LM_ERR("event_add failed while setting request timer (%s).", + strerror(errno)); goto error; } req->timer_ev = timer_ev; - } else if (!sent) { + } else if(!sent) { LM_ERR("Request could not be sent... no more failover groups.\n"); - if (req) { + if(req) { json_object *error = json_object_new_string("failure"); void_jsonrpc_request(req->id); req->cbfunc(error, req->cbdata, 1); @@ -246,23 +256,27 @@ void cmd_pipe_cb(int fd, short event, void *arg) pkg_free(ns); json_object_put(payload); - if (cmd->notify_only) free_pipe_cmd(cmd); + if(cmd->notify_only) + free_pipe_cmd(cmd); return; error: - if(ns) pkg_free(ns); - if(payload) json_object_put(payload); - if (cmd->notify_only) free_pipe_cmd(cmd); + if(ns) + pkg_free(ns); + if(payload) + json_object_put(payload); + if(cmd->notify_only) + free_pipe_cmd(cmd); return; } void socket_cb(int fd, short event, void *arg) -{ - struct jsonrpc_server *server = (struct jsonrpc_server*)arg; +{ + struct jsonrpc_server *server = (struct jsonrpc_server *)arg; - if (event != EV_READ) { + if(event != EV_READ) { LM_ERR("unexpected socket event (%d)\n", event); - handle_server_failure(server); + handle_server_failure(server); return; } @@ -270,15 +284,15 @@ void socket_cb(int fd, short event, void *arg) int retval = netstring_read_fd(fd, &netstring); - if (retval != 0) { + if(retval != 0) { LM_ERR("bad netstring (%d)\n", retval); handle_server_failure(server); return; - } + } struct json_object *res = json_tokener_parse(netstring); - if (res) { + if(res) { handle_jsonrpc_response(res); json_object_put(res); } else { @@ -293,10 +307,10 @@ int set_non_blocking(int fd) int flags; flags = fcntl(fd, F_GETFL); - if (flags < 0) + if(flags < 0) return flags; flags |= O_NONBLOCK; - if (fcntl(fd, F_SETFL, flags) < 0) + if(fcntl(fd, F_SETFL, flags) < 0) return -1; return 0; @@ -304,62 +318,61 @@ int set_non_blocking(int fd) int parse_servers(char *_servers, struct jsonrpc_server_group **group_ptr) { - char cpy[strlen(_servers)+1]; + char cpy[strlen(_servers) + 1]; char *servers = strcpy(cpy, _servers); struct jsonrpc_server_group *group = NULL; /* parse servers string */ char *token = strtok(servers, ":"); - while (token != NULL) - { + while(token != NULL) { char *host, *port_s, *priority_s, *tail; int port, priority; host = token; /* validate domain */ - if (!(isalpha(host[0]) || isdigit(host[0]))) { + if(!(isalpha(host[0]) || isdigit(host[0]))) { LM_ERR("invalid domain (1st char is '%c')\n", host[0]); return -1; } int i; - for (i=1; ihost = h; server->port = port; server->status = JSONRPC_SERVER_DISCONNECTED; @@ -370,45 +383,42 @@ int parse_servers(char *_servers, struct jsonrpc_server_group **group_ptr) /* search for a server group with this server's priority */ struct jsonrpc_server_group *selected_group = NULL; - for (selected_group=group; selected_group != NULL; selected_group=selected_group->next_group) - { - if (selected_group->priority == priority) break; + for(selected_group = group; selected_group != NULL; + selected_group = selected_group->next_group) { + if(selected_group->priority == priority) + break; } - - if (selected_group == NULL) { + + if(selected_group == NULL) { group_cnt++; LM_INFO("Creating group for priority %d\n", priority); /* this is the first server for this priority... link it to itself */ server->next = server; - + selected_group = pkg_malloc(sizeof(struct jsonrpc_server_group)); CHECK_MALLOC(selected_group); memset(selected_group, 0, sizeof(struct jsonrpc_server_group)); selected_group->priority = priority; selected_group->next_server = server; - + /* insert the group properly in the linked list */ struct jsonrpc_server_group *x, *pg; pg = NULL; - if (group == NULL) - { + if(group == NULL) { group = selected_group; group->next_group = NULL; } else { - for (x = group; x != NULL; x = x->next_group) - { - if (priority > x->priority) - { - if (pg == NULL) - { + for(x = group; x != NULL; x = x->next_group) { + if(priority > x->priority) { + if(pg == NULL) { group = selected_group; } else { pg->next_group = selected_group; } selected_group->next_group = x; break; - } else if (x->next_group == NULL) { + } else if(x->next_group == NULL) { x->next_group = selected_group; break; } else { @@ -429,34 +439,37 @@ int parse_servers(char *_servers, struct jsonrpc_server_group **group_ptr) return 0; } -int connect_server(struct jsonrpc_server *server) -{ - struct sockaddr_in server_addr; - struct hostent *hp; +int connect_server(struct jsonrpc_server *server) +{ + struct sockaddr_in server_addr; + struct hostent *hp; memset(&server_addr, 0, sizeof(struct sockaddr_in)); server_addr.sin_family = AF_INET; - server_addr.sin_port = htons(server->port); + server_addr.sin_port = htons(server->port); hp = gethostbyname(server->host); - if (hp == NULL) { - LM_ERR("gethostbyname(%s) failed with h_errno=%d.\n", server->host, h_errno); + if(hp == NULL) { + LM_ERR("gethostbyname(%s) failed with h_errno=%d.\n", server->host, + h_errno); handle_server_failure(server); return -1; } memcpy(&(server_addr.sin_addr.s_addr), hp->h_addr, hp->h_length); - int sockfd = socket(AF_INET,SOCK_STREAM,0); + int sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (connect(sockfd, (struct sockaddr *)&server_addr, sizeof(struct sockaddr_in))) { - LM_WARN("Failed to connect to %s on port %d... %s\n", server->host, server->port, strerror(errno)); + if(connect(sockfd, (struct sockaddr *)&server_addr, + sizeof(struct sockaddr_in))) { + LM_WARN("Failed to connect to %s on port %d... %s\n", server->host, + server->port, strerror(errno)); handle_server_failure(server); return -1; } - if (set_non_blocking(sockfd) != 0) - { - LM_WARN("Failed to set socket (%s:%d) to non blocking.\n", server->host, server->port); + if(set_non_blocking(sockfd) != 0) { + LM_WARN("Failed to set socket (%s:%d) to non blocking.\n", server->host, + server->port); handle_server_failure(server); return -1; } @@ -473,21 +486,19 @@ int connect_server(struct jsonrpc_server *server) return 0; } -int connect_servers(struct jsonrpc_server_group *group) +int connect_servers(struct jsonrpc_server_group *group) { int connected_servers = 0; - for (;group != NULL; group = group->next_group) - { + for(; group != NULL; group = group->next_group) { struct jsonrpc_server *s, *first = NULL; LM_INFO("Connecting to servers for priority %d:\n", group->priority); - for (s=group->next_server;s!=first;s=s->next) - { - if (connect_server(s) == 0) - { + for(s = group->next_server; s != first; s = s->next) { + if(connect_server(s) == 0) { connected_servers++; LM_INFO("Connected to host %s on port %d\n", s->host, s->port); } - if (first == NULL) first = s; + if(first == NULL) + first = s; } } return connected_servers; @@ -496,14 +507,14 @@ int connect_servers(struct jsonrpc_server_group *group) void reconnect_cb(int fd, short event, void *arg) { LM_INFO("Attempting to reconnect now."); - struct jsonrpc_server *server = (struct jsonrpc_server*)arg; - - if (server->status == JSONRPC_SERVER_CONNECTED) { + struct jsonrpc_server *server = (struct jsonrpc_server *)arg; + + if(server->status == JSONRPC_SERVER_CONNECTED) { LM_WARN("Trying to connect an already connected server."); return; } - if (server->ev != NULL) { + if(server->ev != NULL) { event_del(server->ev); pkg_free(server->ev); server->ev = NULL; @@ -517,27 +528,30 @@ void reconnect_cb(int fd, short event, void *arg) int handle_server_failure(struct jsonrpc_server *server) { - LM_INFO("Setting timer to reconnect to %s on port %d in %d seconds.\n", server->host, server->port, JSONRPC_RECONNECT_INTERVAL); + LM_INFO("Setting timer to reconnect to %s on port %d in %d seconds.\n", + server->host, server->port, JSONRPC_RECONNECT_INTERVAL); - if (server->socket) + if(server->socket) close(server->socket); server->socket = 0; - if (server->ev != NULL) { + if(server->ev != NULL) { event_del(server->ev); pkg_free(server->ev); server->ev = NULL; } server->status = JSONRPC_SERVER_FAILURE; server->conn_attempts--; - if(_jsonrpcc_max_conn_retry!=-1 && server->conn_attempts<0) { - LM_ERR("max reconnect attempts. No further attempts will be made to reconnect this server."); + if(_jsonrpcc_max_conn_retry != -1 && server->conn_attempts < 0) { + LM_ERR("max reconnect attempts. No further attempts will be made to " + "reconnect this server."); return -1; } int timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); - - if (timerfd == -1) { - LM_ERR("Could not create timerfd to reschedule connection. No further attempts will be made to reconnect this server."); + + if(timerfd == -1) { + LM_ERR("Could not create timerfd to reschedule connection. No further " + "attempts will be made to reconnect this server."); return -1; } @@ -545,21 +559,23 @@ int handle_server_failure(struct jsonrpc_server *server) CHECK_MALLOC(itime); itime->it_interval.tv_sec = 0; itime->it_interval.tv_nsec = 0; - + itime->it_value.tv_sec = JSONRPC_RECONNECT_INTERVAL; itime->it_value.tv_nsec = 0; - - if (timerfd_settime(timerfd, 0, itime, NULL) == -1) - { - LM_ERR("Could not set timer to reschedule connection. No further attempts will be made to reconnect this server."); + + if(timerfd_settime(timerfd, 0, itime, NULL) == -1) { + LM_ERR("Could not set timer to reschedule connection. No further " + "attempts will be made to reconnect this server."); return -1; } LM_INFO("timerfd value is %d\n", timerfd); struct event *timer_ev = pkg_malloc(sizeof(struct event)); CHECK_MALLOC(timer_ev); - event_set(timer_ev, timerfd, EV_READ, reconnect_cb, server); + event_set(timer_ev, timerfd, EV_READ, reconnect_cb, server); if(event_add(timer_ev, NULL) == -1) { - LM_ERR("event_add failed while rescheduling connection (%s). No further attempts will be made to reconnect this server.", strerror(errno)); + LM_ERR("event_add failed while rescheduling connection (%s). No " + "further attempts will be made to reconnect this server.", + strerror(errno)); return -1; } server->ev = timer_ev; @@ -568,17 +584,17 @@ int handle_server_failure(struct jsonrpc_server *server) } -void free_pipe_cmd(struct jsonrpc_pipe_cmd *cmd) +void free_pipe_cmd(struct jsonrpc_pipe_cmd *cmd) { - if (cmd->method) + if(cmd->method) shm_free(cmd->method); - if (cmd->params) + if(cmd->params) shm_free(cmd->params); - if (cmd->cb_route) + if(cmd->cb_route) shm_free(cmd->cb_route); - if (cmd->err_route) + if(cmd->err_route) shm_free(cmd->err_route); - if (cmd->cb_pv) + if(cmd->cb_pv) shm_free(cmd->cb_pv); shm_free(cmd); } diff --git a/src/modules/jsonrpcc/jsonrpc_io.h b/src/modules/jsonrpcc/jsonrpc_io.h index 63efb69e6b1..c76e0cdd87f 100644 --- a/src/modules/jsonrpcc/jsonrpc_io.h +++ b/src/modules/jsonrpcc/jsonrpc_io.h @@ -27,17 +27,17 @@ #include "../../core/route_struct.h" #include "../../core/pvar.h" -#define JSONRPC_SERVER_CONNECTED 1 +#define JSONRPC_SERVER_CONNECTED 1 #define JSONRPC_SERVER_DISCONNECTED 2 -#define JSONRPC_SERVER_FAILURE 3 +#define JSONRPC_SERVER_FAILURE 3 /* interval (in seconds) at which failed servers are retried */ -#define JSONRPC_RECONNECT_INTERVAL 3 +#define JSONRPC_RECONNECT_INTERVAL 3 /* time (in ms) after which the error route is called */ -#define JSONRPC_TIMEOUT 500 +#define JSONRPC_TIMEOUT 500 -struct jsonrpc_pipe_cmd +struct jsonrpc_pipe_cmd { char *method, *params, *cb_route, *err_route; unsigned int t_hash, t_label, notify_only; @@ -45,7 +45,7 @@ struct jsonrpc_pipe_cmd struct sip_msg *msg; }; -int jsonrpc_io_child_process(int data_pipe, char* servers); -void free_pipe_cmd(struct jsonrpc_pipe_cmd *cmd); +int jsonrpc_io_child_process(int data_pipe, char *servers); +void free_pipe_cmd(struct jsonrpc_pipe_cmd *cmd); #endif /* _JSONRPC_IO_H_ */ diff --git a/src/modules/jsonrpcc/jsonrpc_request.c b/src/modules/jsonrpcc/jsonrpc_request.c index 63af54dfe18..bb30b0da779 100644 --- a/src/modules/jsonrpcc/jsonrpc_request.c +++ b/src/modules/jsonrpcc/jsonrpc_request.c @@ -31,49 +31,48 @@ extern struct tm_binds tmb; -int memory_error() { +int memory_error() +{ LM_ERR("Out of memory!"); return -1; } -int jsonrpc_request(struct sip_msg* _m, char* _method, char* _params, char* _cb_route, char* _err_route, char* _cb_pv) +int jsonrpc_request(struct sip_msg *_m, char *_method, char *_params, + char *_cb_route, char *_err_route, char *_cb_pv) { - str method; - str params; - str cb_route; - str err_route; - + str method; + str params; + str cb_route; + str err_route; - if (fixup_get_svalue(_m, (gparam_p)_method, &method) != 0) { + + if(fixup_get_svalue(_m, (gparam_p)_method, &method) != 0) { LM_ERR("cannot get method value\n"); return -1; } - if (fixup_get_svalue(_m, (gparam_p)_params, ¶ms) != 0) { + if(fixup_get_svalue(_m, (gparam_p)_params, ¶ms) != 0) { LM_ERR("cannot get params value\n"); return -1; } - if (fixup_get_svalue(_m, (gparam_p)_cb_route, &cb_route) != 0) { + if(fixup_get_svalue(_m, (gparam_p)_cb_route, &cb_route) != 0) { LM_ERR("cannot get cb_route value\n"); return -1; } - if (fixup_get_svalue(_m, (gparam_p)_err_route, &err_route) != 0) { + if(fixup_get_svalue(_m, (gparam_p)_err_route, &err_route) != 0) { LM_ERR("cannot get err_route value\n"); return -1; } tm_cell_t *t = 0; t = tmb.t_gett(); - if (t==NULL || t==T_UNDEFINED) - { - if(tmb.t_newtran(_m)<0) - { + if(t == NULL || t == T_UNDEFINED) { + if(tmb.t_newtran(_m) < 0) { LM_ERR("cannot create the transaction\n"); return -1; } t = tmb.t_gett(); - if (t==NULL || t==T_UNDEFINED) - { + if(t == NULL || t == T_UNDEFINED) { LM_ERR("cannot look up the transaction\n"); return -1; } @@ -82,19 +81,20 @@ int jsonrpc_request(struct sip_msg* _m, char* _method, char* _params, char* _cb_ unsigned int hash_index; unsigned int label; - if (tmb.t_suspend(_m, &hash_index, &label) < 0) { + if(tmb.t_suspend(_m, &hash_index, &label) < 0) { LM_ERR("t_suspend() failed\n"); return -1; } struct jsonrpc_pipe_cmd *cmd; - if (!(cmd = (struct jsonrpc_pipe_cmd *) shm_malloc(sizeof(struct jsonrpc_pipe_cmd)))) + if(!(cmd = (struct jsonrpc_pipe_cmd *)shm_malloc( + sizeof(struct jsonrpc_pipe_cmd)))) return memory_error(); memset(cmd, 0, sizeof(struct jsonrpc_pipe_cmd)); - pv_spec_t *cb_pv = (pv_spec_t*)shm_malloc(sizeof(pv_spec_t)); - if (!cb_pv) + pv_spec_t *cb_pv = (pv_spec_t *)shm_malloc(sizeof(pv_spec_t)); + if(!cb_pv) return memory_error(); cb_pv = memcpy(cb_pv, (pv_spec_t *)_cb_pv, sizeof(pv_spec_t)); @@ -107,8 +107,8 @@ int jsonrpc_request(struct sip_msg* _m, char* _method, char* _params, char* _cb_ cmd->msg = _m; cmd->t_hash = hash_index; cmd->t_label = label; - - if (write(cmd_pipe, &cmd, sizeof(cmd)) != sizeof(cmd)) { + + if(write(cmd_pipe, &cmd, sizeof(cmd)) != sizeof(cmd)) { LM_ERR("failed to write to io pipe: %s\n", strerror(errno)); return -1; } @@ -116,22 +116,23 @@ int jsonrpc_request(struct sip_msg* _m, char* _method, char* _params, char* _cb_ return 0; } -int jsonrpc_notification(struct sip_msg* _m, char* _method, char* _params) +int jsonrpc_notification(struct sip_msg *_m, char *_method, char *_params) { str method; str params; - if (fixup_get_svalue(_m, (gparam_p)_method, &method) != 0) { + if(fixup_get_svalue(_m, (gparam_p)_method, &method) != 0) { LM_ERR("cannot get method value\n"); return -1; } - if (fixup_get_svalue(_m, (gparam_p)_params, ¶ms) != 0) { + if(fixup_get_svalue(_m, (gparam_p)_params, ¶ms) != 0) { LM_ERR("cannot get params value\n"); return -1; } struct jsonrpc_pipe_cmd *cmd; - if (!(cmd = (struct jsonrpc_pipe_cmd *) shm_malloc(sizeof(struct jsonrpc_pipe_cmd)))) + if(!(cmd = (struct jsonrpc_pipe_cmd *)shm_malloc( + sizeof(struct jsonrpc_pipe_cmd)))) return memory_error(); memset(cmd, 0, sizeof(struct jsonrpc_pipe_cmd)); @@ -140,7 +141,7 @@ int jsonrpc_notification(struct sip_msg* _m, char* _method, char* _params) cmd->params = shm_str2char_dup(¶ms); cmd->notify_only = 1; - if (write(cmd_pipe, &cmd, sizeof(cmd)) != sizeof(cmd)) { + if(write(cmd_pipe, &cmd, sizeof(cmd)) != sizeof(cmd)) { LM_ERR("failed to write to io pipe: %s\n", strerror(errno)); return -1; } diff --git a/src/modules/jsonrpcc/jsonrpc_request.h b/src/modules/jsonrpcc/jsonrpc_request.h index 49cfdb46c1c..e67d55e2cc3 100644 --- a/src/modules/jsonrpcc/jsonrpc_request.h +++ b/src/modules/jsonrpcc/jsonrpc_request.h @@ -24,8 +24,9 @@ #define _JSONRPC_REQUEST_H_ #include "../../core/parser/msg_parser.h" -int jsonrpc_request(struct sip_msg* msg, char* method, char* params, char* cb_route, char* err_route, char* cb_pv); -int jsonrpc_notification(struct sip_msg* msg, char* method, char* params); +int jsonrpc_request(struct sip_msg *msg, char *method, char *params, + char *cb_route, char *err_route, char *cb_pv); +int jsonrpc_notification(struct sip_msg *msg, char *method, char *params); extern int cmd_pipe; #endif /* _JSONRPC_REQUEST_H_ */ diff --git a/src/modules/jsonrpcc/jsonrpcc_mod.c b/src/modules/jsonrpcc/jsonrpcc_mod.c index 062b5b40965..597df92e455 100644 --- a/src/modules/jsonrpcc/jsonrpcc_mod.c +++ b/src/modules/jsonrpcc/jsonrpcc_mod.c @@ -42,13 +42,13 @@ MODULE_VERSION static int mod_init(void); static int child_init(int); -static int fixup_request(void** param, int param_no); -static int fixup_notification(void** param, int param_no); -static int fixup_request_free(void** param, int param_no); -int fixup_pvar_shm(void** param, int param_no); +static int fixup_request(void **param, int param_no); +static int fixup_notification(void **param, int param_no); +static int fixup_request_free(void **param, int param_no); +int fixup_pvar_shm(void **param, int param_no); char *servers_param; -int pipe_fds[2] = {-1,-1}; +int pipe_fds[2] = {-1, -1}; int cmd_pipe = -1; extern int _jsonrpcc_max_conn_retry; /* max retries to connect */ @@ -58,90 +58,88 @@ struct tm_binds tmb; /* * Exported Functions */ -static cmd_export_t cmds[]={ - {"jsonrpc_request", (cmd_function)jsonrpc_request, 5, fixup_request, fixup_request_free, ANY_ROUTE}, - {"jsonrpc_notification", (cmd_function)jsonrpc_notification, 2, fixup_notification, 0, ANY_ROUTE}, - {0, 0, 0, 0, 0, 0} -}; +static cmd_export_t cmds[] = { + {"jsonrpc_request", (cmd_function)jsonrpc_request, 5, fixup_request, + fixup_request_free, ANY_ROUTE}, + {"jsonrpc_notification", (cmd_function)jsonrpc_notification, 2, + fixup_notification, 0, ANY_ROUTE}, + {0, 0, 0, 0, 0, 0}}; /* * Script Parameters */ -static param_export_t mod_params[]={ - {"servers", PARAM_STRING, &servers_param}, - {"max_conn_attempts", INT_PARAM, &_jsonrpcc_max_conn_retry}, - { 0,0,0 } -}; +static param_export_t mod_params[] = {{"servers", PARAM_STRING, &servers_param}, + {"max_conn_attempts", INT_PARAM, &_jsonrpcc_max_conn_retry}, {0, 0, 0}}; /* * Exports */ struct module_exports exports = { - "jsonrpcc", /* module name */ - DEFAULT_DLFLAGS, /* dlopen flags */ - cmds, /* cmd (cfg function) exports */ - mod_params, /* param exports */ - 0, /* RPC method exports */ - 0, /* pseudo-variables exports */ - 0, /* response handling function */ - mod_init, /* module init function */ - child_init, /* per-child init function */ - 0 /* module destroy function */ + "jsonrpcc", /* module name */ + DEFAULT_DLFLAGS, /* dlopen flags */ + cmds, /* cmd (cfg function) exports */ + mod_params, /* param exports */ + 0, /* RPC method exports */ + 0, /* pseudo-variables exports */ + 0, /* response handling function */ + mod_init, /* module init function */ + child_init, /* per-child init function */ + 0 /* module destroy function */ }; -static int mod_init(void) { - load_tm_f load_tm; +static int mod_init(void) +{ + load_tm_f load_tm; /* load the tm functions */ - if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) - { + if(!(load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LM_ERR("failed find tm - cannot import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ - if (load_tm( &tmb )==-1) { + if(load_tm(&tmb) == -1) { LM_ERR("failed to bind to tm api\n"); return -1; } - if (servers_param == NULL) { + if(servers_param == NULL) { LM_ERR("servers parameter missing.\n"); return -1; } register_procs(1); - if (pipe(pipe_fds) < 0) { + if(pipe(pipe_fds) < 0) { LM_ERR("pipe() failed\n"); return -1; } - return(0); + return (0); } static int child_init(int rank) { int pid; - if (rank!=PROC_INIT) + if(rank != PROC_INIT) cmd_pipe = pipe_fds[1]; - if (rank!=PROC_MAIN) + if(rank != PROC_MAIN) return 0; - pid=fork_process(PROC_NOCHLDINIT, "jsonrpc io handler", 1); - if (pid<0) { + pid = fork_process(PROC_NOCHLDINIT, "jsonrpc io handler", 1); + if(pid < 0) { LM_ERR("failed to fork jsonrpc io handler\n"); return -1; /* error */ } - if(pid==0){ + if(pid == 0) { /* child */ close(pipe_fds[1]); /* initialize the config framework */ - if (cfg_child_init()) + if(cfg_child_init()) return -1; return jsonrpc_io_child_process(pipe_fds[0], servers_param); } @@ -150,31 +148,31 @@ static int child_init(int rank) /* Fixup Functions */ -static int fixup_request(void** param, int param_no) +static int fixup_request(void **param, int param_no) { - if (param_no <= 4) { + if(param_no <= 4) { return fixup_spve_null(param, 1); - } else if (param_no == 5) { + } else if(param_no == 5) { return fixup_pvar_null(param, 1); } LM_ERR("jsonrpc_request takes exactly 5 parameters.\n"); return -1; } -static int fixup_notification(void** param, int param_no) +static int fixup_notification(void **param, int param_no) { - if (param_no <= 2) { + if(param_no <= 2) { return fixup_spve_null(param, 1); } LM_ERR("jsonrpc_notification takes exactly 2 parameters.\n"); return -1; } -static int fixup_request_free(void** param, int param_no) +static int fixup_request_free(void **param, int param_no) { - if (param_no <= 4) { + if(param_no <= 4) { return 0; - } else if (param_no == 5) { + } else if(param_no == 5) { return fixup_free_pvar_null(param, 1); } LM_ERR("jsonrpc_request takes exactly 5 parameters.\n"); diff --git a/src/modules/jsonrpcc/netstring.c b/src/modules/jsonrpcc/netstring.c index 43a74869872..bf7294ceb41 100644 --- a/src/modules/jsonrpcc/netstring.c +++ b/src/modules/jsonrpcc/netstring.c @@ -31,62 +31,69 @@ #include "../../core/mem/mem.h" -int netstring_read_fd(int fd, char **netstring) { - int i, bytes; +int netstring_read_fd(int fd, char **netstring) +{ + int i, bytes; size_t len = 0; - *netstring = NULL; + *netstring = NULL; + + char buffer[10] = {0}; - char buffer[10]={0}; - /* Peek at first 10 bytes, to get length and colon */ - bytes = recv(fd,buffer,10,MSG_PEEK); - - if (bytes<3) return NETSTRING_ERROR_TOO_SHORT; - - /* No leading zeros allowed! */ - if (buffer[0] == '0' && isdigit(buffer[1])) - return NETSTRING_ERROR_LEADING_ZERO; - - /* The netstring must start with a number */ - if (!isdigit(buffer[0])) return NETSTRING_ERROR_NO_LENGTH; - - /* Read the number of bytes */ - for (i = 0; i < bytes && isdigit(buffer[i]); i++) { - /* Error if more than 9 digits */ - if (i >= 9) return NETSTRING_ERROR_TOO_LONG; - /* Accumulate each digit, assuming ASCII. */ - len = len*10 + (buffer[i] - '0'); - } - - /* Read the colon */ - if (buffer[i++] != ':') return NETSTRING_ERROR_NO_COLON; - + bytes = recv(fd, buffer, 10, MSG_PEEK); + + if(bytes < 3) + return NETSTRING_ERROR_TOO_SHORT; + + /* No leading zeros allowed! */ + if(buffer[0] == '0' && isdigit(buffer[1])) + return NETSTRING_ERROR_LEADING_ZERO; + + /* The netstring must start with a number */ + if(!isdigit(buffer[0])) + return NETSTRING_ERROR_NO_LENGTH; + + /* Read the number of bytes */ + for(i = 0; i < bytes && isdigit(buffer[i]); i++) { + /* Error if more than 9 digits */ + if(i >= 9) + return NETSTRING_ERROR_TOO_LONG; + /* Accumulate each digit, assuming ASCII. */ + len = len * 10 + (buffer[i] - '0'); + } + + /* Read the colon */ + if(buffer[i++] != ':') + return NETSTRING_ERROR_NO_COLON; + /* Read the whole string from the buffer */ - size_t read_len = i+len+1; + size_t read_len = i + len + 1; char *buffer2 = pkg_malloc(read_len); - if (!buffer2) { + if(!buffer2) { LM_ERR("Out of memory!"); return -1; } - bytes = recv(fd,buffer2,read_len,0); + bytes = recv(fd, buffer2, read_len, 0); + + /* Make sure we got the whole netstring */ + if(read_len > bytes) + return NETSTRING_ERROR_TOO_SHORT; - /* Make sure we got the whole netstring */ - if (read_len > bytes) return NETSTRING_ERROR_TOO_SHORT; - - /* Test for the trailing comma */ - if (buffer2[read_len-1] != ',') return NETSTRING_ERROR_NO_COMMA; + /* Test for the trailing comma */ + if(buffer2[read_len - 1] != ',') + return NETSTRING_ERROR_NO_COMMA; + + buffer2[read_len - 1] = '\0'; - buffer2[read_len-1] = '\0'; - int x; - - for(x=0;x<=read_len-i-1;x++) { - buffer2[x]=buffer2[x+i]; + + for(x = 0; x <= read_len - i - 1; x++) { + buffer2[x] = buffer2[x + i]; } - + *netstring = buffer2; - return 0; + return 0; } @@ -114,83 +121,94 @@ int netstring_read_fd(int fd, char **netstring) { if (netstring_read("3:foo,", 6, &str, &len) < 0) explode_and_die(); */ -int netstring_read(char *buffer, size_t buffer_length, - char **netstring_start, size_t *netstring_length) { - int i; - size_t len = 0; - - /* Write default values for outputs */ - *netstring_start = NULL; *netstring_length = 0; - - /* Make sure buffer is big enough. Minimum size is 3. */ - if (buffer_length < 3) return NETSTRING_ERROR_TOO_SHORT; - - /* No leading zeros allowed! */ - if (buffer[0] == '0' && isdigit(buffer[1])) - return NETSTRING_ERROR_LEADING_ZERO; - - /* The netstring must start with a number */ - if (!isdigit(buffer[0])) return NETSTRING_ERROR_NO_LENGTH; +int netstring_read(char *buffer, size_t buffer_length, char **netstring_start, + size_t *netstring_length) +{ + int i; + size_t len = 0; - /* Read the number of bytes */ - for (i = 0; i < buffer_length && isdigit(buffer[i]); i++) { - /* Error if more than 9 digits */ - if (i >= 9) return NETSTRING_ERROR_TOO_LONG; - /* Accumulate each digit, assuming ASCII. */ - len = len*10 + (buffer[i] - '0'); - } + /* Write default values for outputs */ + *netstring_start = NULL; + *netstring_length = 0; + + /* Make sure buffer is big enough. Minimum size is 3. */ + if(buffer_length < 3) + return NETSTRING_ERROR_TOO_SHORT; + + /* No leading zeros allowed! */ + if(buffer[0] == '0' && isdigit(buffer[1])) + return NETSTRING_ERROR_LEADING_ZERO; + + /* The netstring must start with a number */ + if(!isdigit(buffer[0])) + return NETSTRING_ERROR_NO_LENGTH; + + /* Read the number of bytes */ + for(i = 0; i < buffer_length && isdigit(buffer[i]); i++) { + /* Error if more than 9 digits */ + if(i >= 9) + return NETSTRING_ERROR_TOO_LONG; + /* Accumulate each digit, assuming ASCII. */ + len = len * 10 + (buffer[i] - '0'); + } - /* Check buffer length once and for all. Specifically, we make sure + /* Check buffer length once and for all. Specifically, we make sure that the buffer is longer than the number we've read, the length of the string itself, and the colon and comma. */ - if (i + len + 1 >= buffer_length) return NETSTRING_ERROR_TOO_SHORT; + if(i + len + 1 >= buffer_length) + return NETSTRING_ERROR_TOO_SHORT; + + /* Read the colon */ + if(buffer[i++] != ':') + return NETSTRING_ERROR_NO_COLON; - /* Read the colon */ - if (buffer[i++] != ':') return NETSTRING_ERROR_NO_COLON; - - /* Test for the trailing comma, and set the return values */ - if (buffer[i + len] != ',') return NETSTRING_ERROR_NO_COMMA; - *netstring_start = &buffer[i]; *netstring_length = len; + /* Test for the trailing comma, and set the return values */ + if(buffer[i + len] != ',') + return NETSTRING_ERROR_NO_COMMA; + *netstring_start = &buffer[i]; + *netstring_length = len; - return 0; + return 0; } /* Return the length, in ASCII characters, of a netstring containing `data_length` bytes. */ -size_t netstring_buffer_size(size_t data_length) { - if (data_length == 0) return 3; - return (size_t)ceil(log10((double)data_length + 1)) + data_length + 2; +size_t netstring_buffer_size(size_t data_length) +{ + if(data_length == 0) + return 3; + return (size_t)ceil(log10((double)data_length + 1)) + data_length + 2; } /* Allocate and create a netstring containing the first `len` bytes of `data`. This must be manually freed by the client. If `len` is 0 then no data will be read from `data`, and it may be NULL. */ -size_t netstring_encode_new(char **netstring, char *data, size_t len) { - char *ns; - size_t num_len = 1; - - if (len == 0) { - ns = pkg_malloc(3); - if (!ns) { - LM_ERR("Out of memory!"); - return 0; - } - ns[0] = '0'; - ns[1] = ':'; - ns[2] = ','; - } else { - num_len = (size_t)ceil(log10((double)len + 1)); - ns = pkg_malloc(num_len + len + 2); - if (!ns) { - LM_ERR("Out of memory!"); - return 0; +size_t netstring_encode_new(char **netstring, char *data, size_t len) +{ + char *ns; + size_t num_len = 1; + + if(len == 0) { + ns = pkg_malloc(3); + if(!ns) { + LM_ERR("Out of memory!"); + return 0; + } + ns[0] = '0'; + ns[1] = ':'; + ns[2] = ','; + } else { + num_len = (size_t)ceil(log10((double)len + 1)); + ns = pkg_malloc(num_len + len + 2); + if(!ns) { + LM_ERR("Out of memory!"); + return 0; + } + snprintf(ns, num_len + len + 2, "%lu:", (unsigned long)len); + memcpy(ns + num_len + 1, data, len); + ns[num_len + len + 1] = ','; } - snprintf(ns, num_len + len + 2, "%lu:", (unsigned long)len); - memcpy(ns + num_len + 1, data, len); - ns[num_len + len + 1] = ','; - } - *netstring = ns; - return num_len + len + 2; + *netstring = ns; + return num_len + len + 2; } - diff --git a/src/modules/jsonrpcc/netstring.h b/src/modules/jsonrpcc/netstring.h index 9af5d3feb71..b1a7096d581 100644 --- a/src/modules/jsonrpcc/netstring.h +++ b/src/modules/jsonrpcc/netstring.h @@ -27,20 +27,20 @@ int netstring_read_fd(int fd, char **netstring); -int netstring_read(char *buffer, size_t buffer_length, - char **netstring_start, size_t *netstring_length); +int netstring_read(char *buffer, size_t buffer_length, char **netstring_start, + size_t *netstring_length); size_t netstring_buffer_size(size_t data_length); size_t netstring_encode_new(char **netstring, char *data, size_t len); /* Errors that can occur during netstring parsing */ -#define NETSTRING_ERROR_TOO_LONG -1 -#define NETSTRING_ERROR_NO_COLON -2 -#define NETSTRING_ERROR_TOO_SHORT -3 -#define NETSTRING_ERROR_NO_COMMA -4 +#define NETSTRING_ERROR_TOO_LONG -1 +#define NETSTRING_ERROR_NO_COLON -2 +#define NETSTRING_ERROR_TOO_SHORT -3 +#define NETSTRING_ERROR_NO_COMMA -4 #define NETSTRING_ERROR_LEADING_ZERO -5 -#define NETSTRING_ERROR_NO_LENGTH -6 -#define NETSTRING_ERROR_BAD_FD -7 +#define NETSTRING_ERROR_NO_LENGTH -6 +#define NETSTRING_ERROR_BAD_FD -7 #endif