Index: asterisk/channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.497 diff -u -r1.497 chan_sip.c --- asterisk/channels/chan_sip.c 9 Sep 2004 15:40:07 -0000 1.497 +++ asterisk/channels/chan_sip.c 10 Sep 2004 01:21:04 -0000 @@ -2,7 +2,7 @@ * Asterisk -- A telephony toolkit for Linux. * * Implementation of Session Initiation Protocol - * + * * Copyright (C) 2004, Digium, Inc. * * Mark Spencer @@ -59,13 +59,26 @@ #ifdef SIP_MYSQL_FRIENDS #define MYSQL_FRIENDS +#define SQL_FRIENDS #include #endif +#ifdef SIP_ODBC_FRIENDS +#define ODBC_FRIENDS +#define SQL_FRIENDS +#include +#endif + +#ifdef MYSQL_FRIENDS +#ifdef ODBC_FRIENDS +#error Both MYSQL_FRIENDS and ODBC_FRIENDS cannot be defined at the same time +#endif +#endif + #ifndef DEFAULT_USERAGENT #define DEFAULT_USERAGENT "Asterisk PBX" #endif - + #define VIDEO_CODEC_MASK 0x1fc0000 /* Video codecs from H.261 thru AST_FORMAT_MAX_VIDEO */ #ifndef IPTOS_MINCOST #define IPTOS_MINCOST 0x02 @@ -118,6 +131,19 @@ static char mydbname[80]; #endif +#ifdef ODBC_FRIENDS +AST_MUTEX_DEFINE_STATIC(odbclock); +void *dbconn; +char dbconn_string[512]; +#endif + +#ifdef SQL_FRIENDS + +char db_select_peer_bysin_query[1024] = "SELECT name,secret,context,username,ipaddr,port,regseconds FROM sipfriends WHERE ipaddr=\"%s\" AND port=\"%d\""; +char db_select_peer_byname_query[1024] = "SELECT name,secret,context,username,ipaddr,port,regseconds FROM sipfriends WHERE name=\"%s\""; +char db_update_peer_query[1024] = "UPDATE sipfriends SET ipaddr=\"%s\", port=\"%d\", regseconds=\"%ld\", username=\"%s\" WHERE name=\"%s\""; + +#endif /* SIP Debug */ #define DEBUG_READ 0 /* Recieved data */ #define DEBUG_SEND 1 /* Transmit data */ @@ -148,7 +174,7 @@ static int pedanticsipchecking = 0; -static int autocreatepeer = 0; +static int autocreatepeer = 0; static int relaxdtmf = 0; @@ -212,7 +238,7 @@ static struct io_context *io; /* The private structures of the sip channels are linked for selecting outgoing channels */ - + #define SIP_MAX_HEADERS 64 #define SIP_MAX_LINES 64 @@ -313,7 +339,7 @@ char callerid[256]; /* Caller*ID */ int restrictcid; /* hide presentation from remote user */ char via[256]; - char fullcontact[128]; /* Extra parameters to go in the "To" header */ + char fullcontact[128]; /* Extra parameters to go in the "To" header */ char accountcode[20]; /* Account code */ char our_contact[256]; /* Our contact header */ char realm[256]; /* Authorization realm */ @@ -333,7 +359,7 @@ time_t ospstart; /* OSP Start time */ #endif struct sip_request initreq; /* Initial request */ - + int maxtime; /* Max time for first response */ int initid; /* Auto-congest ID if appropriate */ int autokillid; /* Auto-kill ID */ @@ -345,13 +371,13 @@ int stateid; int dialogver; int promiscredir; /* Promiscuous redirection */ - + int trustrpid; int progressinband; - + int dtmfmode; struct ast_dsp *vad; - + struct sip_peer *peerpoke; /* If this calls is to poke a peer, which one */ struct sip_registry *registry; /* If this is a REGISTER call, to which registry */ struct ast_rtp *rtp; /* RTP Session */ @@ -374,7 +400,7 @@ int retransid; /* Retransmission ID */ int packetlen; /* Length of packet */ char data[0]; -}; +}; /* Structure for SIP user data. User's place calls to us */ struct sip_user { @@ -411,7 +437,7 @@ struct ast_ha *ha; #ifdef MYSQL_USERS int temponly; -#endif /* MYSQL_FRIENDS */ +#endif /* MYSQL_USERS */ struct sip_user *next; }; @@ -423,7 +449,7 @@ char context[80]; /* JK02: peers need context too to allow parking etc */ char username[80]; char tohost[80]; - char regexten[AST_MAX_EXTENSION]; /* Extension to register (if regcontext is used) */ + char regexten[AST_MAX_EXTENSION]; /* Extension to register (if regcontext is used) */ char fromuser[80]; char fromdomain[80]; char fullcontact[128]; @@ -442,7 +468,7 @@ int insecure; #ifdef OSP_SUPPORT int ospauth; /* Allow OSP Authentication */ -#endif +#endif int nat; int canreinvite; unsigned int callgroup; @@ -460,7 +486,7 @@ int lastms; /* How long last response took (in ms), or -1 for no response */ int maxms; /* Max ms we will accept for the host to be up, 0 to not monitor */ struct timeval ps; /* Ping send time */ - + struct sockaddr_in defaddr; struct ast_ha *ha; int delme; @@ -492,7 +518,7 @@ char username[80]; /* Who we are registering as */ char authuser[80]; /* Who we *authenticate* as */ char hostname[80]; - char secret[80]; /* Password or key name in []'s */ + char secret[80]; /* Password or key name in []'s */ char md5secret[80]; char contact[80]; /* Contact extension */ char random[80]; @@ -563,7 +589,7 @@ /*--- sip_debug_test_addr: See if we pass debug IP filter */ -static inline int sip_debug_test_addr(struct sockaddr_in *addr) +static inline int sip_debug_test_addr(struct sockaddr_in *addr) { if (sipdebug == 0) return 0; @@ -576,7 +602,7 @@ return 1; } -static inline int sip_debug_test_pvt(struct sip_pvt *p) +static inline int sip_debug_test_pvt(struct sip_pvt *p) { if (sipdebug == 0) return 0; @@ -801,7 +827,7 @@ cur = p->packets; while(cur) { if ((cur->seqno == seqno) && ((cur->flags & FLAG_RESPONSE) == resp) && - ((cur->flags & FLAG_RESPONSE) || + ((cur->flags & FLAG_RESPONSE) || (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) { if (!resp && (seqno == p->pendinginvite)) { ast_log(LOG_DEBUG, "Acked pending invite %d\n", p->pendinginvite); @@ -834,7 +860,7 @@ cur = p->packets; while(cur) { if ((cur->seqno == seqno) && ((cur->flags & FLAG_RESPONSE) == resp) && - ((cur->flags & FLAG_RESPONSE) || + ((cur->flags & FLAG_RESPONSE) || (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) { /* this is our baby */ if (cur->retransid > -1) @@ -925,7 +951,7 @@ } /*--- url_decode: Decode SIP URL ---*/ -static void url_decode(char *s) +static void url_decode(char *s) { char *o = s; unsigned int tmp; @@ -993,7 +1019,222 @@ if (debug) ast_verbose("Really sending text %s on %s\n", text, ast->name); transmit_message_with_text(p, text); - return 0; + return 0; +} + +static int set_sip_peer_property(struct sip_peer *peer, char *propName, char *propValue, int *maskfound, int *found ) +{ + int format; + + if (!strcasecmp(propName, "name")) { + strncpy(peer->name, propValue, sizeof(peer->name)-1); + return 1; + } + if (!strcasecmp(propName, "secret")) { + strncpy(peer->secret, propValue, sizeof(peer->secret)-1); + return 1; + } + if (!strcasecmp(propName, "md5secret")) { + strncpy(peer->md5secret, propValue, sizeof(peer->md5secret)-1); + return 1; + } + if (!strcasecmp(propName, "canreinvite")) { + if (!strcasecmp(propValue, "update")) + peer->canreinvite = REINVITE_UPDATE; + else + peer->canreinvite = ast_true(propValue); + return 1; + } + if (!strcasecmp(propName, "nat")) { + if (!strcasecmp(propValue, "rfc3581")) + peer->nat = SIP_NAT_RFC3581; + else if (!strcasecmp(propValue, "route")) + peer->nat = SIP_NAT_ROUTE; + else if (ast_true(propValue)) + peer->nat = SIP_NAT_ALWAYS; + else + peer->nat = SIP_NAT_NEVER; + return 1; + } + if (!strcasecmp(propName, "context")) { + strncpy(peer->context, propValue, sizeof(peer->context)-1); + return 1; + } + if (!strcasecmp(propName, "fromdomain")) { + strncpy(peer->fromdomain, propValue, sizeof(peer->fromdomain)-1); + return 1; + } + if (!strcasecmp(propName, "promiscredir")) { + peer->promiscredir = ast_true(propValue); + return 1; + } + if (!strcasecmp(propName, "fromuser")) { + strncpy(peer->fromuser, propValue, sizeof(peer->fromuser)-1); + return 1; + } + if (!strcasecmp(propName, "dtmfmode")) { + if (!strcasecmp(propValue, "inband")) + peer->dtmfmode=SIP_DTMF_INBAND; + else if (!strcasecmp(propValue, "rfc2833")) + peer->dtmfmode = SIP_DTMF_RFC2833; + else if (!strcasecmp(propValue, "info")) + peer->dtmfmode = SIP_DTMF_INFO; + else { + ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n", propValue); + peer->dtmfmode = SIP_DTMF_RFC2833; + } + return 1; + } + if (!strcasecmp(propName, "host")) { + if (!strcasecmp(propValue, "dynamic")) { + /* They'll register with us */ + peer->dynamic = 1; + if (!found) { + /* Initialize stuff iff we're not found, otherwise + we keep going with what we had */ + memset(&peer->addr.sin_addr, 0, 4); + if (peer->addr.sin_port) { + /* If we've already got a port, make it the default rather than absolute */ + peer->defaddr.sin_port = peer->addr.sin_port; + peer->addr.sin_port = 0; + } + } + } else { + /* Non-dynamic. Make sure we become that way if we're not */ + if (peer->expire > -1) + ast_sched_del(sched, peer->expire); + peer->expire = -1; + peer->dynamic = 0; + if (ast_get_ip(&peer->addr, propValue)) + return -1; + strncpy(peer->tohost, propValue, sizeof(peer->tohost) - 1); + } + if (maskfound && !maskfound[0]) + inet_aton("255.255.255.255", &peer->mask); + return 1; + } + if (!strcasecmp(propName, "ipaddr")) { + if (ast_get_ip(&peer->addr, propValue)) { + return -1; + } + return 1; + } + if (!strcasecmp(propName, "defaultip")) { + if (ast_get_ip(&peer->defaddr, propValue)) { + return -1; + } + return 1; + } + if (!strcasecmp(propName, "permit") || !strcasecmp(propName, "deny")) { + peer->ha = ast_append_ha(propName, propValue, peer->ha); + return 1; + } + if (!strcasecmp(propName, "mask")) { + if( maskfound ) maskfound[0]++; + inet_aton(propValue, &peer->mask); + return 1; + } + if (!strcasecmp(propName, "port")) { + if (peer->dynamic) + peer->defaddr.sin_port = htons(atoi(propValue)); + else + peer->addr.sin_port = htons(atoi(propValue)); + return 1; + } + if (!strcasecmp(propName, "username")) { + strncpy(peer->username, propValue, sizeof(peer->username)-1); + return 1; + } + if (!strcasecmp(propName, "language")) { + strncpy(peer->language, propValue, sizeof(peer->language)-1); + return 1; + } + if (!strcasecmp(propName, "musiconhold")) { + strncpy(peer->musicclass, propValue, sizeof(peer->musicclass)-1); + return 1; + } + if (!strcasecmp(propName, "mailbox")) { + strncpy(peer->mailbox, propValue, sizeof(peer->mailbox)-1); + return 1; + } + if (!strcasecmp(propName, "callgroup")) { + peer->callgroup = ast_get_group(propValue); + return 1; + } + if (!strcasecmp(propName, "pickupgroup")) { + peer->pickupgroup = ast_get_group(propValue); + return 1; + } + if (!strcasecmp(propName, "allow")) { + format = ast_getformatbyname(propValue); + if (format < 1) + ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", propValue); + else + peer->capability |= format; + return 1; + } + if (!strcasecmp(propName, "disallow")) { + format = ast_getformatbyname(propValue); + if (format < 1) + ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", propValue); + else + peer->capability &= ~format; + return 1; + } + if (!strcasecmp(propName, "insecure")) { + if (!strcasecmp(propValue, "very")) { + peer->insecure = 2; + } else if (ast_true(propValue)) + peer->insecure = 1; + else + peer->insecure = 0; + return 1; + } + if (!strcasecmp(propName, "rtptimeout")) { + if ((sscanf(propValue, "%d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) { + ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time. Using default.\n", propValue); + peer->rtptimeout = global_rtptimeout; + } + return 1; + } + if (!strcasecmp(propName, "rtpholdtimeout")) { + if ((sscanf(propValue, "%d", &peer->rtpholdtimeout) != 1) || (peer->rtpholdtimeout < 0)) { + ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time. Using default.\n", propValue); + peer->rtpholdtimeout = global_rtpholdtimeout; + } + return 1; + } + if (!strcasecmp(propName, "qualify")) { + if (!strcasecmp(propValue, "no")) { + peer->maxms = 0; + } else if (!strcasecmp(propValue, "yes")) { + peer->maxms = DEFAULT_MAXMS; + } else if (sscanf(propValue, "%d", &peer->maxms) != 1) { + ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds of sip.conf\n", peer->name); + peer->maxms = 0; + } + return 1; + } + if (!strcasecmp(propName, "trustrpid")) { + peer->trustrpid = ast_true(propValue); + return 1; + } + if (!strcasecmp(propName, "progressinband")) { + peer->progressinband = ast_true(propValue); + return 1; + } +#ifdef OSP_SUPPORT + if (!strcasecmp(propName, "ospauth")) { + if (!strcasecmp(propValue, "exclusive")) { + peer->ospauth = 2; + } else if (ast_true(propValue)) { + peer->ospauth = 1; + } else + peer->ospauth = 0; + return 1; + } +#endif + return 0; } #ifdef MYSQL_USERS @@ -1076,12 +1317,73 @@ } #endif /* MYSQL_USERS */ +#ifdef SQL_FRIENDS + #ifdef MYSQL_FRIENDS -/*--- mysql_update_peer: Update peer from database ---*/ +static int sql_is_good() +{ + return mysql!=0; +} +static unsigned int sql_escape_string(char* to, const char* from, unsigned int length) +{ + return mysql_real_escape_string(mysql,to,from,length); +} +static int sql_real_query(const char* query) +{ + return mysql_real_query(mysql,query,strlen(length)); +} +static void sql_lock() +{ + ast_mutex_lock(&mysqllock); +} +static void sql_unlock() +{ + ast_mutex_unlock(&mysqllock); +} +#endif /* MYSQL_FRIENDS */ + +#ifdef ODBC_FRIENDS +static int sql_is_good(void) +{ + return dbconn!=0; +} +static unsigned int sql_escape_string(char* to, const char* from, unsigned int length) +{ + unsigned int k = 0; + unsigned int n = 0; + for(n=0;nsin_addr), ntohs(sin->sin_port), nowtime + expiry, uname, name); - ast_mutex_lock(&mysqllock); - if (mysql_real_query(mysql, query, strlen(query))) + sql_escape_string(name, peer, strlen(peer)); + sql_escape_string(uname, username, strlen(username)); + snprintf(query, sizeof(query), db_update_peer_query, + ast_inet_ntoa(iabuf,sizeof(iabuf),sin->sin_addr), + ntohs(sin->sin_port), + nowtime + expiry, + uname, + name); + sql_lock(); + if (sql_real_query(query)) ast_log(LOG_WARNING, "Unable to update database\n"); - - ast_mutex_unlock(&mysqllock); + sql_unlock(); } } -/*--- mysql_peer: Get peer from database ---*/ -static struct sip_peer *mysql_peer(char *peer, struct sockaddr_in *sin) +/*--- sql_find_peer: Get peer from database ---*/ +static struct sip_peer *sql_find_peer(char *peer, struct sockaddr_in *sin) { struct sip_peer *p; int success = 0; - + time_t regseconds, nowtime; + p = malloc(sizeof(struct sip_peer)); memset(p, 0, sizeof(struct sip_peer)); - if (mysql && (!peer || (strlen(peer) < 128))) { + if (sql_is_good() && (!peer || (strlen(peer) < 128))) { char query[512]; char *name = NULL; int numfields, x; - int port; char iabuf[INET_ADDRSTRLEN]; - time_t regseconds, nowtime; +#ifdef MYSQL_FRIENDS MYSQL_RES *result; MYSQL_FIELD *fields; MYSQL_ROW rowval; +#endif +#ifdef ODBC_FRIENDS + const char* astodbc_result; + void* astodbc_query; +#endif if (peer) { name = alloca(strlen(peer) * 2 + 1); - mysql_real_escape_string(mysql, name, peer, strlen(peer)); + sql_escape_string(name, peer, strlen(peer)); } if (sin) - snprintf(query, sizeof(query), "SELECT name, secret, context, username, ipaddr, port, regseconds FROM sipfriends WHERE ipaddr=\"%s\" AND port=\"%d\"", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port)); + snprintf(query, sizeof(query), db_select_peer_bysin_query, + ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port)); else - snprintf(query, sizeof(query), "SELECT name, secret, context, username, ipaddr, port, regseconds FROM sipfriends WHERE name=\"%s\"", name); - ast_mutex_lock(&mysqllock); + snprintf(query, sizeof(query), db_select_peer_byname_query, + name); + sql_lock(); +#ifdef MYSQL_FRIENDS mysql_query(mysql, query); if ((result = mysql_store_result(mysql))) { if ((rowval = mysql_fetch_row(result))) { @@ -1138,39 +1451,52 @@ p->addr.sin_family = AF_INET; for (x=0;xsecret, rowval[x], sizeof(p->secret) - 1); - } else if (!strcasecmp(fields[x].name, "name")) { - strncpy(p->name, rowval[x], sizeof(p->name) - 1); - } else if (!strcasecmp(fields[x].name, "context")) { - strncpy(p->context, rowval[x], sizeof(p->context) - 1); - } else if (!strcasecmp(fields[x].name, "username")) { - strncpy(p->username, rowval[x], sizeof(p->username) - 1); - } else if (!strcasecmp(fields[x].name, "ipaddr")) { - inet_aton(rowval[x], &p->addr.sin_addr); - } else if (!strcasecmp(fields[x].name, "port")) { - if (sscanf(rowval[x], "%i", &port) != 1) - port = 0; - p->addr.sin_port = htons(port); - } else if (!strcasecmp(fields[x].name, "regseconds")) { - if (sscanf(rowval[x], "%li", ®seconds) != 1) - regseconds = 0; + if (set_sip_peer_property(p,fields[x].name,rowval[x],NULL,NULL) == 0) { + if (!strcasecmp(propName, "regseconds")) { + if (sscanf(propValue, "%li", ®seconds) != 1) + regseconds = 0; + } } } } - time(&nowtime); - if (nowtime > regseconds) - memset(&p->addr, 0, sizeof(p->addr)); } mysql_free_result(result); - result = NULL; } - ast_mutex_unlock(&mysqllock); +#endif +#ifdef ODBC_FRIENDS + astodbc_result = ast_odbc_query_new(dbconn,query,&astodbc_query); + if (strlen(astodbc_result)==0) { + numfields = ast_odbc_query_get_column_count(astodbc_query); + success = 1; + p->addr.sin_family = AF_INET; + for(x=0;x regseconds) { + memset(&p->addr, 0, sizeof(p->addr)); + } p->dynamic = 1; p->capability = global_capability; p->nat = global_nat; @@ -1179,18 +1505,18 @@ p->insecure = 1; p->expire = -1; p->temponly = 1; - + } return p; } -#endif /* MYSQL_FRIENDS */ +#endif /* SQL_FRIENDS */ /*--- update_peer: Update peer data in database (if used) ---*/ static void update_peer(struct sip_peer *p, int expiry) { -#ifdef MYSQL_FRIENDS +#ifdef SQL_FRIENDS if (p->temponly) - mysql_update_peer(p->name, &p->addr, p->username, expiry); + sql_update_peer(p->name, &p->addr, p->username, expiry); #endif return; } @@ -1208,12 +1534,12 @@ break; } p = p->next; - } + } } else { /* Find by sin */ while(p) { - if (!inaddrcmp(&p->addr, sin) || + if (!inaddrcmp(&p->addr, sin) || (p->insecure && (p->addr.sin_addr.s_addr == sin->sin_addr.s_addr))) { break; @@ -1222,9 +1548,9 @@ } } -#ifdef MYSQL_FRIENDS +#ifdef SQL_FRIENDS if (!p) { - p = mysql_peer(peer, sin); + p = sql_find_peer(peer, sin); } #endif @@ -1474,10 +1800,10 @@ char *osptoken = NULL; #ifdef OSP_SUPPORT char *osphandle = NULL; -#endif +#endif struct varshead *headp; struct ast_var_t *current; - + p = ast->pvt->pvt; if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { ast_log(LOG_WARNING, "sip_call called on %s, neither down nor reserved\n", ast->name); @@ -1505,7 +1831,7 @@ } #endif } - + res = 0; p->outgoing = 1; #ifdef OSP_SUPPORT @@ -1645,7 +1971,7 @@ u->inUse++; } ast_mutex_unlock(&userl.lock); - return -1; + return -1; } } u->inUse++; @@ -1743,7 +2069,7 @@ if ((p->osphandle > -1) && (ast->_state == AST_STATE_UP)) { ast_osp_terminate(p->osphandle, AST_CAUSE_NORMAL, p->ospstart, time(NULL) - p->ospstart); } -#endif +#endif if ( p->outgoing ) { ast_log(LOG_DEBUG, "update_user_counter(%s) - decrement outUse counter\n", p->username); update_user_counter(p, DEC_OUT_USE); @@ -1772,13 +2098,13 @@ ast_mutex_unlock(&usecnt_lock); ast_update_use_count(); - needdestroy = 1; + needdestroy = 1; /* Start the process if it's not already started */ if (!p->alreadygone && !ast_strlen_zero(p->initreq.data)) { if (needcancel) { if (p->outgoing) { transmit_request_with_auth(p, "CANCEL", p->ocseq, 1, 0); - /* Actually don't destroy us yet, wait for the 487 on our original + /* Actually don't destroy us yet, wait for the 487 on our original INVITE, but do set an autodestruct just in case we never get it. */ needdestroy = 0; sip_scheddestroy(p, 15000); @@ -1796,7 +2122,7 @@ char *res; if (ast->hangupcause && ((res = hangup_cause2sip(ast->hangupcause)))) { transmit_response_reliable(p, res, &p->initreq, 1); - } else + } else transmit_response_reliable(p, "403 Forbidden", &p->initreq, 1); } } else { @@ -1825,10 +2151,10 @@ ast_mutex_lock(&p->lock); if (ast->_state != AST_STATE_UP) { -#ifdef OSP_SUPPORT +#ifdef OSP_SUPPORT time(&p->ospstart); #endif - + codec=pbx_builtin_getvar_helper(p->owner,"SIP_CODEC"); if (codec) { fmt=ast_getformatbyname(codec); @@ -2166,7 +2492,7 @@ int len = strlen(name); char *r; for (x=*start;xheaders;x++) { - if (!strncasecmp(req->header[x], name, len) && + if (!strncasecmp(req->header[x], name, len) && (req->header[x][len] == ':')) { r = req->header[x] + len + 1; while(*r && (*r < 33)) @@ -2176,7 +2502,7 @@ } } /* Try aliases */ - for (x=0;xdtmfmode & SIP_DTMF_INBAND) && p->vad) { f = ast_dsp_process(p->owner,p->vad,f); - if (f && (f->frametype == AST_FRAME_DTMF)) + if (f && (f->frametype == AST_FRAME_DTMF)) ast_log(LOG_DEBUG, "Detected DTMF '%c'\n", f->subclass); } } @@ -2281,7 +2607,7 @@ p->stateid = -1; #ifdef OSP_SUPPORT p->osphandle = -1; -#endif +#endif if (sin) { memcpy(&p->sa, sin, sizeof(p->sa)); if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip)) @@ -2292,9 +2618,9 @@ p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); if (videosupport) p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); - p->branch = rand(); + p->branch = rand(); p->tag = rand(); - + /* Start with 101 instead of 1 */ p->ocseq = 101; if (!p->rtp) { @@ -2395,9 +2721,9 @@ if (c) *c = '\0'; } - + } - + if (ast_strlen_zero(callid)) { ast_log(LOG_WARNING, "Call missing call ID from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr)); return NULL; @@ -2405,7 +2731,7 @@ ast_mutex_lock(&iflock); p = iflist; while(p) { - if (!strcmp(p->callid, callid) && + if (!strcmp(p->callid, callid) && (!pedanticsipchecking || !tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) { /* Found the call */ ast_mutex_lock(&p->lock); @@ -2430,7 +2756,7 @@ char *porta=NULL; char *contact=NULL; char *stringp=NULL; - + if (!value) return -1; strncpy(copy, value, sizeof(copy)-1); @@ -2449,19 +2775,19 @@ username = strsep(&stringp, ":"); if (username) { secret = strsep(&stringp, ":"); - if (secret) + if (secret) authuser = strsep(&stringp, ":"); } stringp = hostname; hostname = strsep(&stringp, "/"); - if (hostname) + if (hostname) contact = strsep(&stringp, "/"); if (!contact || ast_strlen_zero(contact)) contact = "s"; stringp=hostname; hostname = strsep(&stringp, ":"); porta = strsep(&stringp, ":"); - + if (porta && !atoi(porta)) { ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno); return -1; @@ -2559,7 +2885,7 @@ #if 0 printf("Header: %s (%d)\n", req->header[f], strlen(req->header[f])); -#endif +#endif if (ast_strlen_zero(req->header[f])) { /* Line by itself means we're now in content */ c++; @@ -2577,7 +2903,7 @@ c++; } /* Check for last header */ - if (!ast_strlen_zero(req->header[f])) + if (!ast_strlen_zero(req->header[f])) f++; req->headers = f; /* Now we process any mime content */ @@ -2589,7 +2915,7 @@ *c = 0; #if 0 printf("Line: %s (%d)\n", req->line[f], strlen(req->line[f])); -#endif +#endif if (f >= SIP_MAX_LINES - 1) { ast_log(LOG_WARNING, "Too many SDP lines...\n"); } else @@ -2602,10 +2928,10 @@ c++; } /* Check for last line */ - if (!ast_strlen_zero(req->line[f])) + if (!ast_strlen_zero(req->line[f])) f++; req->lines = f; - if (*c) + if (*c) ast_log(LOG_WARNING, "Odd content, extra stuff left over ('%s')\n", c); } @@ -2754,7 +3080,7 @@ p->jointcapability = p->capability & (peercapability | vpeercapability); p->peercapability = (peercapability | vpeercapability); p->noncodeccapability = noncodeccapability & peernoncodeccapability; - + if (debug) { const unsigned slen=80; char s1[slen], s2[slen], s3[slen], s4[slen]; @@ -2778,7 +3104,7 @@ if (!(p->owner->nativeformats & p->jointcapability)) { const unsigned slen=80; char s1[slen], s2[slen]; - ast_log(LOG_DEBUG, "Oooh, we need to change our formats since our peer supports only %s and not %s\n", + ast_log(LOG_DEBUG, "Oooh, we need to change our formats since our peer supports only %s and not %s\n", ast_getformatname_multiple(s1, slen, p->jointcapability), ast_getformatname_multiple(s2, slen, p->owner->nativeformats)); p->owner->nativeformats = sip_codec_choose(p->jointcapability); @@ -2795,7 +3121,7 @@ } } return 0; - + } /*--- add_header: Add header to SIP message */ @@ -2818,7 +3144,7 @@ ast_log(LOG_WARNING, "Out of header space\n"); return -1; } - return 0; + return 0; } /*--- add_blank_header: Add blank header to SIP message */ @@ -2841,7 +3167,7 @@ ast_log(LOG_WARNING, "Out of header space\n"); return -1; } - return 0; + return 0; } /*--- add_line: Add content (not header) to SIP message */ @@ -2865,7 +3191,7 @@ ast_log(LOG_WARNING, "Out of line space\n"); return -1; } - return 0; + return 0; } /*--- copy_header: Copy one header field from one request to another */ @@ -3016,7 +3342,7 @@ if (hn > (sizeof(hostname) - 1)) hn = sizeof(hostname) - 1; strncpy(hostname, maddr, hn); hostname[hn] = '\0'; /* safe */ } - + hp = ast_gethostbyname(hostname, &ahp); if (hp == NULL) { ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname); @@ -3120,14 +3446,14 @@ char *ot, *of; memset(req, 0, sizeof(struct sip_request)); - + snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", msg); - + if (!seqno) { p->ocseq++; seqno = p->ocseq; } - + if (newbranch) { p->branch ^= rand(); if (p->nat & SIP_NAT_RFC3581) @@ -3145,9 +3471,9 @@ strncpy(stripped, get_header(orig, "To"), sizeof(stripped) - 1); else strncpy(stripped, get_header(orig, "From"), sizeof(stripped) - 1); - + c = strchr(stripped, '<'); - if (c) + if (c) c++; else c = stripped; @@ -3157,7 +3483,7 @@ n = strchr(c, ';'); if (n) *n = '\0'; - } + } init_req(req, msg, c); snprintf(tmp, sizeof(tmp), "%d %s", seqno, msg); @@ -3215,7 +3541,7 @@ } /*--- transmit_response: Transmit response, no retransmits */ -static int transmit_response(struct sip_pvt *p, char *msg, struct sip_request *req) +static int transmit_response(struct sip_pvt *p, char *msg, struct sip_request *req) { return __transmit_response(p, msg, req, 0); } @@ -3341,7 +3667,7 @@ return -1; } capability = p->capability; - + if (!p->sessionid) { p->sessionid = getpid(); p->sessionversion = p->sessionid; @@ -3372,9 +3698,9 @@ } } if (debug){ - ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(sin.sin_port)); + ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(sin.sin_port)); if (p->vrtp) - ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(vsin.sin_port)); + ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ntohs(vsin.sin_port)); } snprintf(v, sizeof(v), "v=0\r\n"); snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr)); @@ -3527,7 +3853,7 @@ char *e, *cmd; int len; - + cmd= req->header[0]; while(*cmd && (*cmd < 33)) { cmd++; @@ -3546,12 +3872,12 @@ } req->rlPart1= cmd; while( *e && ( *e < 33 ) ) { - e++; + e++; } if( !*e ) { return -1; } - + if ( !strcasecmp(cmd, "SIP/2.0") ) { /* We have a response */ req->rlPart2= e; @@ -3559,14 +3885,14 @@ if( len < 2 ) { return -1; } e+= len - 1; while( *e && *e<33 ) { - e--; + e--; } *(++e)= '\0'; } else { /* We have a request */ - if( *e == '<' ) { + if( *e == '<' ) { e++; - if( !*e ) { return -1; } + if( !*e ) { return -1; } } req->rlPart2= e; if( ( e= strrchr( req->rlPart2, 'S' ) ) == NULL ) { @@ -3590,9 +3916,9 @@ struct sip_request req; if (p->canreinvite == REINVITE_UPDATE) reqprep(&req, p, "UPDATE", 0, 1); - else + else reqprep(&req, p, "INVITE", 0, 1); - + add_header(&req, "Allow", ALLOWED_METHODS); ast_rtp_offered_from_local(p->rtp, 1); add_sdp(&req, p); @@ -3614,7 +3940,7 @@ char *c, *n; strncpy(stripped, get_header(req, "Contact"), sizeof(stripped) - 1); c = strchr(stripped, '<'); - if (c) + if (c) c++; else c = stripped; @@ -3656,7 +3982,7 @@ strncpy(cid, p->owner->callerid, sizeof(cid) - 1); cid[sizeof(cid) - 1] = '\0'; ast_callerid_parse(cid, &n, &l); - if (l) + if (l) ast_shrink_phone_number(l); if (!l || !ast_isphonenumber(l)) l = default_callerid; @@ -3718,13 +4044,13 @@ add_header(req, "User-Agent", default_useragent); } - + /*--- transmit_invite: Build REFER/INVITE/OPTIONS message and trasmit it ---*/ static int transmit_invite(struct sip_pvt *p, char *cmd, int sdp, char *auth, char *authheader, char *vxml_url, char *distinctive_ring, char *osptoken, int init) { struct sip_request req; char iabuf[INET_ADDRSTRLEN]; - + if (init) { /* Bump branch even on initial requests */ p->branch ^= rand(); @@ -3735,7 +4061,7 @@ initreqprep(&req, p, cmd, vxml_url); } else reqprep(&req, p, cmd, 0, 1); - + if (auth) add_header(&req, authheader, auth); append_date(&req); @@ -3748,7 +4074,7 @@ #ifdef OSP_SUPPORT if (osptoken && !ast_strlen_zero(osptoken)) { add_header(&req, "P-OSP-Auth-Token", osptoken); - } + } #endif if (distinctive_ring && !ast_strlen_zero(distinctive_ring)) { @@ -3825,7 +4151,7 @@ else state = 0; - t = tmp; + t = tmp; maxbytes = sizeof(tmp); bytes = snprintf(t, maxbytes, "\n"); t += bytes; @@ -3851,12 +4177,12 @@ bytes = snprintf(t, maxbytes, "\n", !state ? "online" : (state==1) ? "onthephone" : "offline"); t += bytes; maxbytes -= bytes; - bytes = snprintf(t, maxbytes, "\n\n\n"); + bytes = snprintf(t, maxbytes, "\n\n\n"); } else { add_header(&req, "Event", "dialog"); add_header(&req, "Content-Type", "application/dialog-info+xml"); - t = tmp; + t = tmp; maxbytes = sizeof(tmp); bytes = snprintf(t, maxbytes, "\n"); t += bytes; @@ -3870,7 +4196,7 @@ bytes = snprintf(t, maxbytes, "%s\n", state ? "confirmed" : "terminated"); t += bytes; maxbytes -= bytes; - bytes = snprintf(t, maxbytes, "\n\n"); + bytes = snprintf(t, maxbytes, "\n\n"); } if (t > tmp + sizeof(tmp)) ast_log(LOG_WARNING, "Buffer overflow detected!! (Please file a bug report)\n"); @@ -3953,7 +4279,7 @@ static int transmit_register(struct sip_registry *r, char *cmd, char *auth, char *authheader); /*--- sip_reregister: Update registration with SIP Proxy---*/ -static int sip_reregister(void *data) +static int sip_reregister(void *data) { /* if we are here, we know that we need to reregister. */ struct sip_registry *r=(struct sip_registry *)data; @@ -3980,7 +4306,7 @@ struct sip_pvt *p; int res; ast_mutex_lock(®l.lock); - ast_log(LOG_NOTICE, "Registration for '%s@%s' timed out, trying again\n", r->username, r->hostname); + ast_log(LOG_NOTICE, "Registration for '%s@%s' timed out, trying again\n", r->username, r->hostname); if (r->call) { /* Unlink us, destroy old call. Locking is not relevent here because all this happens in the single SIP manager thread. */ @@ -4057,7 +4383,7 @@ strncpy(p->exten, r->contact, sizeof(p->exten) - 1); /* - check which address we should use in our contact header + check which address we should use in our contact header based on whether the remote host is on the external or internal network so we can register through nat */ @@ -4083,7 +4409,7 @@ snprintf(from, sizeof(from), ";tag=as%08x", r->username, p->tohost, p->tag); snprintf(to, sizeof(to), "", r->username, p->tohost); } - + snprintf(addr, sizeof(addr), "sip:%s", r->hostname); strncpy(p->uri, addr, sizeof(p->uri) - 1); @@ -4106,7 +4432,7 @@ add_header(&req, "Call-ID", p->callid); add_header(&req, "CSeq", tmp); add_header(&req, "User-Agent", default_useragent); - if (auth) + if (auth) add_header(&req, authheader, auth); snprintf(tmp, sizeof(tmp), "%d", default_expiry); @@ -4140,7 +4466,7 @@ char from[256]; char *of, *c; char referto[256]; - if (p->outgoing) + if (p->outgoing) of = get_header(&p->initreq, "To"); else of = get_header(&p->initreq, "From"); @@ -4163,8 +4489,8 @@ } /* save in case we get 407 challenge */ - strncpy(p->refer_to, referto, sizeof(p->refer_to) - 1); - strncpy(p->referred_by, p->our_contact, sizeof(p->referred_by) - 1); + strncpy(p->refer_to, referto, sizeof(p->refer_to) - 1); + strncpy(p->referred_by, p->our_contact, sizeof(p->referred_by) - 1); reqprep(&req, p, "REFER", 0, 1); add_header(&req, "Refer-To", referto); @@ -4209,7 +4535,7 @@ add_header(&resp, "Content-Length", "0"); add_blank_header(&resp); - return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq); + return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq); } static void register_peer_exten(struct sip_peer *peer, int onoff) @@ -4275,9 +4601,9 @@ strncpy(p->fullcontact, e, sizeof(p->fullcontact) - 1); } strncpy(p->username, u, sizeof(p->username) - 1); - + } - ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding '%s' at %s@%s:%d for %d\n", p->name, + ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding '%s' at %s@%s:%d for %d\n", p->name, p->username, ast_inet_ntoa(iabuf, sizeof(iabuf), in), atoi(c), atoi(d)); expiry = atoi(d); memset(&p->addr, 0, sizeof(p->addr)); @@ -4289,8 +4615,8 @@ ast_sched_del(sched, p->expire); p->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, (void *)p); register_peer_exten(p, 1); - } - + } + } } } @@ -4299,7 +4625,7 @@ /*--- parse_contact: Parse contact header and save registration ---*/ static int parse_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_request *req) { - char contact[80]= ""; + char contact[80]= ""; char data[256]; char iabuf[INET_ADDRSTRLEN]; char *expires = get_header(req, "Expires"); @@ -4323,12 +4649,12 @@ /* Look for brackets */ strncpy(contact, get_header(req, "Contact"), sizeof(contact) - 1); c = contact; - + if ((n=strchr(c, '<'))) { c = n + 1; n = strchr(c, '>'); /* Lose the part after the > */ - if (n) + if (n) *n = '\0'; } if (!strcasecmp(c, "*") || !expiry) { @@ -4416,7 +4742,7 @@ if(useragent && strcasecmp(useragent, p->useragent)) { strncpy(p->useragent, useragent, sizeof(p->useragent) - 1); if (option_verbose > 3) { - ast_verbose(VERBOSE_PREFIX_3 "Saved useragent \"%s\" for peer %s\n",p->useragent,p->name); + ast_verbose(VERBOSE_PREFIX_3 "Saved useragent \"%s\" for peer %s\n",p->useragent,p->name); } } return 0; @@ -4464,9 +4790,9 @@ free_old_route(p->route); p->route = NULL; } - + p->route_persistant = backwards; - + /* We build up head, then assign it to p->route when we're done */ head = NULL; tail = head; /* 1st we pass through all the hops in any Record-Route headers */ @@ -4575,7 +4901,7 @@ /* Always OK if no secret */ if (ast_strlen_zero(secret) && ast_strlen_zero(md5secret) #ifdef OSP_SUPPORT - && !p->ospauth + && !p->ospauth #endif ) return 0; @@ -4597,7 +4923,7 @@ /* Validate token */ if (ast_osp_validate(NULL, osptoken, &p->osphandle, &osptimelimit, p->callerid, p->sa.sin_addr, p->exten) < 1) return -1; - + snprintf(tmp, sizeof(tmp), "%d", p->osphandle); pbx_builtin_setvar_helper(p->owner, "OSPHANDLE", tmp); @@ -4605,8 +4931,8 @@ if ((p->ospauth > 1) || (ast_strlen_zero(secret) && ast_strlen_zero(md5secret))) return 0; } -#endif - authtoken = get_header(req, reqheader); +#endif + authtoken = get_header(req, reqheader); if (ignore && !ast_strlen_zero(randdata) && ast_strlen_zero(authtoken)) { /* This is a retransmitted invite/register/etc, don't reconstruct authentication information */ @@ -4712,9 +5038,9 @@ p->stateid = -1; return 0; } - + transmit_state_notify(p, state, 1); - + if (option_debug) ast_verbose(VERBOSE_PREFIX_1 "Extension Changed %s new state %d for Notify User %s\n", exten, state, p->username); return 0; @@ -4734,7 +5060,7 @@ while(*t && (*t > 32) && (*t != ';')) t++; *t = '\0'; - + strncpy(tmp, get_header(req, "To"), sizeof(tmp) - 1); c = ditch_braces(tmp); /* Ditch ;user=phone */ @@ -4749,7 +5075,7 @@ ast_log(LOG_NOTICE, "Invalid to address: '%s' from %s (missing sip:) trying to use anyway...\n", c, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr)); } c = strchr(name, '@'); - if (c) + if (c) *c = '\0'; strncpy(p->exten, name, sizeof(p->exten) - 1); build_contact(p); @@ -4783,7 +5109,7 @@ peer->lastmsgssent = -1; res = 0; } - } + } } } if (!peer && autocreatepeer) { @@ -4823,7 +5149,7 @@ { char tmp[256] = "", *c, *a; struct sip_request *req; - + req = oreq; if (!req) req = &p->initreq; @@ -4852,17 +5178,17 @@ char tmp[256] = "", *c, *a; char tmpf[256]= "", *fr; struct sip_request *req; - + req = oreq; if (!req) req = &p->initreq; if (req->rlPart2) strncpy(tmp, req->rlPart2, sizeof(tmp) - 1); c = ditch_braces(tmp); - + strncpy(tmpf, get_header(req, "From"), sizeof(tmpf) - 1); fr = ditch_braces(tmpf); - + if (strncmp(c, "sip:", 4)) { ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); return -1; @@ -4908,7 +5234,7 @@ !strncmp(c, ast_pickup_ext(),strlen(c))) { return 1; } - + return -1; } @@ -4935,7 +5261,7 @@ char tmp5[256] = ""; /* CallID to replace */ struct sip_request *req; struct sip_pvt *p2; - + req = oreq; if (!req) req = &p->initreq; @@ -4943,11 +5269,11 @@ strncpy(tmp2, get_header(req, "Referred-By"), sizeof(tmp2) - 1); strncpy(tmp3, get_header(req, "Contact"), sizeof(tmp3) - 1); strncpy(tmp4, get_header(req, "Remote-Party-ID"), sizeof(tmp4) - 1); - + c = ditch_braces(tmp); c2 = ditch_braces(tmp2); - - + + if (strncmp(c, "sip:", 4) && strncmp(c2, "sip:", 4)) { ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c2); @@ -4971,38 +5297,38 @@ memmove(a + 1, a+3, strlen(a + 3) + 1); a++; } - if ((a = strchr(tmp5, '%'))) + if ((a = strchr(tmp5, '%'))) *a = '\0'; - if ((a = strchr(tmp5, ';'))) + if ((a = strchr(tmp5, ';'))) *a = '\0'; /* Skip leading whitespace */ while(tmp5[0] && (tmp5[0] < 33)) memmove(tmp5, tmp5+1, strlen(tmp5)); - + } } - + if ((a = strchr(c, '@'))) *a = '\0'; - if ((a = strchr(c, ';'))) + if ((a = strchr(c, ';'))) *a = '\0'; - + if ((a2 = strchr(c2, '@'))) *a2 = '\0'; - if ((a2 = strchr(c2, ';'))) + if ((a2 = strchr(c2, ';'))) *a2 = '\0'; - - + + if (sip_debug_test_pvt(p)) { ast_verbose("Looking for %s in %s\n", c, p->context); ast_verbose("Looking for %s in %s\n", c2, p->context); } - if (!ast_strlen_zero(tmp5)) { + if (!ast_strlen_zero(tmp5)) { /* This is a supervised transfer */ ast_log(LOG_DEBUG,"Assigning Replace-Call-ID Info %s to REPLACE_CALL_ID\n",tmp5); - + strncpy(p->refer_to, "", sizeof(p->refer_to) - 1); strncpy(p->referred_by, "", sizeof(p->referred_by) - 1); strncpy(p->refer_contact, "", sizeof(p->refer_contact) - 1); @@ -5055,15 +5381,15 @@ { char tmp[256] = "", *c, *a; struct sip_request *req; - + req = oreq; if (!req) req = &p->initreq; strncpy(tmp, get_header(req, "Also"), sizeof(tmp) - 1); - + c = ditch_braces(tmp); - - + + if (strncmp(c, "sip:", 4)) { ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); return -1; @@ -5071,9 +5397,9 @@ c += 4; if ((a = strchr(c, '@'))) *a = '\0'; - if ((a = strchr(c, ';'))) + if ((a = strchr(c, ';'))) *a = '\0'; - + if (sip_debug_test_pvt(p)) { ast_verbose("Looking for %s in %s\n", c, p->context); } @@ -5104,7 +5430,7 @@ memset(via, 0, sizeof(via)); strncpy(via, get_header(req, "Via"), sizeof(via) - 1); c = strchr(via, ';'); - if (c) + if (c) *c = '\0'; c = strchr(via, ' '); if (c) { @@ -5188,7 +5514,7 @@ return output; } -/*--- get_rpid_num: Get caller id number from Remote-Party-ID header field +/*--- get_rpid_num: Get caller id number from Remote-Party-ID header field * Returns true if number should be restricted (privacy setting found) * output is set to NULL if no number found */ @@ -5244,7 +5570,7 @@ rpid = get_header(req, "Remote-Party-ID"); memset(rpid_num,0,sizeof(rpid_num)); - if(!ast_strlen_zero(rpid)) + if(!ast_strlen_zero(rpid)) p->restrictcid = get_rpid_num(rpid,rpid_num, sizeof(rpid_num)); of = ditch_braces(from); @@ -5304,7 +5630,7 @@ sip_cancel_destroy(p); if (!ast_strlen_zero(user->context)) strncpy(p->context, user->context, sizeof(p->context) - 1); - if (!ast_strlen_zero(user->callerid) && !ast_strlen_zero(p->callerid)) + if (!ast_strlen_zero(user->callerid) && !ast_strlen_zero(p->callerid)) strncpy(p->callerid, user->callerid, sizeof(p->callerid) - 1); strncpy(p->username, user->name, sizeof(p->username) - 1); strncpy(p->peersecret, user->secret, sizeof(p->peersecret) - 1); @@ -5340,14 +5666,14 @@ #ifdef MYSQL_USERS if (user && user->temponly) free(user); -#endif +#endif ast_mutex_unlock(&userl.lock); if (!user) { /* If we didn't find a user match, check for peers */ ast_mutex_lock(&peerl.lock); /* Look for peer based on the IP address we received data from */ /* If peer is registred from this IP address or have this as a default - IP address, this call is from the peer + IP address, this call is from the peer */ peer = find_peer(NULL, &p->recv); if (peer) { @@ -5454,7 +5780,7 @@ return 0; } - + /*--- receive_message: Receive SIP MESSAGE method messages ---*/ /* we handle messages within current calls currently */ static void receive_message(struct sip_pvt *p, struct sip_request *req) @@ -5478,7 +5804,7 @@ } } -/*--- sip_show_inuse: CLI Command to show calls within limits set by +/*--- sip_show_inuse: CLI Command to show calls within limits set by outgoinglimit and incominglimit ---*/ static int sip_show_inuse(int fd, int argc, char *argv[]) { #define FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-15.15s\n" @@ -5488,7 +5814,7 @@ char olimits[40] = ""; char iused[40]; char oused[40]; - if (argc != 3) + if (argc != 3) return RESULT_SHOWUSAGE; ast_mutex_lock(&userl.lock); user = userl.users; @@ -5527,19 +5853,19 @@ return "Unknown"; } } - + /*--- sip_show_users: CLI Command 'SIP Show Users' ---*/ static int sip_show_users(int fd, int argc, char *argv[]) { #define FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-5.5s%-5.5s\n" struct sip_user *user; - if (argc != 3) + if (argc != 3) return RESULT_SHOWUSAGE; ast_mutex_lock(&userl.lock); ast_cli(fd, FORMAT, "Username", "Secret", "Accountcode", "Def.Context", "ACL", "NAT"); for(user=userl.users;user;user=user->next) { - ast_cli(fd, FORMAT, user->name, - user->secret, + ast_cli(fd, FORMAT, user->name, + user->secret, user->accountcode, user->context, user->ha ? "Yes" : "No", @@ -5576,13 +5902,13 @@ if (peer->maxms) { if (peer->lastms < 0) strncpy(status, "UNREACHABLE", sizeof(status) - 1); - else if (peer->lastms > peer->maxms) + else if (peer->lastms > peer->maxms) snprintf(status, sizeof(status), "LAGGED (%d ms)", peer->lastms); - else if (peer->lastms) + else if (peer->lastms) snprintf(status, sizeof(status), "OK (%d ms)", peer->lastms); - else + else strncpy(status, "UNKNOWN", sizeof(status) - 1); - } else + } else strncpy(status, "Unmonitored", sizeof(status) - 1); snprintf(srch, sizeof(srch), FORMAT, name, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)", @@ -5605,7 +5931,7 @@ } if (print_line) { - ast_cli(fd, FORMAT, name, + ast_cli(fd, FORMAT, name, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)", peer->dynamic ? " D " : " ", /* Dynamic or not? */ (peer->nat & SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */ @@ -5643,7 +5969,7 @@ } /*--- print_group: Print call group and pickup group ---*/ -static void print_group(int fd, unsigned int group) +static void print_group(int fd, unsigned int group) { unsigned int i; int first=1; @@ -5740,7 +6066,7 @@ ast_cli(fd, "PNG "); if (peer->capability & AST_FORMAT_H261) ast_cli(fd, "H.261 "); - if (peer->capability & AST_FORMAT_H263) + if (peer->capability & AST_FORMAT_H263) ast_cli(fd, "H.263 "); ast_cli(fd, "\n"); ast_cli(fd, " Status : "); @@ -5754,7 +6080,7 @@ strncpy(status, "UNKNOWN", sizeof(status) - 1); ast_cli(fd, "%s\n",status); ast_cli(fd, " Useragent : %s\n", peer->useragent); - ast_cli(fd, " Full Contact : %s\n", peer->fullcontact); + ast_cli(fd, " Full Contact : %s\n", peer->fullcontact); ast_cli(fd,"\n"); } else { ast_cli(fd,"Peer %s not found.\n", argv[3]); @@ -5791,11 +6117,11 @@ static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions); /*--- sip_show_channels: Show active SIP channels ---*/ -static int sip_show_channels(int fd, int argc, char *argv[]) +static int sip_show_channels(int fd, int argc, char *argv[]) { return __sip_show_channels(fd, argc, argv, 0); } - + /*--- sip_show_subscriptions: Show active SIP subscriptions ---*/ static int sip_show_subscriptions(int fd, int argc, char *argv[]) { @@ -5820,16 +6146,16 @@ ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "URI"); while (cur) { if (!cur->subscribed && !subscriptions) { - ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), - ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->callerid) ? "(None)" : cur->callerid ) : cur->username, - cur->callid, - cur->ocseq, cur->icseq, + ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), + ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->callerid) ? "(None)" : cur->callerid ) : cur->username, + cur->callid, + cur->ocseq, cur->icseq, ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), cur->needdestroy ? "(d)" : "" ); numchans++; } if (cur->subscribed && subscriptions) { ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), - ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->callerid) ? "(None)" : cur->callerid ) : cur->username, + ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->callerid) ? "(None)" : cur->callerid ) : cur->username, cur->callid, cur->uri); } @@ -5925,7 +6251,7 @@ cur = cur->next; } ast_mutex_unlock(&iflock); - if (!found) + if (!found) ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); return RESULT_SUCCESS; } @@ -5966,7 +6292,7 @@ cur = cur->next; } ast_mutex_unlock(&iflock); - if (!found) + if (!found) ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); return RESULT_SUCCESS; } @@ -5981,7 +6307,7 @@ char resp = 0; struct ast_frame f; char *c; - + /* Need to check the media/type */ if (!strcasecmp(get_header(req, "Content-Type"), "application/dtmf-relay")) { @@ -5993,7 +6319,7 @@ } else { strncpy(buf, c, sizeof(buf) - 1); } - + if (p->owner) { /* PBX call */ if (!ast_strlen_zero(buf)) { if (sipdebug) @@ -6078,13 +6404,13 @@ return RESULT_SHOWUSAGE; ast_mutex_lock(&peerl.lock); for (peer = peerl.peers;peer;peer = peer->next) - if (!strcmp(peer->name, argv[3])) + if (!strcmp(peer->name, argv[3])) break; ast_mutex_unlock(&peerl.lock); -#ifdef MYSQL_FRIENDS +#ifdef SQL_FRIENDS if (!peer) - peer = mysql_peer(argv[3], NULL); -#endif + peer = sql_find_peer(argv[3], NULL); +#endif if (peer) { if (peer->addr.sin_addr.s_addr) { debugaddr.sin_family = AF_INET; @@ -6105,7 +6431,7 @@ static int sip_do_debug(int fd, int argc, char *argv[]) { if (argc != 2) { - if (argc != 4) + if (argc != 4) return RESULT_SHOWUSAGE; else if (strncmp(argv[2], "ip\0", 3) == 0) return sip_do_debug_ip(fd, argc, argv); @@ -6160,7 +6486,7 @@ /* There's nothing to use for authentication */ return -1; } - return transmit_register(p->registry,"REGISTER",digest, respheader); + return transmit_register(p->registry,"REGISTER",digest, respheader); } /*--- do_proxy_auth: Challenge user ---*/ @@ -6172,7 +6498,7 @@ /* No way to authenticate */ return -1; } - return transmit_invite(p,msg,!strcasecmp(msg, "INVITE"),digest, respheader, NULL,NULL,NULL, init); + return transmit_invite(p,msg,!strcasecmp(msg, "INVITE"),digest, respheader, NULL,NULL,NULL, init); } /*--- reply_digest: reply to authentication for outbound registrations ---*/ @@ -6190,7 +6516,7 @@ strncpy(tmp, get_header(req, header),sizeof(tmp) - 1); - if (ast_strlen_zero(tmp)) + if (ast_strlen_zero(tmp)) return -1; c = tmp; c+=strlen("Digest "); @@ -6267,12 +6593,12 @@ strncpy(p->domain, domain, sizeof(p->domain)-1); strncpy(p->opaque, opaque, sizeof(p->opaque)-1); strncpy(p->qop, qop, sizeof(p->qop)-1); - build_reply_digest(p, orig_header, digest, digest_len); + build_reply_digest(p, orig_header, digest, digest_len); return 0; } /*--- build_reply_digest: Build reply digest ---*/ -/* Build digest challenge for authentication of peers (for registration) +/* Build digest challenge for authentication of peers (for registration) and users (for calls). Also used for authentication of CANCEL and BYE */ static int build_reply_digest(struct sip_pvt *p, char* orig_header, char* digest, int digest_len) { @@ -6317,31 +6643,31 @@ return 0; } - -static char show_users_usage[] = + +static char show_users_usage[] = "Usage: sip show users\n" " Lists all users known to the SIP (Session Initiation Protocol) subsystem.\n"; -static char show_inuse_usage[] = +static char show_inuse_usage[] = "Usage: sip show inuse\n" " List all users known to the SIP (Session Initiation Protocol) subsystem usage counters and limits.\n"; -static char show_channels_usage[] = +static char show_channels_usage[] = "Usage: sip show channels\n" " Lists all currently active SIP channels.\n"; -static char show_channel_usage[] = +static char show_channel_usage[] = "Usage: sip show channel \n" " Provides detailed status on a given SIP channel.\n"; -static char show_history_usage[] = +static char show_history_usage[] = "Usage: sip show history \n" " Provides detailed dialog history on a given SIP channel.\n"; -static char show_peers_usage[] = +static char show_peers_usage[] = "Usage: sip show peers\n" " Lists all known SIP peers.\n"; @@ -6353,7 +6679,7 @@ "Usage: sip show registry\n" " Lists all registration requests and status.\n"; -static char debug_usage[] = +static char debug_usage[] = "Usage: sip debug\n" " Enables dumping of SIP packets for debugging purposes\n\n" " sip debug ip \n" @@ -6362,15 +6688,15 @@ " Enables dumping of SIP packets to and from host.\n" " Require peer to be registered.\n"; -static char no_debug_usage[] = +static char no_debug_usage[] = "Usage: sip no debug\n" " Disables dumping of SIP packets for debugging purposes\n"; -static char no_history_usage[] = +static char no_history_usage[] = "Usage: sip no history\n" " Disables recording of SIP dialog history for debugging purposes\n"; -static char history_usage[] = +static char history_usage[] = "Usage: sip history\n" " Enables recording of SIP dialog history for debugging purposes.\n" "Use 'sip show hitory' to view the history of a call number.\n"; @@ -6380,11 +6706,11 @@ " Reloads SIP configuration from sip.conf\n"; static char show_subscriptions_usage[] = -"Usage: sip show subscriptions\n" +"Usage: sip show subscriptions\n" " Shows active SIP subscriptions for extension states\n"; -static struct ast_cli_entry cli_show_users = +static struct ast_cli_entry cli_show_users = { { "sip", "show", "users", NULL }, sip_show_users, "Show defined SIP users", show_users_usage }; static struct ast_cli_entry cli_show_subscriptions = { { "sip", "show", "subscriptions", NULL }, sip_show_subscriptions, "Show active SIP subscriptions", show_subscriptions_usage}; @@ -6493,7 +6819,7 @@ msg = strchr(c, ' '); if (!msg) msg = ""; else msg++; owner = p->owner; - if (owner) + if (owner) owner->hangupcause = hangup_sip2cause(resp); /* Acknowledge whatever it is destined for */ if ((resp >= 100) && (resp <= 199)) @@ -6511,7 +6837,7 @@ *to = '\0'; } if (p->peerpoke) { - /* We don't really care what the response is, just that it replied back. + /* We don't really care what the response is, just that it replied back. Well, as long as it's not a 100 response... since we might need to hang around for something more "difinitive" */ if (resp != 100) { @@ -6564,7 +6890,7 @@ sip_cancel_destroy(p); } break; - case 183: + case 183: if (!strcasecmp(msg, "INVITE")) { sip_cancel_destroy(p); if (!ast_strlen_zero(get_header(req, "Content-Type"))) @@ -6604,7 +6930,7 @@ build_route(p, req, 1); if (p->owner) { if (p->owner->_state != AST_STATE_UP) { -#ifdef OSP_SUPPORT +#ifdef OSP_SUPPORT time(&p->ospstart); #endif ast_queue_control(p->owner, AST_CONTROL_ANSWER); @@ -6673,7 +6999,7 @@ expires_ms -= EXPIRY_GUARD_SECS * 1000; r->refresh= (int) expires_ms / 1000; - r->expire=ast_sched_add(sched, expires_ms, sip_reregister, r); + r->expire=ast_sched_add(sched, expires_ms, sip_reregister, r); } else ast_log(LOG_WARNING, "Got 200 OK on REGISTER that isn't a register\n"); @@ -6788,7 +7114,7 @@ ast_queue_control(p->owner, AST_CONTROL_CONGESTION); break; default: - /* Send hangup */ + /* Send hangup */ if (owner) ast_queue_hangup(p->owner); break; @@ -6871,7 +7197,7 @@ strncpy(chan1m->context, chan1->context, sizeof(chan1m->context) - 1); strncpy(chan1m->exten, chan1->exten, sizeof(chan1m->exten) - 1); chan1m->priority = chan1->priority; - + /* We make a clone of the peer channel too, so we can play back the announcement */ snprintf(chan2m->name, sizeof (chan2m->name), "SIPPeer/%s",chan2->name); @@ -6990,7 +7316,7 @@ /* Determine the request URI for sip, sips or tel URIs */ if( determine_firstline_parts( req ) < 0 ) { - return -1; + return -1; } cmd= req->rlPart1; e= req->rlPart2; @@ -6999,14 +7325,14 @@ useragent = get_header(req, "User-Agent"); strncpy(p->useragent, useragent, sizeof(p->useragent)-1); - + if (strcasecmp(cmd, "SIP/2.0")) { - /* Request coming in */ + /* Request coming in */ if (p->icseq && (p->icseq > seqno)) { ast_log(LOG_DEBUG, "Ignoring too old packet packet %d (expecting >= %d)\n", seqno, p->icseq); return -1; } else if (p->icseq && (p->icseq == seqno)) { - /* ignore means "don't do anything with it" but still have to + /* ignore means "don't do anything with it" but still have to respond appropriately. We do this if we receive a repeat of the last sequence number */ ignore=1; @@ -7024,7 +7350,7 @@ } snprintf(p->lastmsg, sizeof(p->lastmsg), "Rx: %s", cmd); } else { - /* Response to our request -- Do some sanity checks */ + /* Response to our request -- Do some sanity checks */ if (!p->initreq.headers) { ast_log(LOG_DEBUG, "That's odd... Got a response on a call we dont know about.\n"); p->needdestroy = 1; @@ -7033,14 +7359,14 @@ ast_log(LOG_DEBUG, "Ignoring out of order response %d (expecting %d)\n", seqno, p->ocseq); return -1; } else if (p->ocseq && (p->ocseq != seqno)) { - /* ignore means "don't do anything with it" but still have to + /* ignore means "don't do anything with it" but still have to respond appropriately */ ignore=1; } } - + if (strcmp(cmd, "SIP/2.0") && (seqno >= p->icseq)) - /* Next should follow monotonically (but not necessarily + /* Next should follow monotonically (but not necessarily incrementally -- thanks again to the genius authors of SIP -- increasing */ p->icseq = seqno; @@ -7056,7 +7382,7 @@ transmit_response_with_allow(p, "404 Not Found", req, 0); else if (res > 0) transmit_response_with_allow(p, "484 Address Incomplete", req, 0); - else + else transmit_response_with_allow(p, "200 OK", req, 0); /* Destroy if this OPTIONS was the opening request, but not if it's in the middle of a normal call flow. */ @@ -7147,7 +7473,7 @@ /* If no extension was specified, use the s one */ if (ast_strlen_zero(p->exten)) strncpy(p->exten, "s", sizeof(p->exten) - 1); - /* Initialize tag */ + /* Initialize tag */ p->tag = rand(); /* First invitation */ c = sip_new(p, AST_STATE_DOWN, ast_strlen_zero(p->username) ? NULL : p->username ); @@ -7159,8 +7485,8 @@ ast_mutex_lock(&c->lock); } } - - } else + + } else c = p->owner; if (!ignore && p) p->lastinvite = seqno; @@ -7390,7 +7716,7 @@ transmit_response(p, "484 Address Incomplete", req); p->needdestroy = 1; } else { - /* Initialize tag */ + /* Initialize tag */ p->tag = rand(); if (!strcmp(get_header(req, "Accept"), "application/dialog-info+xml")) p->subscribed = 2; @@ -7410,14 +7736,14 @@ transmit_response(p, "403 Forbidden", req); p->needdestroy = 1; } - + } else p->subscribed = 1; if (p->subscribed) p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, p); } - - } else + + } else c = p->owner; if (!ignore && p) @@ -7429,7 +7755,7 @@ return 0; } /* The next line can be removed if the SNOM200 Expires bug is fixed */ - if (p->subscribed == 1) { + if (p->subscribed == 1) { if (p->expiry>max_expiry) p->expiry = max_expiry; } @@ -7456,7 +7782,7 @@ ast_verbose("Using latest request as basis request\n"); copy_request(&p->initreq, req); check_via(p, req); - if ((res = register_verify(p, sin, req, e, ignore)) < 0) + if ((res = register_verify(p, sin, req, e, ignore)) < 0) ast_log(LOG_NOTICE, "Registration from '%s' failed for '%s'\n", get_header(req, "To"), ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr)); if (res < 1) { /* Destroy the session, but keep us around for just a bit in case they don't @@ -7471,7 +7797,7 @@ if (!ast_strlen_zero(get_header(req, "Content-Type"))) { if (process_sdp(p, req)) return -1; - } + } check_pendings(p); } if (!p->lastinvite && ast_strlen_zero(p->randdata)) @@ -7486,7 +7812,7 @@ } } else { transmit_response_with_allow(p, "405 Method Not Allowed", req, 0); - ast_log(LOG_NOTICE, "Unknown SIP command '%s' from '%s'\n", + ast_log(LOG_NOTICE, "Unknown SIP command '%s' from '%s'\n", cmd, ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr)); /* If this is some new method, and we don't have a call, destroy it now */ if (!p->initreq.headers) @@ -7576,15 +7902,15 @@ int newmsgs, oldmsgs; /* Check for messages */ ast_app_messagecount(peer->mailbox, &newmsgs, &oldmsgs); - + time(&peer->lastmsgcheck); - + /* Return now if it's the same thing we told them last time */ if (((newmsgs << 8) | (oldmsgs)) == peer->lastmsgssent) { ast_mutex_unlock(&peerl.lock); return 0; } - + p = sip_alloc(NULL, NULL, 0); if (!p) { ast_log(LOG_WARNING, "Unable to build sip pvt data for MWI\n"); @@ -7627,9 +7953,9 @@ int curpeernum; int reloading; /* Add an I/O event to our UDP socket */ - if (sipsock > -1) + if (sipsock > -1) ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); - + /* This thread monitors all the frame relay interfaces which are not yet in use (and thus do not have a separate thread) indefinitely */ /* From here on out, we die whenever asked */ @@ -7646,7 +7972,7 @@ } /* Check for interfaces needing to be killed */ ast_mutex_lock(&iflock); -restartsearch: +restartsearch: time(&t); sip = iflist; while(sip) { @@ -7656,8 +7982,8 @@ /* Might be a timeout now -- see if we're on hold */ struct sockaddr_in sin; ast_rtp_get_peer(sip->rtp, &sin); - if (sin.sin_addr.s_addr || - (sip->rtpholdtimeout && + if (sin.sin_addr.s_addr || + (sip->rtpholdtimeout && (t > sip->lastrtprx + sip->rtpholdtimeout))) { /* Needs a hangup */ if (sip->rtptimeout) { @@ -7704,7 +8030,7 @@ res = 1; res = ast_io_wait(io, res); ast_mutex_lock(&monlock); - if (res >= 0) + if (res >= 0) ast_sched_runq(sched); /* needs work to send mwi to mysql peers */ ast_mutex_lock(&peerl.lock); @@ -7732,7 +8058,7 @@ } /* Never reached */ return NULL; - + } /*--- restart_monitor: Start the channel monitor thread ---*/ @@ -7772,7 +8098,7 @@ static int sip_poke_noanswer(void *data) { struct sip_peer *peer = data; - + peer->pokeexpire = -1; if (peer->lastms > -1) ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE!\n", peer->name); @@ -7996,9 +8322,9 @@ !strcasecmp(v->name, "deny")) { user->ha = ast_append_ha(v->name, v->value, user->ha); } else if (!strcasecmp(v->name, "secret")) { - strncpy(user->secret, v->value, sizeof(user->secret)-1); + strncpy(user->secret, v->value, sizeof(user->secret)-1); } else if (!strcasecmp(v->name, "md5secret")) { - strncpy(user->md5secret, v->value, sizeof(user->secret)-1); + strncpy(user->md5secret, v->value, sizeof(user->secret)-1); } else if (!strcasecmp(v->name, "promiscredir")) { user->promiscredir = ast_true(v->value); } else if (!strcasecmp(v->name, "dtmfmode")) { @@ -8056,13 +8382,13 @@ } } else if (!strcasecmp(v->name, "allow")) { format = ast_getformatbyname(v->value); - if (format < 1) + if (format < 1) ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value); else user->capability |= format; } else if (!strcasecmp(v->name, "disallow")) { format = ast_getformatbyname(v->value); - if (format < 1) + if (format < 1) ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value); else user->capability &= ~format; @@ -8136,13 +8462,12 @@ struct sip_peer *prev; struct ast_ha *oldha = NULL; int maskfound=0; - int format; int found=0; prev = NULL; ast_mutex_lock(&peerl.lock); peer = peerl.peers; while(peer) { - if (!strcasecmp(peer->name, name)) { + if (!strcasecmp(peer->name, name)) { break; } prev = peer; @@ -8192,156 +8517,17 @@ peer->ospauth = global_ospauth; #endif while(v) { - if (!strcasecmp(v->name, "secret")) - strncpy(peer->secret, v->value, sizeof(peer->secret)-1); - else if (!strcasecmp(v->name, "md5secret")) - strncpy(peer->md5secret, v->value, sizeof(peer->md5secret)-1); - else if (!strcasecmp(v->name, "canreinvite")) { - if (!strcasecmp(v->value, "update")) - peer->canreinvite = REINVITE_UPDATE; - else - peer->canreinvite = ast_true(v->value); - } else if (!strcasecmp(v->name, "nat")) { - if (!strcasecmp(v->value, "rfc3581")) - peer->nat = SIP_NAT_RFC3581; - else if (!strcasecmp(v->value, "route")) - peer->nat = SIP_NAT_ROUTE; - else if (ast_true(v->value)) - peer->nat = SIP_NAT_ALWAYS; - else - peer->nat = SIP_NAT_NEVER; - } else if (!strcasecmp(v->name, "context")) - strncpy(peer->context, v->value, sizeof(peer->context)-1); - else if (!strcasecmp(v->name, "fromdomain")) - strncpy(peer->fromdomain, v->value, sizeof(peer->fromdomain)-1); - else if (!strcasecmp(v->name, "promiscredir")) - peer->promiscredir = ast_true(v->value); - else if (!strcasecmp(v->name, "fromuser")) - strncpy(peer->fromuser, v->value, sizeof(peer->fromuser)-1); - else if (!strcasecmp(v->name, "dtmfmode")) { - if (!strcasecmp(v->value, "inband")) - peer->dtmfmode=SIP_DTMF_INBAND; - else if (!strcasecmp(v->value, "rfc2833")) - peer->dtmfmode = SIP_DTMF_RFC2833; - else if (!strcasecmp(v->value, "info")) - peer->dtmfmode = SIP_DTMF_INFO; - else { - ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n", v->value); - peer->dtmfmode = SIP_DTMF_RFC2833; - } - } else if (!strcasecmp(v->name, "host")) { - if (!strcasecmp(v->value, "dynamic")) { - /* They'll register with us */ - peer->dynamic = 1; - if (!found) { - /* Initialize stuff iff we're not found, otherwise - we keep going with what we had */ - memset(&peer->addr.sin_addr, 0, 4); - if (peer->addr.sin_port) { - /* If we've already got a port, make it the default rather than absolute */ - peer->defaddr.sin_port = peer->addr.sin_port; - peer->addr.sin_port = 0; - } - } - } else { - /* Non-dynamic. Make sure we become that way if we're not */ - if (peer->expire > -1) - ast_sched_del(sched, peer->expire); - peer->expire = -1; - peer->dynamic = 0; - if (ast_get_ip(&peer->addr, v->value)) { - free(peer); - return NULL; - } - strncpy(peer->tohost, v->value, sizeof(peer->tohost) - 1); - } - if (!maskfound) - inet_aton("255.255.255.255", &peer->mask); - } else if (!strcasecmp(v->name, "defaultip")) { - if (ast_get_ip(&peer->defaddr, v->value)) { - free(peer); - return NULL; - } - } else if (!strcasecmp(v->name, "permit") || - !strcasecmp(v->name, "deny")) { - peer->ha = ast_append_ha(v->name, v->value, peer->ha); - } else if (!strcasecmp(v->name, "mask")) { - maskfound++; - inet_aton(v->value, &peer->mask); - } else if (!strcasecmp(v->name, "port")) { - if (peer->dynamic) - peer->defaddr.sin_port = htons(atoi(v->value)); - else - peer->addr.sin_port = htons(atoi(v->value)); - } else if (!strcasecmp(v->name, "username")) { - strncpy(peer->username, v->value, sizeof(peer->username)-1); - } else if (!strcasecmp(v->name, "language")) { - strncpy(peer->language, v->value, sizeof(peer->language)-1); - } else if (!strcasecmp(v->name, "regexten")) { - strncpy(peer->regexten, v->value, sizeof(peer->regexten)-1); - } else if (!strcasecmp(v->name, "musiconhold")) { - strncpy(peer->musicclass, v->value, sizeof(peer->musicclass)-1); - } else if (!strcasecmp(v->name, "mailbox")) { - strncpy(peer->mailbox, v->value, sizeof(peer->mailbox)-1); - } else if (!strcasecmp(v->name, "callgroup")) { - peer->callgroup = ast_get_group(v->value); - } else if (!strcasecmp(v->name, "pickupgroup")) { - peer->pickupgroup = ast_get_group(v->value); - } else if (!strcasecmp(v->name, "allow")) { - format = ast_getformatbyname(v->value); - if (format < 1) - ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value); - else - peer->capability |= format; - } else if (!strcasecmp(v->name, "disallow")) { - format = ast_getformatbyname(v->value); - if (format < 1) - ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value); - else - peer->capability &= ~format; - } else if (!strcasecmp(v->name, "insecure")) { - if (!strcasecmp(v->value, "very")) { - peer->insecure = 2; - } else if (ast_true(v->value)) - peer->insecure = 1; - else - peer->insecure = 0; - } else if (!strcasecmp(v->name, "rtptimeout")) { - if ((sscanf(v->value, "%d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) { - ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); - peer->rtptimeout = global_rtptimeout; - } - } else if (!strcasecmp(v->name, "rtpholdtimeout")) { - if ((sscanf(v->value, "%d", &peer->rtpholdtimeout) != 1) || (peer->rtpholdtimeout < 0)) { - ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); - peer->rtpholdtimeout = global_rtpholdtimeout; - } - } else if (!strcasecmp(v->name, "qualify")) { - if (!strcasecmp(v->value, "no")) { - peer->maxms = 0; - } else if (!strcasecmp(v->value, "yes")) { - peer->maxms = DEFAULT_MAXMS; - } else if (sscanf(v->value, "%d", &peer->maxms) != 1) { - ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno); - peer->maxms = 0; - } - } else if (!strcasecmp(v->name, "trustrpid")) { - peer->trustrpid = ast_true(v->value); - } else if (!strcasecmp(v->name, "progressinband")) { - peer->progressinband = ast_true(v->value); -#ifdef OSP_SUPPORT - } else if (!strcasecmp(v->name, "ospauth")) { - if (!strcasecmp(v->value, "exclusive")) { - peer->ospauth = 2; - } else if (ast_true(v->value)) { - peer->ospauth = 1; - } else - peer->ospauth = 0; -#endif - } - /* else if (strcasecmp(v->name,"type")) - * ast_log(LOG_WARNING, "Ignoring %s\n", v->name); - */ + int n = set_sip_peer_property(peer,v->name,v->value,&maskfound,&found); + if( n<0 ) { + free(peer); + return NULL; + } + else if( n==0 ) { + /* ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */ + } + else { + /* the property was found */ + } v=v->next; } if (!found && peer->dynamic && (sipsock > -1)) @@ -8370,7 +8556,7 @@ global_dtmfmode = SIP_DTMF_RFC2833; global_promiscredir = 0; - + if (gethostname(ourhost, sizeof(ourhost))) { ast_log(LOG_WARNING, "Unable to get hostname, SIP disabled\n"); return 0; @@ -8382,11 +8568,11 @@ ast_log(LOG_NOTICE, "Unable to load config %s, SIP disabled\n", config); return 0; } - + global_nat = SIP_NAT_RFC3581; - + sip_prefs_free(); - + memset(&bindaddr, 0, sizeof(bindaddr)); memset(&localaddr, 0, sizeof(localaddr)); memset(&externip, 0, sizeof(externip)); @@ -8515,13 +8701,13 @@ } else if (!strcasecmp(v->name, "localmask")) { ast_log(LOG_WARNING, "Use of localmask is no long supported -- use localnet with mask syntax\n"); } else if (!strcasecmp(v->name, "externip")) { - if (!(hp = ast_gethostbyname(v->value, &ahp))) + if (!(hp = ast_gethostbyname(v->value, &ahp))) ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", v->value); else memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr)); } else if (!strcasecmp(v->name, "allow")) { format = ast_getformatbyname(v->value); - if (format < 1) + if (format < 1) ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value); else { global_capability |= format; @@ -8529,7 +8715,7 @@ } } else if (!strcasecmp(v->name, "disallow")) { format = ast_getformatbyname(v->value); - if (format < 1) + if (format < 1) ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value); else { global_capability &= ~format; @@ -8570,13 +8756,26 @@ } else if (!strcasecmp(v->name, "dbname")) { strncpy(mydbname, v->value, sizeof(mydbname) - 1); #endif +#ifdef ODBC_FRIENDS + } else if (!strcasecmp(v->name, "dbconn_string")) { + strncpy(dbconn_string, v->value, sizeof(dbconn_string) - 1); +#endif +#ifdef SQL_FRIENDS + } + else if (!strcasecmp(v->name, "db_select_peer_byname_query")) { + strncpy(db_select_peer_byname_query, v->value, sizeof(db_select_peer_byname_query) - 1); + } else if (!strcasecmp(v->name, "db_select_peer_bysin_query")) { + strncpy(db_select_peer_bysin_query, v->value, sizeof(db_select_peer_bysin_query) - 1); + } else if (!strcasecmp(v->name, "db_update_peer_query")) { + strncpy(db_update_peer_query, v->value, sizeof(db_update_peer_query) - 1); +#endif } /* else if (strcasecmp(v->name,"type")) * ast_log(LOG_WARNING, "Ignoring %s\n", v->name); */ v = v->next; } - + cat = ast_category_browse(cfg, NULL); while(cat) { if (strcasecmp(cat, "general")) { @@ -8607,7 +8806,7 @@ } cat = ast_category_browse(cfg, cat); } - + if (ntohl(bindaddr.sin_addr.s_addr)) { memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip)); } else { @@ -8647,12 +8846,12 @@ close(sipsock); sipsock = -1; } else { - if (option_verbose > 1) { - ast_verbose(VERBOSE_PREFIX_2 "SIP Listening on %s:%d\n", + if (option_verbose > 1) { + ast_verbose(VERBOSE_PREFIX_2 "SIP Listening on %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port)); ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos); } - if (setsockopt(sipsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) + if (setsockopt(sipsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); } } @@ -8675,6 +8874,16 @@ mydbname, mydbhost, mydbuser); } #endif +#ifdef ODBC_FRIENDS + if (!dbconn && !ast_strlen_zero(dbconn_string)) { + const char* odbc_result = ast_odbc_conn_new(dbconn_string,1,0,&dbconn); + if (strlen(odbc_result) > 0) { + ast_log(LOG_WARNING, "Error Logging into database %s: %s\n",dbconn_string,odbc_result); + dbconn = NULL; + } else + ast_verbose(VERBOSE_PREFIX_1 "Connected to ODBC database\n"); + } +#endif return 0; } @@ -8789,7 +8998,7 @@ static int sip_get_codec(struct ast_channel *chan) { struct sip_pvt *p = chan->pvt->pvt; - return p->peercapability; + return p->peercapability; } static struct ast_rtp_protocol sip_rtp = { @@ -8837,7 +9046,7 @@ } regl.registrations = NULL; ast_mutex_unlock(®l.lock); - + ast_mutex_lock(&peerl.lock); for (peer=peerl.peers;peer;) { /* Assume all will be deleted, and we'll find out for sure later */ @@ -8888,7 +9097,7 @@ prune_peers(); /* And start the monitor for the first time */ ast_mutex_lock(®l.lock); - for (reg = regl.registrations; reg; reg = reg->next) + for (reg = regl.registrations; reg; reg = reg->next) __sip_do_register(reg); ast_mutex_unlock(®l.lock); ast_mutex_lock(&peerl.lock); @@ -8939,7 +9148,7 @@ if (!io) { ast_log(LOG_WARNING, "Unable to create I/O context\n"); } - + res = reload_config(); if (!res) { /* Make sure we can register our sip channel type */ @@ -8975,10 +9184,10 @@ ast_mutex_unlock(&peerl.lock); ast_mutex_lock(®l.lock); - for (reg = regl.registrations; reg; reg = reg->next) + for (reg = regl.registrations; reg; reg = reg->next) __sip_do_register(reg); ast_mutex_unlock(®l.lock); - + /* And start the monitor for the first time */ restart_monitor(); } @@ -8988,7 +9197,7 @@ int unload_module() { struct sip_pvt *p, *pl; - + /* First, take us out of the channel loop */ ast_unregister_application(app_dtmfmode); ast_cli_unregister(&cli_show_users); @@ -9062,7 +9271,7 @@ ast_mutex_destroy(&userl.lock); ast_mutex_destroy(&peerl.lock); ast_mutex_destroy(®l.lock); - + return 0; }