diff --git a/utils/kamcmd/kamcmd.c b/utils/kamcmd/kamcmd.c index 372721e6700..56124ca49fe 100644 --- a/utils/kamcmd/kamcmd.c +++ b/utils/kamcmd/kamcmd.c @@ -1,7 +1,7 @@ /* * Copyright (C) 2006 iptelorg GmbH * - * This file is part of kamailio, a free SIP server. + * This file is part of kamcmd, a free cli tool for Kamailio SIP server. * * kamailio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -176,7 +176,7 @@ static inline char* int2str(unsigned int l, int* len) { static char r[INT2STR_MAX_LEN]; int i; - + i=INT2STR_MAX_LEN-2; r[INT2STR_MAX_LEN-1]=0; /* null terminate */ do{ @@ -196,11 +196,11 @@ static inline char* int2str(unsigned int l, int* len) static char* trim_ws(char* l) { char* ret; - + for(;*l && ((*l==' ')||(*l=='\t')||(*l=='\n')||(*l=='\r')); l++); ret=l; if (*ret==0) return ret; - for(l=l+strlen(l)-1; (l>ret) && + for(l=l+strlen(l)-1; (l>ret) && ((*l==' ')||(*l=='\t')||(*l=='\n')||(*l=='\r')); l--); *(l+1)=0; return ret; @@ -353,7 +353,7 @@ static int parse_arg(struct binrpc_val* v, char* arg) double f; char* tmp; int len; - + i=strtol(arg, &tmp, 10); if ((tmp==0) || (*tmp)){ f=strtod(arg, &tmp); @@ -385,7 +385,7 @@ static int parse_arg(struct binrpc_val* v, char* arg) static int parse_cmd(struct binrpc_cmd* cmd, char** argv, int count) { int r; - + cmd->method=argv[0]; if ((count-1)>MAX_BINRPC_ARGS){ fprintf(stderr, "ERROR: too many args %d, only %d allowed\n", @@ -444,7 +444,7 @@ int connect_unix_sock(char* name, int type) int len; int ret; int retries; - + retries=0; s=-1; memset(&ifsun, 0, sizeof (struct sockaddr_un)); @@ -472,7 +472,7 @@ int connect_unix_sock(char* name, int type) sock_dir="/tmp"; retry: ret=snprintf(mysun.sun_path, UNIX_PATH_MAX, "%s/" NAME "_%d", - sock_dir, rand()); + sock_dir, rand()); if ((ret<0) ||(ret>=UNIX_PATH_MAX)){ fprintf(stderr, "ERROR: buffer overflow while trying to" "generate unix datagram socket name"); @@ -519,7 +519,7 @@ int connect_tcpudp_socket(char* address, int port, int type) struct sockaddr_in addr; struct hostent* he; int sock; - + sock=-1; /* resolve destination */ he=gethostbyname(address); @@ -531,7 +531,7 @@ int connect_tcpudp_socket(char* address, int port, int type) addr.sin_family=he->h_addrtype; addr.sin_port=htons(port); memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length); - + sock = socket(he->h_addrtype, type, 0); if (sock==-1){ fprintf(stderr, "ERROR: socket: %s\n", strerror(errno)); @@ -552,7 +552,7 @@ int connect_tcpudp_socket(char* address, int port, int type) static void hexdump(unsigned char* buf, int len, int ascii) { int r, i; - + /* dump it in hex */ for (r=0; rmethod, strlen(cmd->method)); @@ -631,7 +631,7 @@ static int send_binrpc_cmd(int s, struct binrpc_cmd* cmd, int cookie) goto write_again; goto error_send; } - + return n; error_send: return -1; @@ -646,7 +646,7 @@ static int binrpc_errno=0; * returns < 0 on error, reply size on success + initializes in_pkt * if ret==-2 (parse error), sets binrpc_errno to the binrpc error * error returns: -1 - read error (check errno) - * -2 - binrpc parse error (chekc binrpc_errno) + * -2 - binrpc parse error (chekc binrpc_errno) * -3 - cookie error (the cookied doesn't match) * -4 - message too big */ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size, @@ -658,8 +658,7 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size, unsigned char* msg_end; int n; int ret; - - + hdr_end=crt=reply_buf; msg_end=reply_buf+max_reply_size; binrpc_errno=0; @@ -716,7 +715,7 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size, } } }while(crtmethod=strtok(line, " \t"); if (cmd->method==0) goto error_no_method; @@ -1024,7 +1023,7 @@ static int parse_line(struct binrpc_cmd* cmd, char* line) static void fix_cmd(struct binrpc_cmd* cmd, char** format) { int r; - + for (r=0; cmd_aliases[r].name; r++){ if (strcmp(cmd_aliases[r].name, cmd->method)==0){ cmd->method=cmd_aliases[r].method; @@ -1043,7 +1042,7 @@ static int run_builtins(int s, struct binrpc_cmd* cmd) { int r; int ret; - + for (r=0; builtins[r].name; r++){ if (strcmp(builtins[r].name, cmd->method)==0){ ret=builtins[r].f(s, cmd); @@ -1062,7 +1061,7 @@ inline static int run_cmd(int s, struct binrpc_cmd* cmd, char* format) char* fmt; fmt=format; - + fix_cmd(cmd, &fmt); if (!(ret=run_builtins(s, cmd))){ ret=run_binrpc_cmd(s, cmd, fmt); @@ -1077,7 +1076,7 @@ inline static int run_line(int s, char* l, char* format) { struct binrpc_cmd cmd; int ret; - + if ((ret=parse_line(&cmd, l))==0){ return run_cmd(s, &cmd, format); } @@ -1103,7 +1102,7 @@ static void free_rpc_array(struct binrpc_val* a, int size) /* parse the body into a malloc allocated, binrpc_val array */ -static struct binrpc_val* parse_reply_body(int* records, +static struct binrpc_val* parse_reply_body(int* records, struct binrpc_parse_ctx* in_pkt, unsigned char* body, int size) { @@ -1124,7 +1123,7 @@ static struct binrpc_val* parse_reply_body(int* records, goto error_mem; p=body; end=p+size; - + /* read body */ while(pargc && (cmd->argv[0].type==BINRPC_T_STR)){ /* if it has args, try command help */ for (r=0; cmd_aliases[r].name; r++){ @@ -1603,7 +1602,7 @@ static int kamcmd_help(int s, struct binrpc_cmd* cmd) } for(r=0; builtins[r].name; r++){ if (strcmp(cmd->argv[0].u.strval.s, builtins[r].name)==0){ - printf("builtin command: %s\n", + printf("builtin command: %s\n", builtins[r].doc?builtins[r].doc:"undocumented"); return 0; } @@ -1614,7 +1613,7 @@ static int kamcmd_help(int s, struct binrpc_cmd* cmd) } return 0; } - + if (rpc_no==0){ if (get_kamcmd_list(s)<0) goto error; @@ -1837,7 +1836,7 @@ char** kamcmd_completion(const char* text, int start, int end) static int cnt_grp_start; int cnt_grp_len; #endif /* USE_COUNTERS */ - + crt_param_no=0; /* skip over whitespace at the beginning */ for (j=0; (jproto){ case UDP_SOCK: case TCP_SOCK: @@ -2104,14 +2103,14 @@ int main(int argc, char** argv) } free(sock_id); /* not needed anymore */ sock_id=0; - + if (optind>=argc){ /*fprintf(stderr, "ERROR: no command specified\n"); goto error; */ }else{ if (parse_cmd(&cmd, &argv[optind], argc-optind)<0) goto error; - if (run_cmd(s, &cmd, format)<0) + if (run_cmd(s, &cmd, format)<0) goto error; goto end; } @@ -2129,17 +2128,17 @@ int main(int argc, char** argv) printf("%s\n", COPYRIGHT); printf("%s\n", DISCLAIMER); #ifdef USE_READLINE - + /* initialize readline */ /* allow conditional parsing of the ~/.inputrc file*/ - rl_readline_name=NAME; + rl_readline_name=NAME; rl_completion_entry_function=kamcmd_generator; rl_attempted_completion_function=kamcmd_completion; - + while(!quit){ line=readline(NAME "> "); if (line==0) /* EOF */ - break; + break; l=trim_ws(line); /* trim whitespace */ if (*l){ add_history(l); diff --git a/utils/kamcmd/license.h b/utils/kamcmd/license.h index 961e984a963..f6262c0789b 100644 --- a/utils/kamcmd/license.h +++ b/utils/kamcmd/license.h @@ -1,7 +1,5 @@ /* - * $Id$ - * - * sercmd GPL license, standard disclaimer and copyright + * kamcmd GPL license, standard disclaimer and copyright */ #ifndef __license_h_ diff --git a/utils/kamcmd/parse_listen_id.c b/utils/kamcmd/parse_listen_id.c index 9fde9b278f2..aa2a3cd1279 100644 --- a/utils/kamcmd/parse_listen_id.c +++ b/utils/kamcmd/parse_listen_id.c @@ -1,9 +1,7 @@ /* - * $Id$ - * * Copyright (C) 2006 iptelorg GmbH * - * This file is part of ser, a free SIP server. + * This file is part of kamcmd, a free cli tool for Kamailio SIP server. * * ser is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,14 +18,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* History: - * -------- - * 2006-02-20 created by andrei - */ #include @@ -54,14 +48,14 @@ static int _debug = 0; if(_debug==1) \ fprintf(stderr, __VA_ARGS__); \ } while(0) -#define LOG(lev, ...) fprintf(stderr, __VA_ARGS__) +#define ERR(...) fprintf(stderr, __VA_ARGS__) #else #define DBG(fmt, args...) \ do { \ if(_debug==1) \ fprintf(stderr, fmt, ## args); \ } while(0) -#define LOG(lev, fmt, args...) fprintf(stderr, fmt, ## args) +#define ERR(fmt, args...) fprintf(stderr, fmt, ## args) #endif @@ -100,11 +94,11 @@ static inline unsigned short str2s(const char* s, unsigned int len, return ret; error_digits: - DBG("str2s: ERROR: too many letters in [%.*s]\n", (int)len, init); + DBG("ERROR: too many letters in [%.*s]\n", (int)len, init); if (err) *err=1; return 0; error_char: - DBG("str2s: ERROR: unexpected char %c in %.*s\n", *str, (int)len, init); + DBG("ERROR: unexpected char %c in %.*s\n", *str, (int)len, init); if (err) *err=1; return 0; } @@ -119,7 +113,7 @@ static inline unsigned short str2s(const char* s, unsigned int len, * tcp|udp|unix:host_name * host_name:port * host_name - * + * * * where host_name=string, ipv4 address, [ipv6 address], * unix socket path (starts with '/') @@ -135,22 +129,22 @@ struct id_list* parse_listen_id(char* l, int len, enum socket_protos def) struct servent* se; char* s; struct id_list* id; - + s=pkg_malloc((len+1)*sizeof(char)); if (s==0){ - LOG(L_ERR, "ERROR:parse_listen_id: out of memory\n"); + ERR("ERROR:parse_listen_id: out of memory\n"); goto error; } memcpy(s, l, len); s[len]=0; /* null terminate */ - + /* duplicate */ proto=UNKNOWN_SOCK; port=0; name=0; port_str=0; p=s; - + if ((*p)=='[') goto ipv6; /* find proto or name */ for (; *p; p++){ @@ -207,11 +201,11 @@ struct id_list* parse_listen_id(char* l, int len, enum socket_protos def) goto error; } } - + find_port: p++; port_str=(*p)?p:0; - + end: /* fix all the stuff */ if (name==0) goto error; @@ -247,13 +241,13 @@ struct id_list* parse_listen_id(char* l, int len, enum socket_protos def) port=str2s(port_str, strlen(port_str), &err); if (err){ /* try getservbyname */ - se=getservbyname(port_str, + se=getservbyname(port_str, (proto==TCP_SOCK)?"tcp":(proto==UDP_SOCK)?"udp":0); if (se) port=ntohs(se->s_port); else goto error; } }else{ - /* no port, check if the hostname is a port + /* no port, check if the hostname is a port * (e.g. tcp:3012 == tcp:*:3012 */ if (proto==TCP_SOCK|| proto==UDP_SOCK){ port=str2s(name, strlen(name), &err); @@ -266,7 +260,7 @@ struct id_list* parse_listen_id(char* l, int len, enum socket_protos def) } id=pkg_malloc(sizeof(struct id_list)); if (id==0){ - LOG(L_ERR, "ERROR:parse_listen_id: out of memory\n"); + ERR("ERROR:parse_listen_id: out of memory\n"); goto error; } id->name=name; diff --git a/utils/kamcmd/parse_listen_id.h b/utils/kamcmd/parse_listen_id.h index 774755ceccc..6ed2535c683 100644 --- a/utils/kamcmd/parse_listen_id.h +++ b/utils/kamcmd/parse_listen_id.h @@ -1,9 +1,7 @@ /* - * $Id$ - * * Copyright (C) 2006 iptelorg GmbH * - * This file is part of ser, a free SIP server. + * This file is part of kamcmd, a free cli tool for Kamailio SIP server. * * ser is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,14 +18,10 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* History: - * -------- - * 2006-02-20 created by andrei - */ #ifndef parse_listen_id_h @@ -35,7 +29,7 @@ enum payload_proto { P_BINRPC , P_FIFO }; -enum socket_protos { UNKNOWN_SOCK=0, UDP_SOCK, TCP_SOCK, +enum socket_protos { UNKNOWN_SOCK=0, UDP_SOCK, TCP_SOCK, UNIXS_SOCK, UNIXD_SOCK #ifdef USE_FIFO , FIFO_SOCK