--- chan_sip.c 2004-11-26 15:14:55.000000000 +0000 +++ /home/brian/chan_sip_new.c 2004-11-26 15:14:13.000000000 +0000 @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -76,27 +75,12 @@ /* guard limit must be larger than guard secs */ /* guard min must be < 1000, and should be >= 250 */ -<<<<<<< chan_sip.c #define EXPIRY_GUARD_SECS 15 /* How long before expiry do we reregister */ #define EXPIRY_GUARD_LIMIT 30 /* Below here, we use EXPIRY_GUARD_PCT instead of EXPIRY_GUARD_SECS */ #define EXPIRY_GUARD_MIN 500 /* This is the minimum guard time applied. If GUARD_PCT turns out to be lower than this, it will use this time instead. This is in milliseconds. */ #define EXPIRY_GUARD_PCT 0.20 /* Percentage of expires timeout to use when below EXPIRY_GUARD_LIMIT */ -======= -#define EXPIRY_GUARD_SECS 15 /* How long before expiry do we reregister */ -#define EXPIRY_GUARD_LIMIT 30 /* Below here, we use EXPIRY_GUARD_PCT instead of - EXPIRY_GUARD_SECS */ -#define EXPIRY_GUARD_MIN 500 /* This is the minimum guard time applied. If - GUARD_PCT turns out to be lower than this, it - will use this time instead. - This is in milliseconds. */ -#define EXPIRY_GUARD_PCT 0.20 /* Percentage of expires timeout to use when - below EXPIRY_GUARD_LIMIT */ - -static int max_expiry = DEFAULT_MAX_EXPIRY; -static int default_expiry = DEFAULT_DEFAULT_EXPIRY; ->>>>>>> 1.576 #ifndef MAX #define MAX(a,b) ((a) > (b) ? (a) : (b)) @@ -105,18 +89,13 @@ #define CALLERID_UNKNOWN "Unknown" /* --- Choices for DTMF support in SIP channel */ -<<<<<<< chan_sip.c #define SIP_DTMF_RFC2833 (1 << 0) #define SIP_DTMF_INBAND (1 << 1) #define SIP_DTMF_INFO (1 << 2) -======= -#define SIP_DTMF_RFC2833 (1 << 0) /* RTP DTMF */ -#define SIP_DTMF_INBAND (1 << 1) /* Inband audio, only for ULAW/ALAW */ -#define SIP_DTMF_INFO (1 << 2) /* SIP Info messages */ ->>>>>>> 1.576 +static int max_expiry = DEFAULT_MAX_EXPIRY; +static int default_expiry = DEFAULT_DEFAULT_EXPIRY; -<<<<<<< chan_sip.c #define DEFAULT_MAXMS 2000 /* Must be faster than 2 seconds by default */ #define DEFAULT_FREQ_OK 60 * 1000 /* How often to check for the host to be up */ #define DEFAULT_FREQ_NOTOK 10 * 1000 /* How often to check, if the host is down... */ @@ -127,60 +106,36 @@ /* SIP Debug */ #define DEBUG_READ 0 /* Recieved data */ #define DEBUG_SEND 1 /* Transmit data */ -======= -#define DEFAULT_MAXMS 2000 /* Must be faster than 2 seconds by default */ -#define DEFAULT_FREQ_OK 60 * 1000 /* How often to check for the host to be up */ -#define DEFAULT_FREQ_NOTOK 10 * 1000 /* How often to check, if the host is down... */ - -#define DEFAULT_RETRANS 1000 /* How frequently to retransmit */ -#define MAX_RETRANS 5 /* Try only 5 times for retransmissions */ - - /* SIP Debug */ -#define DEBUG_READ 0 /* Recieved data */ -#define DEBUG_SEND 1 /* Transmit data */ ->>>>>>> 1.576 static char *desc = "Session Initiation Protocol (SIP)"; static char *type = "SIP"; static char *tdesc = "Session Initiation Protocol (SIP)"; static char *config = "sip.conf"; -<<<<<<< chan_sip.c #define DEFAULT_SIP_PORT 5060 /* From RFC 2543 */ #define SIP_MAX_PACKET 4096 /* Also from RFC 2543, should sub headers tho */ -======= -#define DEFAULT_SIP_PORT 5060 /* From RFC 2543 */ -#define SIP_MAX_PACKET 4096 /* Also from RFC 2543, should sub headers tho */ ->>>>>>> 1.576 #define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER" static char default_useragent[AST_MAX_EXTENSION] = DEFAULT_USERAGENT; -#define DEFAULT_CONTEXT "default" -static char default_context[AST_MAX_EXTENSION] = DEFAULT_CONTEXT; +static char default_context[AST_MAX_EXTENSION] = "default"; static char default_language[MAX_LANGUAGE] = ""; -#define DEFAULT_CALLERID "asterisk" -static char default_callerid[AST_MAX_EXTENSION] = DEFAULT_CALLERID; +static char default_callerid[AST_MAX_EXTENSION] = "asterisk"; static char default_fromdomain[AST_MAX_EXTENSION] = ""; -#define DEFAULT_NOTIFYMIME "application/simple-message-summary" -static char default_notifymime[AST_MAX_EXTENSION] = DEFAULT_NOTIFYMIME; +static char notifymime[AST_MAX_EXTENSION] = "application/simple-message-summary"; -static int srvlookup = 0; /* SRV Lookup on or off. Default is off, RFC behavior is on */ +static int srvlookup = 0; -static int pedanticsipchecking = 0; /* Extra checking ? Default off */ +static int pedanticsipchecking = 0; -<<<<<<< chan_sip.c static int autocreatepeer = 0; static char* regscript = ""; -======= -static int autocreatepeer = 0; /* Auto creation of peers at registration? Default off. */ ->>>>>>> 1.576 static int relaxdtmf = 0; @@ -188,17 +143,14 @@ static int global_rtpholdtimeout = 0; -static int global_trustrpid = 0; /* Trust RPID headers? Default off. */ +static int global_trustrpid = 0; static int global_progressinband = 0; #ifdef OSP_SUPPORT -static int global_ospauth = 0; /* OSP = Open Settlement Protocol */ +static int global_ospauth = 0; #endif -#define DEFAULT_MWITIME 10 -static int global_mwitime = DEFAULT_MWITIME; /* Time between MWI checks for peers */ - static int usecnt =0; AST_MUTEX_DEFINE_STATIC(usecnt_lock); @@ -234,23 +186,16 @@ static int global_dtmfmode = SIP_DTMF_RFC2833; /* DTMF mode default */ static int recordhistory = 0; -static int global_promiscredir; /* Support of 302 REDIR - Default off */ +static int global_promiscredir; -<<<<<<< chan_sip.c static char global_musicclass[MAX_LANGUAGE] = ""; /* Global music on hold class */ static char global_realm[AST_MAX_EXTENSION] = "asterisk"; /* Default realm */ static char regcontext[AST_MAX_EXTENSION] = ""; -======= -static char global_musicclass[MAX_LANGUAGE] = ""; /* Global music on hold class */ -static char global_realm[AST_MAX_EXTENSION] = "asterisk"; /* Default realm */ -static char regcontext[AST_MAX_EXTENSION] = ""; /* Context for auto-extensions */ ->>>>>>> 1.576 static FILE *shell_file; /* Expire slowly */ -#define DEFAULT_EXPIRY 900 -static int expiry = DEFAULT_EXPIRY; +static int expiry = 900; static struct sched_context *sched; static struct io_context *io; @@ -272,7 +217,6 @@ /* sip_request: The data grabbed from the UDP socket */ struct sip_request { -<<<<<<< chan_sip.c char *rlPart1; /* SIP Method Name or "SIP/2.0" protocol version */ char *rlPart2; /* The Request URI or Response Status */ int len; @@ -281,16 +225,6 @@ int lines; /* SDP Content */ char *line[SIP_MAX_LINES]; char data[SIP_MAX_PACKET]; -======= - char *rlPart1; /* SIP Method Name or "SIP/2.0" protocol version */ - char *rlPart2; /* The Request URI or Response Status */ - int len; /* Length */ - int headers; /* # of SIP Headers */ - char *header[SIP_MAX_HEADERS]; - int lines; /* SDP Content */ - char *line[SIP_MAX_LINES]; - char data[SIP_MAX_PACKET]; ->>>>>>> 1.576 }; struct sip_pkt; @@ -307,7 +241,6 @@ /* sip_pvt: PVT structures are used for each SIP conversation, ie. a call */ static struct sip_pvt { -<<<<<<< chan_sip.c ast_mutex_t lock; /* Channel private lock */ char callid[80]; /* Global CallID */ char randdata[80]; /* Random data */ @@ -384,91 +317,11 @@ int needreinvite; /* Do we need to send another reinvite? */ int pendingbye; /* Need to send bye after we ack? */ int gotrefer; /* Got a refer? */ -======= - ast_mutex_t lock; /* Channel private lock */ - char callid[80]; /* Global CallID */ - char randdata[80]; /* Random data */ - unsigned int ocseq; /* Current outgoing seqno */ - unsigned int icseq; /* Current incoming seqno */ - unsigned int callgroup; /* Call group */ - unsigned int pickupgroup; /* Pickup group */ - int lastinvite; /* Last Cseq of invite */ - int alreadygone; /* Whether or not we've already been destroyed by or peer */ - int needdestroy; /* if we need to be destroyed */ - int capability; /* Special capability (codec) */ - int novideo; /* Didn't get video in invite, don't offer */ - int jointcapability; /* Supported capability at both ends (codecs ) */ - int peercapability; /* Supported peer capability */ - int prefcodec; /* Preferred codec (outbound only) */ - int noncodeccapability; - int callingpres; /* Calling presentation */ - int outgoing; /* Outgoing or incoming call? */ - int authtries; /* Times we've tried to authenticate */ - int insecure; /* Don't check source port/ip */ - int expiry; /* How long we take to expire */ - int branch; /* One random number */ - int canreinvite; /* Do we support reinvite */ - int ringing; /* Have sent 180 ringing */ - int progress; /* Have sent 183 message progress */ - int useclientcode; /* Trust X-ClientCode info message */ - int tag; /* Another random number */ - int nat; /* Whether to try to support NAT */ - int sessionid; /* SDP Session ID */ - int sessionversion; /* SDP Session Version */ - struct sockaddr_in sa; /* Our peer */ - struct sockaddr_in redirip; /* Where our RTP should be going if not to us */ - struct sockaddr_in vredirip; /* Where our Video RTP should be going if not to us */ - int redircodecs; /* Redirect codecs */ - struct sockaddr_in recv; /* Received as */ - struct in_addr ourip; /* Our IP */ - struct ast_channel *owner; /* Who owns us */ - char exten[AST_MAX_EXTENSION]; /* Extension where to start */ - char refer_to[AST_MAX_EXTENSION]; /* Place to store REFER-TO extension */ - char referred_by[AST_MAX_EXTENSION]; /* Place to store REFERRED-BY extension */ - char refer_contact[AST_MAX_EXTENSION]; /* Place to store Contact info from a REFER extension */ - struct sip_pvt *refer_call; /* Call we are referring */ - struct sip_route *route; /* Head of linked list of routing steps (fm Record-Route) */ - int route_persistant; /* Is this the "real" route? */ - char from[256]; /* The From: header */ - char useragent[256]; /* User agent in SIP request */ - char context[AST_MAX_EXTENSION]; /* Context for this call */ - char fromdomain[AST_MAX_EXTENSION]; /* Domain to show in the from field */ - char fromuser[AST_MAX_EXTENSION]; /* Domain to show in the user field */ - char tohost[AST_MAX_EXTENSION]; /* Host we should put in the "to" field */ - char language[MAX_LANGUAGE]; /* Default language for this call */ - char musicclass[MAX_LANGUAGE]; /* Music on Hold class */ - char rdnis[256]; /* Referring DNIS */ - char theirtag[256]; /* Their tag */ - char username[256]; - char peername[256]; - char authname[256]; /* Who we use for authentication */ - char uri[256]; /* Original requested URI */ - char peersecret[256]; /* Password */ - char peermd5secret[256]; - char cid_num[256]; /* Caller*ID */ - char cid_name[256]; /* Caller*ID */ - char via[256]; /* Via: header */ - char fullcontact[128]; /* The Contact: that the UA registers with us */ - char accountcode[20]; /* Account code */ - char our_contact[256]; /* Our contact header */ - char realm[256]; /* Authorization realm */ - char nonce[256]; /* Authorization nonce */ - char opaque[256]; /* Opaque nonsense */ - char qop[80]; /* Quality of Protection, since SIP wasn't complicated enough yet. */ - char domain[256]; /* Authorization nonce */ - char lastmsg[256]; /* Last Message sent/received */ - int amaflags; /* AMA Flags */ - int pendinginvite; /* Any pending invite */ - int needreinvite; /* Do we need to send another reinvite? */ - int pendingbye; /* Need to send bye after we ack? */ - int gotrefer; /* Got a refer? */ ->>>>>>> 1.576 #ifdef OSP_SUPPORT int ospauth; /* Allow OSP Authentication */ int osphandle; /* OSP Handle for call */ time_t ospstart; /* OSP Start time */ #endif -<<<<<<< chan_sip.c struct sip_request initreq; /* Initial request */ int maxtime; /* Max time for first response */ @@ -496,36 +349,6 @@ struct sip_pkt *packets; /* Packets scheduled for re-transmission */ struct sip_history *history; /* History of this SIP dialog */ struct sip_pvt *next; /* Next call in chain */ -======= - 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 */ - time_t lastrtprx; /* Last RTP received */ - int rtptimeout; /* RTP timeout time */ - int rtpholdtimeout; /* RTP timeout when on hold */ - - int subscribed; /* Is this call a subscription? */ - int stateid; - int dialogver; - int promiscredir; /* Promiscuous redirection */ - - int trustrpid; /* Trust RPID headers? */ - int progressinband; - - int dtmfmode; /* DTMF to use for this call */ - 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 */ - struct ast_rtp *vrtp; /* Video RTP session */ - struct sip_pkt *packets; /* Packets scheduled for re-transmission */ - struct sip_history *history; /* History of this SIP dialog */ - struct ast_variable *vars; - struct sip_pvt *next; /* Next call in chain */ ->>>>>>> 1.576 } *iflist = NULL; #define FLAG_RESPONSE (1 << 0) @@ -533,7 +356,6 @@ /* sip packet - read in sipsock_read, transmitted in send_request */ struct sip_pkt { -<<<<<<< chan_sip.c struct sip_pkt *next; /* Next packet */ int retrans; /* Retransmission number */ int seqno; /* Sequence number */ @@ -543,21 +365,9 @@ int packetlen; /* Length of packet */ char data[0]; }; -======= - struct sip_pkt *next; /* Next packet */ - int retrans; /* Retransmission number */ - int seqno; /* Sequence number */ - int flags; /* non-zero if this is a response packet (e.g. 200 OK) */ - struct sip_pvt *owner; /* Owner call */ - int retransid; /* Retransmission ID */ - int packetlen; /* Length of packet */ - char data[0]; -}; ->>>>>>> 1.576 /* Structure for SIP user data. User's place calls to us */ struct sip_user { -<<<<<<< chan_sip.c /* Users who can access various contexts */ char name[80]; char secret[80]; @@ -578,35 +388,9 @@ int insecure; int canreinvite; int capability; -======= - /* Users who can access various contexts */ - char name[80]; /* The name in sip.conf */ - char secret[80]; /* Password */ - char md5secret[80]; /* Password in md5 */ - char context[80]; /* Default context for incoming calls */ - char cid_num[80]; /* Caller ID num */ - char cid_name[80]; /* Caller ID name */ - char accountcode[20]; /* Account code */ - char language[MAX_LANGUAGE]; /* Default language for this user */ - char musicclass[MAX_LANGUAGE]; /* Music on Hold class */ - char useragent[256]; /* User agent in SIP request */ - unsigned int callgroup; /* Call group */ - unsigned int pickupgroup; /* Pickup Group */ - int nat; /* NAT setting */ - int amaflags; /* AMA flags for billing */ - int callingpres; /* Calling id presentation */ - int insecure; /* Insecure means don't check password */ - int canreinvite; /* Do we support re-invites ? */ - int capability; /* Codec capability */ ->>>>>>> 1.576 #ifdef OSP_SUPPORT -<<<<<<< chan_sip.c int ospauth; /* Allow OSP Authentication */ -======= - int ospauth; /* Allow OSP Authentication */ ->>>>>>> 1.576 #endif -<<<<<<< chan_sip.c int dtmfmode; int inUse; int incominglimit; @@ -618,26 +402,10 @@ struct ast_ha *ha; int temponly; struct sip_user *next; -======= - int dtmfmode; /* DTMF setting */ - int inUse; - int incominglimit; - int outUse; - int outgoinglimit; - int promiscredir; /* Support of 302 redirect */ - int useclientcode; /* SNOM clientcode support */ - int trustrpid; /* Trust remote party ID from this UA */ - int progressinband; - struct ast_ha *ha; /* ACL setting */ - int temponly; /* Flag for temporary users (realtime) */ - struct ast_variable *vars; - struct sip_user *next; ->>>>>>> 1.576 }; /* Structure for SIP peer data, we place calls to peers if registred or fixed IP address (host) */ struct sip_peer { -<<<<<<< chan_sip.c char name[80]; char secret[80]; char md5secret[80]; @@ -661,35 +429,7 @@ int rtptimeout; int rtpholdtimeout; int insecure; -======= - char name[80]; /* Peer name in sip.conf */ - char secret[80]; /* Password */ - char md5secret[80]; /* Password in MD5 */ - char context[80]; /* Default context for incoming calls */ - char username[80]; /* Temporary username until registration */ - char tohost[80]; /* If not dynamic, IP address */ - char regexten[AST_MAX_EXTENSION]; /* Extension to register (if regcontext is used) */ - char fromuser[80]; /* From: user when calling this peer */ - char fromdomain[80]; /* From: domain when calling this peer */ - char fullcontact[128]; /* Contact registred with us (not in sip.conf) */ - char cid_num[80]; /* Caller ID num */ - char cid_name[80]; /* Caller ID name */ - char mailbox[AST_MAX_EXTENSION]; /* Mailbox setting for MWI checks */ - char language[MAX_LANGUAGE]; /* Default language for prompts */ - char musicclass[MAX_LANGUAGE]; /* Music on Hold class */ - char useragent[256]; /* User agent in SIP request (saved from registration) */ - int lastmsgssent; - time_t lastmsgcheck; /* Last time we checked for MWI */ - int dynamic; /* Dynamic? Yes or no. Dynamic hosts register with us */ - int expire; /* Registration expiration */ - int expiry; - int capability; /* Codec capability */ - int rtptimeout; - int rtpholdtimeout; - int insecure; /* Do we want to authenticate this peer? */ ->>>>>>> 1.576 #ifdef OSP_SUPPORT -<<<<<<< chan_sip.c int ospauth; /* Allow OSP Authentication */ #endif int nat; @@ -717,42 +457,11 @@ int lastmsg; int temponly; struct sip_peer *next; -======= - int ospauth; /* Allow OSP Authentication */ -#endif - int nat; /* NAT support needed? */ - int canreinvite; /* Does the peer support re-invites? */ - unsigned int callgroup; /* Call group */ - unsigned int pickupgroup; /* Pickup group */ - int promiscredir; /* Support of 302 redirect? */ - int dtmfmode; /* DTMF mode */ - int trustrpid; /* Trust Remote Party ID headers? */ - int useclientcode; /* SNOM clientcode support */ - int progressinband; - struct sockaddr_in addr; /* IP address of peer */ - struct in_addr mask; - - /* Qualification */ - struct sip_pvt *call; /* Call pointer */ - int pokeexpire; /* When to expire poke (qualify= checking) */ - 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; /* Default IP address, used until registration */ - struct ast_ha *ha; /* Access control list */ - int delme; - int selfdestruct; - int lastmsg; - int temponly; - struct sip_peer *next; ->>>>>>> 1.576 }; AST_MUTEX_DEFINE_STATIC(sip_reload_lock); static int sip_reloading = 0; -<<<<<<< chan_sip.c #define REG_STATE_UNREGISTERED 0 #define REG_STATE_REGSENT 1 #define REG_STATE_AUTHSENT 2 @@ -765,26 +474,9 @@ #define SIP_NAT_RFC3581 (1 << 0) #define SIP_NAT_ROUTE (1 << 2) #define SIP_NAT_ALWAYS (SIP_NAT_ROUTE | SIP_NAT_RFC3581) -======= -/* States for outbound registrations (with register= lines in sip.conf */ -#define REG_STATE_UNREGISTERED 0 -#define REG_STATE_REGSENT 1 -#define REG_STATE_AUTHSENT 2 -#define REG_STATE_REGISTERED 3 -#define REG_STATE_REJECTED 4 -#define REG_STATE_TIMEOUT 5 -#define REG_STATE_NOAUTH 6 - -/* NAT settings */ -#define SIP_NAT_NEVER 0 /* No nat support */ -#define SIP_NAT_RFC3581 (1 << 0) -#define SIP_NAT_ROUTE (1 << 2) -#define SIP_NAT_ALWAYS (SIP_NAT_ROUTE | SIP_NAT_RFC3581) ->>>>>>> 1.576 /* sip_registry: Registrations with other SIP proxies */ struct sip_registry { -<<<<<<< chan_sip.c int portno; /* Optional port override */ char username[80]; /* Who we are registering as */ char authuser[80]; /* Who we *authenticate* as */ @@ -803,26 +495,6 @@ unsigned int ocseq; /* Sequence number we got to for REGISTERs for this registry */ struct sockaddr_in us; /* Who the server thinks we are */ struct sip_registry *next; -======= - int portno; /* Optional port override */ - char username[80]; /* Who we are registering as */ - char authuser[80]; /* Who we *authenticate* as */ - char hostname[80]; /* Domain or host we register to */ - char secret[80]; /* Password or key name in []'s */ - char md5secret[80]; - char contact[80]; /* Contact extension */ - char random[80]; - int expire; /* Sched ID of expiration */ - int timeout; /* sched id of sip_reg_timeout */ - int refresh; /* How often to refresh */ - struct sip_pvt *call; /* create a sip_pvt structure for each outbound "registration call" in progress */ - int regstate; /* Registration state (see above) */ - int callid_valid; /* 0 means we haven't chosen callid for this registry yet. */ - char callid[80]; /* Global CallID for this registry */ - unsigned int ocseq; /* Sequence number we got to for REGISTERs for this registry */ - struct sockaddr_in us; /* Who the server thinks we are */ - struct sip_registry *next; ->>>>>>> 1.576 }; /*--- The user list: Users and friends ---*/ @@ -978,7 +650,6 @@ /*--- retrans_pkt: Retransmit SIP message if no answer ---*/ static int retrans_pkt(void *data) { -<<<<<<< chan_sip.c struct sip_pkt *pkt=data, *prev, *cur; int res = 0; char iabuf[INET_ADDRSTRLEN]; @@ -1035,65 +706,6 @@ if (pkt) ast_mutex_unlock(&pkt->owner->lock); return res; -======= - struct sip_pkt *pkt=data, *prev, *cur; - int res = 0; - char iabuf[INET_ADDRSTRLEN]; - ast_mutex_lock(&pkt->owner->lock); - if (pkt->retrans < MAX_RETRANS) { - pkt->retrans++; - if (sip_debug_test_pvt(pkt->owner)) { - if (pkt->owner->nat & SIP_NAT_ROUTE) - ast_verbose("Retransmitting #%d (NAT):\n%s\n to %s:%d\n", pkt->retrans, pkt->data, ast_inet_ntoa(iabuf, sizeof(iabuf), pkt->owner->recv.sin_addr), ntohs(pkt->owner->recv.sin_port)); - else - ast_verbose("Retransmitting #%d (no NAT):\n%s\n to %s:%d\n", pkt->retrans, pkt->data, ast_inet_ntoa(iabuf, sizeof(iabuf), pkt->owner->sa.sin_addr), ntohs(pkt->owner->sa.sin_port)); - } - append_history(pkt->owner, "ReTx", pkt->data); - __sip_xmit(pkt->owner, pkt->data, pkt->packetlen); - res = 1; - } else { - ast_log(LOG_WARNING, "Maximum retries exceeded on call %s for seqno %d (%s %s)\n", pkt->owner->callid, pkt->seqno, (pkt->flags & FLAG_FATAL) ? "Critical" : "Non-critical", (pkt->flags & FLAG_RESPONSE) ? "Response" : "Request"); - append_history(pkt->owner, "MaxRetries", pkt->flags & FLAG_FATAL ? "(Critical)" : "(Non-critical)"); - pkt->retransid = -1; - if (pkt->flags & FLAG_FATAL) { - while(pkt->owner->owner && ast_mutex_trylock(&pkt->owner->owner->lock)) { - ast_mutex_unlock(&pkt->owner->lock); - usleep(1); - ast_mutex_lock(&pkt->owner->lock); - } - if (pkt->owner->owner) { - pkt->owner->alreadygone=1; - ast_queue_hangup(pkt->owner->owner); - ast_mutex_unlock(&pkt->owner->owner->lock); - } else { - /* If no owner, destroy now */ - pkt->owner->needdestroy = 1; - } - } - /* In any case, go ahead and remove the packet */ - prev = NULL; - cur = pkt->owner->packets; - while(cur) { - if (cur == pkt) - break; - prev = cur; - cur = cur->next; - } - if (cur) { - if (prev) - prev->next = cur->next; - else - pkt->owner->packets = cur->next; - ast_mutex_unlock(&pkt->owner->lock); - free(cur); - pkt = NULL; - } else - ast_log(LOG_WARNING, "Weird, couldn't find packet owner!\n"); - } - if (pkt) - ast_mutex_unlock(&pkt->owner->lock); - return res; ->>>>>>> 1.576 } /*--- __sip_reliable_xmit: transmit packet with retransmits ---*/ @@ -1529,17 +1141,8 @@ static void destroy_user(struct sip_user *user) { -<<<<<<< chan_sip.c ast_free_ha(user->ha); free(user); -======= - ast_free_ha(user->ha); - if(user->vars) { - ast_destroy_realtime(user->vars); - user->vars = NULL; - } - free(user); ->>>>>>> 1.576 } static struct sip_user *build_user(const char *name, struct ast_variable *v); @@ -1597,7 +1200,6 @@ /* returns TRUE on failure, FALSE on success */ static int create_addr(struct sip_pvt *r, char *opeer) { -<<<<<<< chan_sip.c struct hostent *hp; struct ast_hostent ahp; struct sip_peer *p; @@ -1720,130 +1322,6 @@ } return 0; } -======= - struct hostent *hp; - struct ast_hostent ahp; - struct sip_peer *p; - int found=0; - char *port; - char *callhost; - int portno; - char host[256], *hostn; - char peer[256]=""; - - strncpy(peer, opeer, sizeof(peer) - 1); - port = strchr(peer, ':'); - if (port) { - *port = '\0'; - port++; - } - r->sa.sin_family = AF_INET; - ast_mutex_lock(&peerl.lock); - p = find_peer(peer, NULL); - - if (p) { - found++; - r->capability = p->capability; - r->nat = p->nat; - if (r->rtp) { - ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (r->nat & SIP_NAT_ROUTE)); - ast_rtp_setnat(r->rtp, (r->nat & SIP_NAT_ROUTE)); - } - if (r->vrtp) { - ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (r->nat & SIP_NAT_ROUTE)); - ast_rtp_setnat(r->vrtp, (r->nat & SIP_NAT_ROUTE)); - } - strncpy(r->peername, p->username, sizeof(r->peername)-1); - strncpy(r->authname, p->username, sizeof(r->authname)-1); - strncpy(r->peersecret, p->secret, sizeof(r->peersecret)-1); - strncpy(r->peermd5secret, p->md5secret, sizeof(r->peermd5secret)-1); - strncpy(r->username, p->username, sizeof(r->username)-1); - strncpy(r->tohost, p->tohost, sizeof(r->tohost)-1); - strncpy(r->fullcontact, p->fullcontact, sizeof(r->fullcontact)-1); - if (!r->initreq.headers && !ast_strlen_zero(p->fromdomain)) { - if ((callhost = strchr(r->callid, '@'))) { - strncpy(callhost + 1, p->fromdomain, sizeof(r->callid) - (callhost - r->callid) - 2); - } - } - if (ast_strlen_zero(r->tohost)) { - if (p->addr.sin_addr.s_addr) - ast_inet_ntoa(r->tohost, sizeof(r->tohost), p->addr.sin_addr); - else - ast_inet_ntoa(r->tohost, sizeof(r->tohost), p->defaddr.sin_addr); - } - if (!ast_strlen_zero(p->fromdomain)) - strncpy(r->fromdomain, p->fromdomain, sizeof(r->fromdomain)-1); - if (!ast_strlen_zero(p->fromuser)) - strncpy(r->fromuser, p->fromuser, sizeof(r->fromuser)-1); - r->insecure = p->insecure; - r->canreinvite = p->canreinvite; - r->maxtime = p->maxms; - r->callgroup = p->callgroup; - r->pickupgroup = p->pickupgroup; - if (p->dtmfmode) { - r->dtmfmode = p->dtmfmode; - if (r->dtmfmode & SIP_DTMF_RFC2833) - r->noncodeccapability |= AST_RTP_DTMF; - else - r->noncodeccapability &= ~AST_RTP_DTMF; - } - r->promiscredir = p->promiscredir; - strncpy(r->context, p->context,sizeof(r->context)-1); - if ((p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) && - (!p->maxms || ((p->lastms >= 0) && (p->lastms <= p->maxms)))) { - if (p->addr.sin_addr.s_addr) { - r->sa.sin_addr = p->addr.sin_addr; - r->sa.sin_port = p->addr.sin_port; - } else { - r->sa.sin_addr = p->defaddr.sin_addr; - r->sa.sin_port = p->defaddr.sin_port; - } - memcpy(&r->recv, &r->sa, sizeof(r->recv)); - } else { - if (p->temponly) { - destroy_peer(p); - } - p = NULL; - } - } - ast_mutex_unlock(&peerl.lock); - if (!p && !found) { - hostn = peer; - if (port) - portno = atoi(port); - else - portno = DEFAULT_SIP_PORT; - if (srvlookup) { - char service[256]; - int tportno; - int ret; - snprintf(service, sizeof(service), "_sip._udp.%s", peer); - ret = ast_get_srv(NULL, host, sizeof(host), &tportno, service); - if (ret > 0) { - hostn = host; - portno = tportno; - } - } - hp = ast_gethostbyname(hostn, &ahp); - if (hp) { - strncpy(r->tohost, peer, sizeof(r->tohost) - 1); - memcpy(&r->sa.sin_addr, hp->h_addr, sizeof(r->sa.sin_addr)); - r->sa.sin_port = htons(portno); - memcpy(&r->recv, &r->sa, sizeof(r->recv)); - return 0; - } else { - ast_log(LOG_WARNING, "No such host: %s\n", peer); - return -1; - } - } else if (!p) - return -1; - else { - if (p->temponly) { - destroy_peer(p); - } - return 0; - } ->>>>>>> 1.576 } /*--- auto_congest: Scheduled congestion on a call ---*/ @@ -1939,7 +1417,6 @@ char *distinctive_ring = NULL; char *osptoken = NULL; #ifdef OSP_SUPPORT -<<<<<<< chan_sip.c char *osphandle = NULL; #endif struct varshead *headp; @@ -1964,43 +1441,12 @@ { distinctive_ring = ast_var_value(current); } -======= - char *osphandle = NULL; -#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); - return -1; - } - /* Check whether there is vxml_url, distinctive ring variables */ - - headp=&ast->varshead; - AST_LIST_TRAVERSE(headp,current,entries) { - /* Check whether there is a VXML_URL variable */ - if (!vxml_url && !strcasecmp(ast_var_name(current),"VXML_URL")) { - vxml_url = ast_var_value(current); - } else if (!distinctive_ring && !strcasecmp(ast_var_name(current),"ALERT_INFO")) { - /* Check whether there is a ALERT_INFO variable */ - distinctive_ring = ast_var_value(current); - } ->>>>>>> 1.576 #ifdef OSP_SUPPORT -<<<<<<< chan_sip.c else if (!strcasecmp(ast_var_name(current), "OSPTOKEN")) { osptoken = ast_var_value(current); } else if (!strcasecmp(ast_var_name(current), "OSPHANDLE")) { osphandle = ast_var_value(current); } -======= - else if (!osptoken && !strcasecmp(ast_var_name(current), "OSPTOKEN")) { - osptoken = ast_var_value(current); - } else if (!osphandle && !strcasecmp(ast_var_name(current), "OSPHANDLE")) { - osphandle = ast_var_value(current); - } ->>>>>>> 1.576 #endif } @@ -2031,7 +1477,6 @@ /*--- __sip_destroy: Execute destrucion of call structure, release memory---*/ static void __sip_destroy(struct sip_pvt *p, int lockowner) { -<<<<<<< chan_sip.c struct sip_pvt *cur, *prev = NULL; struct sip_pkt *cp; struct sip_history *hist; @@ -2108,88 +1553,6 @@ ast_mutex_destroy(&p->lock); free(p); } -======= - struct sip_pvt *cur, *prev = NULL; - struct sip_pkt *cp; - struct sip_history *hist; - - if (sip_debug_test_pvt(p)) - ast_verbose("Destroying call '%s'\n", p->callid); - if (p->stateid > -1) - ast_extension_state_del(p->stateid, NULL); - if (p->initid > -1) - ast_sched_del(sched, p->initid); - if (p->autokillid > -1) - ast_sched_del(sched, p->autokillid); - - if (p->rtp) { - ast_rtp_destroy(p->rtp); - } - if (p->vrtp) { - ast_rtp_destroy(p->vrtp); - } - if (p->route) { - free_old_route(p->route); - p->route = NULL; - } - if (p->registry) { - /* Carefully unlink from registry */ - struct sip_registry *reg; - ast_mutex_lock(®l.lock); - reg = regl.registrations; - while(reg) { - if ((reg == p->registry) && (p->registry->call == p)) - p->registry->call=NULL; - reg = reg->next; - } - ast_mutex_unlock(®l.lock); - } - /* Unlink us from the owner if we have one */ - if (p->owner) { - if (lockowner) - ast_mutex_lock(&p->owner->lock); - ast_log(LOG_DEBUG, "Detaching from %s\n", p->owner->name); - p->owner->pvt->pvt = NULL; - if (lockowner) - ast_mutex_unlock(&p->owner->lock); - } - /* Clear history */ - while(p->history) { - hist = p->history; - p->history = p->history->next; - free(hist); - } - cur = iflist; - while(cur) { - if (cur == p) { - if (prev) - prev->next = cur->next; - else - iflist = cur->next; - break; - } - prev = cur; - cur = cur->next; - } - if (!cur) { - ast_log(LOG_WARNING, "%p is not in list?!?! \n", cur); - } else { - if (p->initid > -1) - ast_sched_del(sched, p->initid); - while((cp = p->packets)) { - p->packets = p->packets->next; - if (cp->retransid > -1) - ast_sched_del(sched, cp->retransid); - free(cp); - } - ast_mutex_destroy(&p->lock); - if(p->vars) { - ast_destroy_realtime(p->vars); - p->vars = NULL; - } - free(p); - } ->>>>>>> 1.576 } /*--- update_user_counter: Handle incominglimit and outgoinglimit for SIP users ---*/ @@ -2533,7 +1896,6 @@ the indication - busy signal, congestion etc */ static int sip_indicate(struct ast_channel *ast, int condition) { -<<<<<<< chan_sip.c struct sip_pvt *p = ast->pvt->pvt; switch(condition) { case AST_CONTROL_RINGING: @@ -2579,54 +1941,6 @@ return -1; } return 0; -======= - struct sip_pvt *p = ast->pvt->pvt; - switch(condition) { - case AST_CONTROL_RINGING: - if (ast->_state == AST_STATE_RING) { - if (!p->progress || !p->progressinband) { - /* Send 180 ringing if out-of-band seems reasonable */ - transmit_response(p, "180 Ringing", &p->initreq); - p->ringing = 1; - if (p->progressinband < 2) - break; - } else { - /* Well, if it's not reasonable, just send in-band */ - } - } - return -1; - case AST_CONTROL_BUSY: - if (ast->_state != AST_STATE_UP) { - transmit_response(p, "486 Busy Here", &p->initreq); - p->alreadygone = 1; - ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); - break; - } - return -1; - case AST_CONTROL_CONGESTION: - if (ast->_state != AST_STATE_UP) { - transmit_response(p, "503 Service Unavailable", &p->initreq); - p->alreadygone = 1; - ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); - break; - } - return -1; - case AST_CONTROL_PROGRESS: - case AST_CONTROL_PROCEEDING: - if ((ast->_state != AST_STATE_UP) && !p->progress && !p->outgoing) { - transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, 0); - p->progress = 1; - break; - } - return -1; - case -1: - return -1; - default: - ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", condition); - return -1; - } - return 0; ->>>>>>> 1.576 } @@ -2635,7 +1949,6 @@ /* called from sip_request_call (calls from the pbx ) */ static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title) { -<<<<<<< chan_sip.c struct ast_channel *tmp; int fmt; @@ -2665,38 +1978,6 @@ snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%08x", i->fromdomain, (int)(long)(i)); } tmp->type = type; -======= - struct ast_channel *tmp; - struct ast_variable *v = NULL; - int fmt; - - ast_mutex_unlock(&i->lock); - /* Don't hold a sip pvt lock while we allocate a channel */ - tmp = ast_channel_alloc(1); - ast_mutex_lock(&i->lock); - if (tmp) { - /* Select our native format based on codec preference until we receive - something from another device to the contrary. */ - if (i->jointcapability) - tmp->nativeformats = sip_codec_choose(i->jointcapability); - else if (i->capability) - tmp->nativeformats = sip_codec_choose(i->capability); - else - tmp->nativeformats = sip_codec_choose(global_capability); - fmt = ast_best_codec(tmp->nativeformats); - if (title) - snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%04x", title, rand() & 0xffff); - else - if (strchr(i->fromdomain,':')) - { - snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%08x", strchr(i->fromdomain,':')+1, (int)(long)(i)); - } - else - { - snprintf(tmp->name, sizeof(tmp->name), "SIP/%s-%08x", i->fromdomain, (int)(long)(i)); - } - tmp->type = type; ->>>>>>> 1.576 if (i->dtmfmode & SIP_DTMF_INBAND) { i->vad = ast_dsp_new(); ast_dsp_set_features(i->vad, DSP_FEATURE_DTMF_DETECT); @@ -2738,7 +2019,6 @@ strncpy(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode)-1); if (i->amaflags) tmp->amaflags = i->amaflags; -<<<<<<< chan_sip.c if (!ast_strlen_zero(i->language)) strncpy(tmp->language, i->language, sizeof(tmp->language)-1); if (!ast_strlen_zero(i->musicclass)) @@ -2778,49 +2058,6 @@ } else ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); return tmp; -======= - if (!ast_strlen_zero(i->language)) - strncpy(tmp->language, i->language, sizeof(tmp->language)-1); - if (!ast_strlen_zero(i->musicclass)) - strncpy(tmp->musicclass, i->musicclass, sizeof(tmp->musicclass)-1); - i->owner = tmp; - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - strncpy(tmp->context, i->context, sizeof(tmp->context)-1); - strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1); - if (!ast_strlen_zero(i->cid_num)) - tmp->cid.cid_num = strdup(i->cid_num); - if (!ast_strlen_zero(i->cid_name)) - tmp->cid.cid_name = strdup(i->cid_name); - if (!ast_strlen_zero(i->rdnis)) - tmp->cid.cid_rdnis = strdup(i->rdnis); - if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s")) - tmp->cid.cid_dnid = strdup(i->exten); - tmp->priority = 1; - if (!ast_strlen_zero(i->domain)) { - pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain); - } - if (!ast_strlen_zero(i->useragent)) { - pbx_builtin_setvar_helper(tmp, "SIPUSERAGENT", i->useragent); - } - if (!ast_strlen_zero(i->callid)) { - pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid); - } - ast_setstate(tmp, state); - if (state != AST_STATE_DOWN) { - if (ast_pbx_start(tmp)) { - ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); - ast_hangup(tmp); - tmp = NULL; - } - } - for (v = i->vars ; v ; v = v->next) - pbx_builtin_setvar_helper(tmp,v->name,v->value); - } else - ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); - return tmp; ->>>>>>> 1.576 } static struct cfalias { @@ -3050,7 +2287,6 @@ if (!p->rtp) { ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", strerror(errno)); ast_mutex_destroy(&p->lock); -<<<<<<< chan_sip.c free(p); return NULL; } @@ -3084,45 +2320,6 @@ p->promiscredir = global_promiscredir; p->trustrpid = global_trustrpid; p->progressinband = global_progressinband; -======= - if(p->vars) { - ast_destroy_realtime(p->vars); - p->vars = NULL; - } - free(p); - return NULL; - } - ast_rtp_settos(p->rtp, tos); - if (p->vrtp) - ast_rtp_settos(p->vrtp, tos); - if (useglobal_nat && sin) { - /* Setup NAT structure according to global settings if we have an address */ - p->nat = global_nat; - memcpy(&p->recv, sin, sizeof(p->recv)); - ast_rtp_setnat(p->rtp, (p->nat & SIP_NAT_ROUTE)); - if (p->vrtp) - ast_rtp_setnat(p->vrtp, (p->nat & SIP_NAT_ROUTE)); - } - - strncpy(p->fromdomain, default_fromdomain, sizeof(p->fromdomain) - 1); - /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */ - if (p->nat != SIP_NAT_NEVER) - snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x;rport", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); - else - snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); - if (!callid) - build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain); - else - strncpy(p->callid, callid, sizeof(p->callid) - 1); - /* Assume reinvite OK and via INVITE */ - p->canreinvite = global_canreinvite; - /* Assign default music on hold class */ - strncpy(p->musicclass, global_musicclass, sizeof(p->musicclass) - 1); - p->dtmfmode = global_dtmfmode; - p->promiscredir = global_promiscredir; - p->trustrpid = global_trustrpid; - p->progressinband = global_progressinband; ->>>>>>> 1.576 #ifdef OSP_SUPPORT p->ospauth = global_ospauth; #endif @@ -3296,7 +2493,6 @@ /*--- lws2sws: Parse multiline SIP headers into one header */ /* This is enabled if pedanticsipchecking is enabled */ -<<<<<<< chan_sip.c static int lws2sws(char *msgbuf, int len) { int h = 0, t = 0; @@ -3340,50 +2536,6 @@ } msgbuf[t] = '\0'; return t; -======= -static int lws2sws(char *msgbuf, int len) -{ - int h = 0, t = 0; - int lws = 0; - - for (; h < len;) { - /* Eliminate all CRs */ - if (msgbuf[h] == '\r') { - h++; - continue; - } - /* Check for end-of-line */ - if (msgbuf[h] == '\n') { - /* Check for end-of-message */ - if (h + 1 == len) - break; - /* Check for a continuation line */ - if (msgbuf[h + 1] == ' ' || msgbuf[h + 1] == '\t') { - /* Merge continuation line */ - h++; - continue; - } - /* Propagate LF and start new line */ - msgbuf[t++] = msgbuf[h++]; - lws = 0; - continue; - } - if (msgbuf[h] == ' ' || msgbuf[h] == '\t') { - if (lws) { - h++; - continue; - } - msgbuf[t++] = msgbuf[h++]; - lws = 1; - continue; - } - msgbuf[t++] = msgbuf[h++]; - if (lws) - lws = 0; - } - msgbuf[t] = '\0'; - return t; ->>>>>>> 1.576 } /*--- parse: Parse a SIP message ----*/ @@ -3456,7 +2608,6 @@ /*--- process_sdp: Process SIP SDP ---*/ static int process_sdp(struct sip_pvt *p, struct sip_request *req) { -<<<<<<< chan_sip.c char *m; char *c; char *a; @@ -3573,125 +2724,6 @@ */ sdpLineNum_iterator_init(&iterator); while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') { -======= - char *m; - char *c; - char *a; - char host[258]; - char iabuf[INET_ADDRSTRLEN]; - int len = -1; - int portno=0; - int vportno=0; - int peercapability, peernoncodeccapability; - int vpeercapability=0, vpeernoncodeccapability=0; - struct sockaddr_in sin; - char *codecs; - struct hostent *hp; - struct ast_hostent ahp; - int codec; - int iterator; - int sendonly = 0; - int x,y; - int debug=sip_debug_test_pvt(p); - - /* Update our last rtprx when we receive an SDP, too */ - time(&p->lastrtprx); - - /* Get codec and RTP info from SDP */ - if (strcasecmp(get_header(req, "Content-Type"), "application/sdp")) { - ast_log(LOG_NOTICE, "Content is '%s', not 'application/sdp'\n", get_header(req, "Content-Type")); - return -1; - } - m = get_sdp(req, "m"); - c = get_sdp(req, "c"); - if (ast_strlen_zero(m) || ast_strlen_zero(c)) { - ast_log(LOG_WARNING, "Insufficient information for SDP (m = '%s', c = '%s')\n", m, c); - return -1; - } - if (sscanf(c, "IN IP4 %256s", host) != 1) { - ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c); - return -1; - } - /* XXX This could block for a long time, and block the main thread! XXX */ - hp = ast_gethostbyname(host, &ahp); - if (!hp) { - ast_log(LOG_WARNING, "Unable to lookup host in c= line, '%s'\n", c); - return -1; - } - sdpLineNum_iterator_init(&iterator); - p->novideo = 1; - while ((m = get_sdp_iterate(&iterator, req, "m"))[0] != '\0') { - if ((sscanf(m, "audio %d RTP/AVP %n", &x, &len) == 1) || - (sscanf(m, "audio %d/%d RTP/AVP %n", &x, &y, &len) == 2)) { - portno = x; - /* Scan through the RTP payload types specified in a "m=" line: */ - ast_rtp_pt_clear(p->rtp); - codecs = m + len; - while(!ast_strlen_zero(codecs)) { - if (sscanf(codecs, "%d%n", &codec, &len) != 1) { - ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); - return -1; - } - if (debug) - ast_verbose("Found RTP audio format %d\n", codec); - ast_rtp_set_m_type(p->rtp, codec); - codecs += len; - /* Skip over any whitespace */ - while(*codecs && (*codecs < 33)) codecs++; - } - } - if (p->vrtp) - ast_rtp_pt_clear(p->vrtp); /* Must be cleared in case no m=video line exists */ - - if (p->vrtp && (sscanf(m, "video %d RTP/AVP %n", &x, &len) == 1)) { - p->novideo = 0; - vportno = x; - /* Scan through the RTP payload types specified in a "m=" line: */ - codecs = m + len; - while(!ast_strlen_zero(codecs)) { - if (sscanf(codecs, "%d%n", &codec, &len) != 1) { - ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); - return -1; - } - if (debug) - ast_verbose("Found video format %s\n", ast_getformatname(codec)); - ast_rtp_set_m_type(p->vrtp, codec); - codecs += len; - /* Skip over any whitespace */ - while(*codecs && (*codecs < 33)) codecs++; - } - } - } - - /* RTP addresses and ports for audio and video */ - sin.sin_family = AF_INET; - memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); - - /* Setup audio port number */ - sin.sin_port = htons(portno); - if (p->rtp && sin.sin_port) { - ast_rtp_set_peer(p->rtp, &sin); - if (debug) { - ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port)); - ast_log(LOG_DEBUG,"Peer audio RTP is at port %s:%d\n",ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port)); - } - } - /* Setup video port number */ - sin.sin_port = htons(vportno); - if (p->vrtp && sin.sin_port) { - ast_rtp_set_peer(p->vrtp, &sin); - if (debug) { - ast_verbose("Peer video RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port)); - ast_log(LOG_DEBUG,"Peer video RTP is at port %s:%d\n",ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port)); - } - } - - /* Next, scan through each "a=rtpmap:" line, noting each - * specified RTP payload type (with corresponding MIME subtype): - */ - sdpLineNum_iterator_init(&iterator); - while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') { ->>>>>>> 1.576 char* mimeSubtype = ast_strdupa(a); /* ensures we have enough space */ if (!strcasecmp(a, "sendonly")) { sendonly=1; @@ -4852,7 +3884,6 @@ */ static int transmit_notify_with_mwi(struct sip_pvt *p, int newmsgs, int oldmsgs) { -<<<<<<< chan_sip.c struct sip_request req; char tmp[256]; char tmp2[256]; @@ -4876,31 +3907,6 @@ ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines); determine_firstline_parts(&p->initreq); } -======= - struct sip_request req; - char tmp[256]; - char tmp2[256]; - char clen[20]; - initreqprep(&req, p, "NOTIFY", NULL); - add_header(&req, "Event", "message-summary"); - add_header(&req, "Content-Type", default_notifymime); - - snprintf(tmp, sizeof(tmp), "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no"); - snprintf(tmp2, sizeof(tmp2), "Voice-Message: %d/%d\r\n", newmsgs, oldmsgs); - snprintf(clen, sizeof(clen), "%d", (int)(strlen(tmp) + strlen(tmp2))); - add_header(&req, "Content-Length", clen); - add_line(&req, tmp); - add_line(&req, tmp2); - - if (!p->initreq.headers) { - /* Use this as the basis */ - copy_request(&p->initreq, &req); - parse(&p->initreq); - if (sip_debug_test_pvt(p)) - ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines); - determine_firstline_parts(&p->initreq); - } ->>>>>>> 1.576 return send_request(p, &req, 1, p->ocseq); } @@ -5012,7 +4018,6 @@ /*--- transmit_register: Transmit register to SIP proxy ---*/ static int transmit_register(struct sip_registry *r, char *cmd, char *auth, char *authheader) { -<<<<<<< chan_sip.c struct sip_request req; char from[256]; char to[256]; @@ -5144,143 +4149,6 @@ determine_firstline_parts(&p->initreq); r->regstate=auth?REG_STATE_AUTHSENT:REG_STATE_REGSENT; return send_request(p, &req, 2, p->ocseq); -======= - struct sip_request req; - char from[256]; - char to[256]; - char tmp[80]; - char via[80]; - char addr[80]; - char iabuf[INET_ADDRSTRLEN]; - struct sip_pvt *p; - - /* exit if we are already in process with this registrar ?*/ - if ( r == NULL || ((auth==NULL) && (r->regstate==REG_STATE_REGSENT || r->regstate==REG_STATE_AUTHSENT))) { - ast_log(LOG_NOTICE, "Strange, trying to register when registration already pending\n"); - return 0; - } - - if (r->call) { - if (!auth) { - ast_log(LOG_WARNING, "Already have a call??\n"); - return 0; - } else { - p = r->call; - p->tag = rand(); /* create a new local tag for every register attempt */ - p->theirtag[0]='\0'; /* forget their old tag, so we don't match tags when getting response */ - } - } else { - if (!r->callid_valid) { - build_callid(r->callid, sizeof(r->callid), __ourip, default_fromdomain); - r->callid_valid = 1; - } - p=sip_alloc( r->callid, NULL, 0); - if (!p) { - ast_log(LOG_WARNING, "Unable to allocate registration call\n"); - return 0; - } - if (create_addr(p,r->hostname)) { - sip_destroy(p); - return 0; - } - /* Copy back Call-ID in case create_addr changed it */ - strncpy(r->callid, p->callid, sizeof(r->callid) - 1); - if (r->portno) - p->sa.sin_port = htons(r->portno); - p->outgoing = 1; - r->call=p; - p->registry=r; - if (!ast_strlen_zero(r->secret)) - strncpy(p->peersecret, r->secret, sizeof(p->peersecret)-1); - if (!ast_strlen_zero(r->md5secret)) - strncpy(p->peermd5secret, r->md5secret, sizeof(p->peermd5secret)-1); - if (!ast_strlen_zero(r->authuser)) { - strncpy(p->peername, r->authuser, sizeof(p->peername)-1); - strncpy(p->authname, r->authuser, sizeof(p->authname)-1); - } else { - if (!ast_strlen_zero(r->username)) { - strncpy(p->peername, r->username, sizeof(p->peername)-1); - strncpy(p->authname, r->username, sizeof(p->authname)-1); - strncpy(p->fromuser, r->username, sizeof(p->fromuser)-1); - } - } - if (!ast_strlen_zero(r->username)) - strncpy(p->username, r->username, sizeof(p->username)-1); - strncpy(p->exten, r->contact, sizeof(p->exten) - 1); - - /* - 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 - */ - if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) - memcpy(&p->ourip, &bindaddr.sin_addr, sizeof(p->ourip)); - build_contact(p); - } - - /* set up a timeout */ - if (auth==NULL) { - if (r->timeout > -1) { - ast_log(LOG_WARNING, "Still have a timeout, %d\n", r->timeout); - ast_sched_del(sched, r->timeout); - } - r->timeout = ast_sched_add(sched, 20*1000, sip_reg_timeout, r); - ast_log(LOG_DEBUG, "Scheduled a timeout # %d\n", r->timeout); - } - - if (strchr(r->username, '@')) { - snprintf(from, sizeof(from), ";tag=as%08x", r->username, p->tag); - if (!ast_strlen_zero(p->theirtag)) - snprintf(to, sizeof(to), ";tag=%s", r->username, p->theirtag); - else - snprintf(to, sizeof(to), "", r->username); - } else { - snprintf(from, sizeof(from), ";tag=as%08x", r->username, p->tohost, p->tag); - if (!ast_strlen_zero(p->theirtag)) - snprintf(to, sizeof(to), ";tag=%s", r->username, p->tohost, p->theirtag); - else - snprintf(to, sizeof(to), "", r->username, p->tohost); - } - - snprintf(addr, sizeof(addr), "sip:%s", r->hostname); - strncpy(p->uri, addr, sizeof(p->uri) - 1); - - p->branch ^= rand(); - - memset(&req, 0, sizeof(req)); - init_req(&req, cmd, addr); - - snprintf(tmp, sizeof(tmp), "%u %s", ++r->ocseq, cmd); - p->ocseq = r->ocseq; - - /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */ - if (p->nat & SIP_NAT_RFC3581) - snprintf(via, sizeof(via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x;rport", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); - else /* Work around buggy UNIDEN UIP200 firmware */ - snprintf(via, sizeof(via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); - add_header(&req, "Via", via); - add_header(&req, "From", from); - add_header(&req, "To", to); - add_header(&req, "Call-ID", p->callid); - add_header(&req, "CSeq", tmp); - add_header(&req, "User-Agent", default_useragent); - if (auth) - add_header(&req, authheader, auth); - - snprintf(tmp, sizeof(tmp), "%d", default_expiry); - add_header(&req, "Expires", tmp); - add_header(&req, "Contact", p->our_contact); - add_header(&req, "Event", "registration"); - add_header(&req, "Content-Length", "0"); - add_blank_header(&req); - copy_request(&p->initreq, &req); - parse(&p->initreq); - if (sip_debug_test_pvt(p)) - ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines); - determine_firstline_parts(&p->initreq); - r->regstate=auth?REG_STATE_AUTHSENT:REG_STATE_REGSENT; - return send_request(p, &req, 2, p->ocseq); ->>>>>>> 1.576 } /*--- transmit_message_with_text: Transmit text with SIP MESSAGE method ---*/ @@ -5401,7 +4269,6 @@ /*--- reg_source_db: Save registration in Asterisk DB ---*/ static void reg_source_db(struct sip_peer *p) { -<<<<<<< chan_sip.c char data[256]; char iabuf[INET_ADDRSTRLEN]; struct in_addr in; @@ -5453,60 +4320,6 @@ } } } -======= - char data[256]; - char iabuf[INET_ADDRSTRLEN]; - struct in_addr in; - char *c, *d, *u, *e; - int expiry; - if (!ast_db_get("SIP/Registry", p->name, data, sizeof(data))) { - c = strchr(data, ':'); - if (c) { - *c = '\0'; - c++; - if (inet_aton(data, &in)) { - d = strchr(c, ':'); - if (d) { - *d = '\0'; - d++; - u = strchr(d, ':'); - if (u) { - *u = '\0'; - u++; - e = strchr(u, ':'); - if (e) { - *e = '\0'; - e++; - strncpy(p->fullcontact, e, sizeof(p->fullcontact) - 1); - } - strncpy(p->username, u, sizeof(p->username) - 1); - - } - if (option_verbose > 2) - 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)); - p->addr.sin_family = AF_INET; - p->addr.sin_addr = in; - p->addr.sin_port = htons(atoi(c)); - if (sipsock < 0) { - /* SIP isn't up yet, so schedule a poke only, pretty soon */ - if (p->pokeexpire > -1) - ast_sched_del(sched, p->pokeexpire); - p->pokeexpire = ast_sched_add(sched, rand() % 5000 + 1, sip_poke_peer_s, p); - } else - sip_poke_peer(p); - if (p->expire > -1) - ast_sched_del(sched, p->expire); - p->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, (void *)p); - register_peer_exten(p, 1); - } - - } - } - } ->>>>>>> 1.576 } /*--- parse_contact: Parse contact header and save registration ---*/ @@ -5663,7 +4476,7 @@ } } -/*--- build_route: Build route list from Record-Route header ---*/ +/*--- build_route: Build route headers ---*/ static void build_route(struct sip_pvt *p, struct sip_request *req, int backwards) { struct sip_route *thishop, *head, *tail; @@ -6422,33 +5235,12 @@ strncpy(output,start,maxlen-1); output[maxlen-1] = '\0'; -<<<<<<< chan_sip.c end = strchr(output,'@'); if (end) *end = '\0'; if(strstr(input,"privacy=full") || strstr(input,"privacy=uri")) return AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; -======= - start = strchr(input,':'); - if (!start) { - output[0] = '\0'; - return 0; - } - start++; - - /* we found "number" */ - strncpy(output,start,maxlen-1); - output[maxlen-1] = '\0'; - - end = strchr(output,'@'); - if (end) - *end = '\0'; - else - output[0] = '\0'; - if(strstr(input,"privacy=full") || strstr(input,"privacy=uri")) - return AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; ->>>>>>> 1.576 return 0; } @@ -6457,7 +5249,6 @@ /*--- check_user: Check if matching user or peer is defined ---*/ static int check_user_full(struct sip_pvt *p, struct sip_request *req, char *cmd, char *uri, int reliable, struct sockaddr_in *sin, int ignore, char *mailbox, int mailboxlen) { -<<<<<<< chan_sip.c struct sip_user *user; struct sip_peer *peer; char *of, from[256] = "", *c; @@ -6515,77 +5306,9 @@ /* Find user based on user name in the from header */ if (user && ast_apply_ha(user->ha, sin)) { p->nat = user->nat; -======= - struct sip_user *user; - struct sip_peer *peer; - char *of, from[256] = "", *c; - char *rpid,rpid_num[50]; - char iabuf[INET_ADDRSTRLEN]; - int res = 0; - char *t; - char calleridname[50]; - int debug=sip_debug_test_addr(sin); - struct ast_variable *tmpvar = NULL, *v = NULL; - - /* Terminate URI */ - t = uri; - while(*t && (*t > 32) && (*t != ';')) - t++; - *t = '\0'; - of = get_header(req, "From"); - strncpy(from, of, sizeof(from) - 1); - memset(calleridname,0,sizeof(calleridname)); - get_calleridname(from, calleridname, sizeof(calleridname)); - - rpid = get_header(req, "Remote-Party-ID"); - memset(rpid_num,0,sizeof(rpid_num)); - if(!ast_strlen_zero(rpid)) - p->callingpres = get_rpid_num(rpid,rpid_num, sizeof(rpid_num)); - - of = ditch_braces(from); - if (ast_strlen_zero(p->exten)) { - t = uri; - if (!strncmp(t, "sip:", 4)) - t+= 4; - strncpy(p->exten, t, sizeof(p->exten) - 1); - t = strchr(p->exten, '@'); - if (t) - *t = '\0'; - if (ast_strlen_zero(p->our_contact)) - build_contact(p); - } - if (strncmp(of, "sip:", 4)) { - ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n"); - } else - of += 4; - /* Get just the username part */ - if ((c = strchr(of, '@'))) - *c = '\0'; - if ((c = strchr(of, ':'))) - *c = '\0'; - strncpy(p->cid_num, of, sizeof(p->cid_num) - 1); - ast_shrink_phone_number(p->cid_num); - if (*calleridname) - strncpy(p->cid_name, calleridname, sizeof(p->cid_name) - 1); - if (ast_strlen_zero(of)) - return 0; - ast_mutex_lock(&userl.lock); - user = find_user(of); - /* Find user based on user name in the from header */ - if (user && ast_apply_ha(user->ha, sin)) { - /* copy vars */ - for (v = user->vars ; v ; v = v->next) { - if((tmpvar = ast_new_variable(v->name, v->value))) { - tmpvar->next = p->vars; - p->vars = tmpvar; - } - } - p->nat = user->nat; ->>>>>>> 1.576 #ifdef OSP_SUPPORT p->ospauth = user->ospauth; #endif -<<<<<<< chan_sip.c p->trustrpid = user->trustrpid; p->progressinband = user->progressinband; /* replace callerid if rpid found, and not restricted */ @@ -6673,101 +5396,9 @@ strncpy(p->cid_num, rpid_num, sizeof(p->cid_num) - 1); ast_shrink_phone_number(p->cid_num); } -======= - p->trustrpid = user->trustrpid; - p->useclientcode = user->useclientcode; - p->progressinband = user->progressinband; - /* replace callerid if rpid found, and not restricted */ - if(!ast_strlen_zero(rpid_num) && p->trustrpid) { - if (*calleridname) - strncpy(p->cid_name, calleridname, sizeof(p->cid_name) - 1); - strncpy(p->cid_num, rpid_num, sizeof(p->cid_num) - 1); - ast_shrink_phone_number(p->cid_num); - } - - if (p->rtp) { - ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (p->nat & SIP_NAT_ROUTE)); - ast_rtp_setnat(p->rtp, (p->nat & SIP_NAT_ROUTE)); - } - if (p->vrtp) { - ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (p->nat & SIP_NAT_ROUTE)); - ast_rtp_setnat(p->vrtp, (p->nat & SIP_NAT_ROUTE)); - } - if (!(res = check_auth(p, req, p->randdata, sizeof(p->randdata), user->name, user->secret, user->md5secret, cmd, uri, reliable, ignore))) { - sip_cancel_destroy(p); - if (!ast_strlen_zero(user->context)) - strncpy(p->context, user->context, sizeof(p->context) - 1); - if (!ast_strlen_zero(user->cid_num) && !ast_strlen_zero(p->cid_num)) { - strncpy(p->cid_num, user->cid_num, sizeof(p->cid_num) - 1); - ast_shrink_phone_number(p->cid_num); - } - if (!ast_strlen_zero(user->cid_name) && !ast_strlen_zero(p->cid_name)) - strncpy(p->cid_name, user->cid_name, sizeof(p->cid_name) - 1); - strncpy(p->username, user->name, sizeof(p->username) - 1); - strncpy(p->peersecret, user->secret, sizeof(p->peersecret) - 1); - strncpy(p->peermd5secret, user->md5secret, sizeof(p->peermd5secret) - 1); - strncpy(p->accountcode, user->accountcode, sizeof(p->accountcode) -1); - strncpy(p->language, user->language, sizeof(p->language) -1); - strncpy(p->musicclass, user->musicclass, sizeof(p->musicclass) -1); - p->canreinvite = user->canreinvite; - p->amaflags = user->amaflags; - p->callgroup = user->callgroup; - p->pickupgroup = user->pickupgroup; - p->callingpres = user->callingpres; - p->capability = user->capability; - p->jointcapability = user->capability; - if (p->peercapability) - p->jointcapability &= p->peercapability; - p->promiscredir = user->promiscredir; - if (user->dtmfmode) { - p->dtmfmode = user->dtmfmode; - if (p->dtmfmode & SIP_DTMF_RFC2833) - p->noncodeccapability |= AST_RTP_DTMF; - else - p->noncodeccapability &= ~AST_RTP_DTMF; - } - } - if (user && debug) - ast_verbose("Found user '%s'\n", user->name); - } else { - if (user) { - if (debug) - ast_verbose("Found user '%s', but fails host access\n", user->name); - if (user->temponly) - destroy_user(user); - } - user = NULL; - } - /* Temp user gets cleaned up at the end */ - 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 - */ - peer = find_peer(NULL, &p->recv); - if (peer) { - if (debug) - ast_verbose("Found peer '%s'\n", peer->name); - /* Take the peer */ - p->nat = peer->nat; - p->trustrpid = peer->trustrpid; - p->useclientcode = peer->useclientcode; - p->progressinband = peer->progressinband; - /* replace callerid if rpid found, and not restricted */ - if(!ast_strlen_zero(rpid_num) && p->trustrpid) { - if (*calleridname) - strncpy(p->cid_name, calleridname, sizeof(p->cid_name) - 1); - strncpy(p->cid_num, rpid_num, sizeof(p->cid_num) - 1); - ast_shrink_phone_number(p->cid_num); - } ->>>>>>> 1.576 #ifdef OSP_SUPPORT p->ospauth = peer->ospauth; #endif -<<<<<<< chan_sip.c if (p->rtp) { ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (p->nat & SIP_NAT_ROUTE)); ast_rtp_setnat(p->rtp, (p->nat & SIP_NAT_ROUTE)); @@ -6821,68 +5452,6 @@ if (debug) ast_verbose("Found no matching peer or user for '%s:%d'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port)); ast_mutex_unlock(&peerl.lock); -======= - if (p->rtp) { - ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (p->nat & SIP_NAT_ROUTE)); - ast_rtp_setnat(p->rtp, (p->nat & SIP_NAT_ROUTE)); - } - if (p->vrtp) { - ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (p->nat & SIP_NAT_ROUTE)); - ast_rtp_setnat(p->vrtp, (p->nat & SIP_NAT_ROUTE)); - } - strncpy(p->peersecret, peer->secret, sizeof(p->peersecret)-1); - p->peersecret[sizeof(p->peersecret)-1] = '\0'; - strncpy(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret)-1); - p->peermd5secret[sizeof(p->peermd5secret)-1] = '\0'; - if (peer->insecure > 1) { - /* Pretend there is no required authentication if insecure is "very" */ - p->peersecret[0] = '\0'; - p->peermd5secret[0] = '\0'; - } - if (!(res = check_auth(p, req, p->randdata, sizeof(p->randdata), peer->name, p->peersecret, p->peermd5secret, cmd, uri, reliable, ignore))) { - p->canreinvite = peer->canreinvite; - strncpy(p->peername, peer->name, sizeof(p->peername) - 1); - strncpy(p->authname, peer->name, sizeof(p->authname) - 1); - if (mailbox) - snprintf(mailbox, mailboxlen, ",%s,", peer->mailbox); - if (!ast_strlen_zero(peer->username)) { - strncpy(p->username, peer->username, sizeof(p->username) - 1); - strncpy(p->authname, peer->username, sizeof(p->authname) - 1); - } - if (!ast_strlen_zero(peer->cid_num) && !ast_strlen_zero(p->cid_num)) { - strncpy(p->cid_num, peer->cid_num, sizeof(p->cid_num) - 1); - ast_shrink_phone_number(p->cid_num); - } - if (!ast_strlen_zero(peer->cid_name) && !ast_strlen_zero(p->cid_name)) - strncpy(p->cid_name, peer->cid_name, sizeof(p->cid_name) - 1); - strncpy(p->fullcontact, peer->fullcontact, sizeof(p->fullcontact) - 1); - if (!ast_strlen_zero(peer->context)) - strncpy(p->context, peer->context, sizeof(p->context) - 1); - strncpy(p->peersecret, peer->secret, sizeof(p->peersecret) - 1); - strncpy(p->peermd5secret, peer->md5secret, sizeof(p->peermd5secret) - 1); - strncpy(p->language, peer->language, sizeof(p->language) -1); - p->callgroup = peer->callgroup; - p->pickupgroup = peer->pickupgroup; - p->capability = peer->capability; - p->jointcapability = peer->capability; - if (p->peercapability) - p->jointcapability &= p->peercapability; - p->promiscredir = peer->promiscredir; - if (peer->dtmfmode) { - p->dtmfmode = peer->dtmfmode; - if (p->dtmfmode & SIP_DTMF_RFC2833) - p->noncodeccapability |= AST_RTP_DTMF; - else - p->noncodeccapability &= ~AST_RTP_DTMF; - } - } - if (peer->temponly) - destroy_peer(peer); - } else - if (debug) - ast_verbose("Found no matching peer or user for '%s:%d'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port)); - ast_mutex_unlock(&peerl.lock); ->>>>>>> 1.576 } @@ -6891,14 +5460,11 @@ return res; } - -/*--- check_user: Find user ---*/ static int check_user(struct sip_pvt *p, struct sip_request *req, char *cmd, char *uri, int reliable, struct sockaddr_in *sin, int ignore) { return check_user_full(p, req, cmd, uri, reliable, sin, ignore, NULL, 0); } - -/*--- get_msg_text: Get text out of a SIP MESSAGE packet ---*/ +/*--- get_msg_text: Get text out of a SIP MESSAGE ---*/ static int get_msg_text(char *buf, int len, struct sip_request *req) { int x; @@ -6924,7 +5490,6 @@ /* we handle messages within current calls currently */ static void receive_message(struct sip_pvt *p, struct sip_request *req) { -<<<<<<< chan_sip.c char buf[1024]; struct ast_frame f; if (get_msg_text(buf, sizeof(buf), req)) { @@ -6942,26 +5507,6 @@ f.datalen = strlen(buf); ast_queue_frame(p->owner, &f); } -======= - char buf[1024]; - struct ast_frame f; - - if (get_msg_text(buf, sizeof(buf), req)) { - ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid); - return; - } - if (p->owner) { - if (sip_debug_test_pvt(p)) - ast_verbose("Message received: '%s'\n", buf); - memset(&f, 0, sizeof(f)); - f.frametype = AST_FRAME_TEXT; - f.subclass = 0; - f.offset = 0; - f.data = buf; - f.datalen = strlen(buf); - ast_queue_frame(p->owner, &f); - } ->>>>>>> 1.576 } /*--- sip_show_inuse: CLI Command to show calls within limits set by @@ -6969,7 +5514,6 @@ static int sip_show_inuse(int fd, int argc, char *argv[]) { #define FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-15.15s\n" #define FORMAT2 "%-15.15s %-15.15s %-15.15s %-15.15s %-15.15s\n" -<<<<<<< chan_sip.c struct sip_user *user; char ilimits[40] = ""; char olimits[40] = ""; @@ -6995,34 +5539,6 @@ } ast_mutex_unlock(&userl.lock); return RESULT_SUCCESS; -======= - struct sip_user *user; - char ilimits[40] = ""; - char olimits[40] = ""; - char iused[40]; - char oused[40]; - - if (argc != 3) - return RESULT_SHOWUSAGE; - ast_mutex_lock(&userl.lock); - user = userl.users; - ast_cli(fd, FORMAT, "Username", "incoming", "Limit","outgoing","Limit"); - for(user=userl.users;user;user=user->next) { - if (user->incominglimit) - snprintf(ilimits, sizeof(ilimits), "%d", user->incominglimit); - else - strncpy(ilimits, "N/A", sizeof(ilimits) - 1); - if (user->outgoinglimit) - snprintf(olimits, sizeof(olimits), "%d", user->outgoinglimit); - else - strncpy(olimits, "N/A", sizeof(olimits) - 1); - snprintf(iused, sizeof(iused), "%d", user->inUse); - snprintf(oused, sizeof(oused), "%d", user->outUse); - ast_cli(fd, FORMAT2, user->name, iused, ilimits,oused,olimits); - } - ast_mutex_unlock(&userl.lock); - return RESULT_SUCCESS; ->>>>>>> 1.576 #undef FORMAT #undef FORMAT2 } @@ -7163,10 +5679,9 @@ /*--- print_group: Print call group and pickup group ---*/ static void print_group(int fd, unsigned int group) { - unsigned int i; - int first=1; + unsigned int i; + int first=1; -<<<<<<< chan_sip.c for (i=0; i<=31; i++) { /* Max group is 31 */ if (group & (1 << i)) { if (!first) { @@ -7178,25 +5693,11 @@ } } ast_cli(fd, " (%u)\n", group); -======= - for (i=0; i<=31; i++) { /* Max group is 31 */ - if (group & (1 << i)) { - if (!first) { - ast_cli(fd, ", "); - } else { - first=0; - } - ast_cli(fd, "%u", i); - } - } - ast_cli(fd, " (%u)\n", group); ->>>>>>> 1.576 } /*--- sip_show_peer: Show one peer in detail ---*/ static int sip_show_peer(int fd, int argc, char *argv[]) { -<<<<<<< chan_sip.c char status[30] = ""; char iabuf[INET_ADDRSTRLEN]; struct sip_peer *peer; @@ -7232,45 +5733,6 @@ /* - is enumerated */ ast_cli(fd, " DTMFmode : "); if (peer->dtmfmode == SIP_DTMF_RFC2833) -======= - char status[30] = ""; - char cbuf[256]; - char iabuf[INET_ADDRSTRLEN]; - struct sip_peer *peer; - - if (argc != 4) - return RESULT_SHOWUSAGE; - ast_mutex_lock(&peerl.lock); - peer = find_peer(argv[3], NULL); - if (peer) { - ast_cli(fd,"\n\n"); - ast_cli(fd, " * Name : %s\n", peer->name); - ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"":""); - ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(peer->md5secret)?"":""); - ast_cli(fd, " Context : %s\n", peer->context); - ast_cli(fd, " Language : %s\n", peer->language); - ast_cli(fd, " FromUser : %s\n", peer->fromuser); - ast_cli(fd, " FromDomain : %s\n", peer->fromdomain); - ast_cli(fd, " Callgroup : "); - print_group(fd, peer->callgroup); - ast_cli(fd, " Pickupgroup : "); - print_group(fd, peer->pickupgroup); - ast_cli(fd, " Mailbox : %s\n", peer->mailbox); - ast_cli(fd, " LastMsgsSent : %d\n", peer->lastmsgssent); - ast_cli(fd, " Dynamic : %s\n", (peer->dynamic?"Yes":"No")); - ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "")); - ast_cli(fd, " Expire : %d\n", peer->expire); - ast_cli(fd, " Expiry : %d\n", peer->expiry); - ast_cli(fd, " Insecure : %s\n", (peer->insecure?((peer->insecure == 2)?"Very":"Yes"):"No") ); - ast_cli(fd, " Nat : %s\n", nat2str(peer->nat)); - ast_cli(fd, " ACL : %s\n", (peer->ha?"Yes":"No")); - ast_cli(fd, " CanReinvite : %s\n", (peer->canreinvite?"Yes":"No")); - ast_cli(fd, " PromiscRedir : %s\n", (peer->promiscredir?"Yes":"No")); - - /* - is enumerated */ - ast_cli(fd, " DTMFmode : "); - if (peer->dtmfmode == SIP_DTMF_RFC2833) ->>>>>>> 1.576 ast_cli(fd, "rfc2833 "); if (peer->dtmfmode == SIP_DTMF_INFO) ast_cli(fd, "info "); @@ -7346,7 +5808,6 @@ { #define FORMAT2 "%-30.30s %-12.12s %8.8s %-20.20s\n" #define FORMAT "%-30.30s %-12.12s %8d %-20.20s\n" -<<<<<<< chan_sip.c struct sip_registry *reg; char host[80]; if (argc != 3) @@ -7360,22 +5821,6 @@ } ast_mutex_unlock(®l.lock); return RESULT_SUCCESS; -======= - struct sip_registry *reg; - char host[80]; - - if (argc != 3) - return RESULT_SHOWUSAGE; - ast_mutex_lock(®l.lock); - ast_cli(fd, FORMAT2, "Host", "Username", "Refresh", "State"); - for (reg = regl.registrations;reg;reg = reg->next) { - snprintf(host, sizeof(host), "%s:%d", reg->hostname, reg->portno ? reg->portno : DEFAULT_SIP_PORT); - ast_cli(fd, FORMAT, host, - reg->username, reg->refresh, regstate2str(reg->regstate)); - } - ast_mutex_unlock(®l.lock); - return RESULT_SUCCESS; ->>>>>>> 1.576 #undef FORMAT #undef FORMAT2 } @@ -7400,7 +5845,6 @@ #define FORMAT3 "%-15.15s %-10.10s %-21.21s %-15.15s\n" #define FORMAT2 "%-15.15s %-10.10s %-11.11s %-11.11s %s\n" #define FORMAT "%-15.15s %-10.10s %-11.11s %5.5d/%5.5d %-6.6s%s\n" -<<<<<<< chan_sip.c struct sip_pvt *cur; char iabuf[INET_ADDRSTRLEN]; int numchans = 0; @@ -7425,35 +5869,8 @@ ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, cur->callid, cur->uri); -======= - struct sip_pvt *cur; - char iabuf[INET_ADDRSTRLEN]; - int numchans = 0; - if (argc != 3) - return RESULT_SHOWUSAGE; - ast_mutex_lock(&iflock); - cur = iflist; - if (!subscriptions) - ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format"); - else - 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->cid_num) ? "(None)" : cur->cid_num ) : 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->cid_num) ? "(None)" : cur->cid_num ) : cur->username, - cur->callid, cur->uri); ->>>>>>> 1.576 } -<<<<<<< chan_sip.c cur = cur->next; } ast_mutex_unlock(&iflock); @@ -7462,16 +5879,6 @@ else ast_cli(fd, "%d active SIP subscriptions(s)\n", numchans); return RESULT_SUCCESS; -======= - cur = cur->next; - } - ast_mutex_unlock(&iflock); - if (!subscriptions) - ast_cli(fd, "%d active SIP channel(s)\n", numchans); - else - ast_cli(fd, "%d active SIP subscriptions(s)\n", numchans); - return RESULT_SUCCESS; ->>>>>>> 1.576 #undef FORMAT #undef FORMAT2 #undef FORMAT3 @@ -7480,7 +5887,6 @@ /*--- complete_sipch: Support routine for 'sip show channel' CLI ---*/ static char *complete_sipch(char *line, char *word, int pos, int state) { -<<<<<<< chan_sip.c int which=0; struct sip_pvt *cur; char *c = NULL; @@ -7497,31 +5903,11 @@ } ast_mutex_unlock(&iflock); return c; -======= - int which=0; - struct sip_pvt *cur; - char *c = NULL; - - ast_mutex_lock(&iflock); - cur = iflist; - while(cur) { - if (!strncasecmp(word, cur->callid, strlen(word))) { - if (++which > state) { - c = strdup(cur->callid); - break; - } - } - cur = cur->next; - } - ast_mutex_unlock(&iflock); - return c; ->>>>>>> 1.576 } /*--- sip_show_channel: Show details of one call ---*/ static int sip_show_channel(int fd, int argc, char *argv[]) { -<<<<<<< chan_sip.c struct sip_pvt *cur; char tmp[256]; char iabuf[INET_ADDRSTRLEN]; @@ -7580,73 +5966,11 @@ if (!found) ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); return RESULT_SUCCESS; -======= - struct sip_pvt *cur; - char tmp[256]; - char iabuf[INET_ADDRSTRLEN]; - size_t len; - int found = 0; - - if (argc != 4) - return RESULT_SHOWUSAGE; - len = strlen(argv[3]); - ast_mutex_lock(&iflock); - cur = iflist; - while(cur) { - if (!strncasecmp(cur->callid, argv[3],len)) { - ast_cli(fd,"\n"); - if (cur->subscribed) - ast_cli(fd, " * Subscription\n"); - else - ast_cli(fd, " * SIP Call\n"); - ast_cli(fd, " Direction: %s\n", cur->outgoing?"Outgoing":"Incoming"); - ast_cli(fd, " Call-ID: %s\n", cur->callid); - ast_cli(fd, " Our Codec Capability: %d\n", cur->capability); - ast_cli(fd, " Non-Codec Capability: %d\n", cur->noncodeccapability); - ast_cli(fd, " Their Codec Capability: %d\n", cur->peercapability); - ast_cli(fd, " Joint Codec Capability: %d\n", cur->jointcapability); - ast_cli(fd, " Format %s\n", ast_getformatname(cur->owner ? cur->owner->nativeformats : 0) ); - ast_cli(fd, " Theoretical Address: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), ntohs(cur->sa.sin_port)); - ast_cli(fd, " Received Address: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), cur->recv.sin_addr), ntohs(cur->recv.sin_port)); - ast_cli(fd, " NAT Support: %s\n", nat2str(cur->nat)); - ast_cli(fd, " Our Tag: %08d\n", cur->tag); - ast_cli(fd, " Their Tag: %s\n", cur->theirtag); - ast_cli(fd, " SIP User agent: %s\n", cur->useragent); - if (!ast_strlen_zero(cur->username)) - ast_cli(fd, " Username: %s\n", cur->username); - if (!ast_strlen_zero(cur->peername)) - ast_cli(fd, " Peername: %s\n", cur->peername); - if (!ast_strlen_zero(cur->uri)) - ast_cli(fd, " Original uri: %s\n", cur->uri); - if (!ast_strlen_zero(cur->cid_num)) - ast_cli(fd, " Caller-ID: %s\n", cur->cid_num); - ast_cli(fd, " Need Destroy: %d\n", cur->needdestroy); - ast_cli(fd, " Last Message: %s\n", cur->lastmsg); - ast_cli(fd, " Promiscuous Redir: %s\n", cur->promiscredir ? "Yes" : "No"); - ast_cli(fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A"); - tmp[0] = '\0'; - if (cur->dtmfmode & SIP_DTMF_RFC2833) - strncat(tmp, "rfc2833 ", sizeof(tmp) - strlen(tmp) - 1); - if (cur->dtmfmode & SIP_DTMF_INFO) - strncat(tmp, "info ", sizeof(tmp) - strlen(tmp) - 1); - if (cur->dtmfmode & SIP_DTMF_INBAND) - strncat(tmp, "inband ", sizeof(tmp) - strlen(tmp) - 1); - ast_cli(fd, " DTMF Mode: %s\n\n", tmp); - found++; - } - cur = cur->next; - } - ast_mutex_unlock(&iflock); - if (!found) - ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); - return RESULT_SUCCESS; ->>>>>>> 1.576 } /*--- sip_show_channel: Show details of one call ---*/ static int sip_show_history(int fd, int argc, char *argv[]) { -<<<<<<< chan_sip.c struct sip_pvt *cur; struct sip_history *hist; size_t len; @@ -7683,45 +6007,6 @@ if (!found) ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); return RESULT_SUCCESS; -======= - struct sip_pvt *cur; - struct sip_history *hist; - size_t len; - int x; - int found = 0; - - if (argc != 4) - return RESULT_SHOWUSAGE; - if (!recordhistory) - ast_cli(fd, "\n***Note: History recording is currently DISABLED. Use 'sip history' to ENABLE.\n"); - len = strlen(argv[3]); - ast_mutex_lock(&iflock); - cur = iflist; - while(cur) { - if (!strncasecmp(cur->callid, argv[3],len)) { - ast_cli(fd,"\n"); - if (cur->subscribed) - ast_cli(fd, " * Subscription\n"); - else - ast_cli(fd, " * SIP Call\n"); - x = 0; - hist = cur->history; - while(hist) { - x++; - ast_cli(fd, "%d. %s\n", x, hist->event); - hist = hist->next; - } - if (!x) - ast_cli(fd, "Call '%s' has no history\n", cur->callid); - found++; - } - cur = cur->next; - } - ast_mutex_unlock(&iflock); - if (!found) - ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); - return RESULT_SUCCESS; ->>>>>>> 1.576 } @@ -7729,7 +6014,6 @@ /* Doesn't read the duration of the DTMF signal */ static void receive_info(struct sip_pvt *p, struct sip_request *req) { -<<<<<<< chan_sip.c char buf[1024] = ""; unsigned int event; char resp = 0; @@ -7791,87 +6075,11 @@ ast_log(LOG_WARNING, "Unable to parse INFO message from %s. Content %s\n", p->callid, buf); transmit_response(p, "415 Unsupported media type", req); return; -======= - char buf[1024] = ""; - unsigned int event; - 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") || - !strcasecmp(get_header(req, "Content-Type"), "application/vnd.nortelnetworks.digits")) { - - /* Try getting the "signal=" part */ - if (ast_strlen_zero(c = get_sdp(req, "Signal")) && ast_strlen_zero(c = get_sdp(req, "d"))) { - ast_log(LOG_WARNING, "Unable to retrieve DTMF signal from INFO message from %s\n", p->callid); - transmit_response(p, "200 OK", req); /* Should return error */ - return; - } else { - strncpy(buf, c, sizeof(buf) - 1); - } - - if (p->owner) { /* PBX call */ - if (!ast_strlen_zero(buf)) { - if (sipdebug) - ast_verbose("* DTMF received: '%c'\n", buf[0]); - if (buf[0] == '*') - event = 10; - else if (buf[0] == '#') - event = 11; - else - event = atoi(buf); - if (event < 10) { - resp = '0' + event; - } else if (event < 11) { - resp = '*'; - } else if (event < 12) { - resp = '#'; - } else if (event < 16) { - resp = 'A' + (event - 12); - } - /* Build DTMF frame and deliver to PBX for transmission to other call leg*/ - memset(&f, 0, sizeof(f)); - f.frametype = AST_FRAME_DTMF; - f.subclass = resp; - f.offset = 0; - f.data = NULL; - f.datalen = 0; - ast_queue_frame(p->owner, &f); - } - transmit_response(p, "200 OK", req); - return; - } else { - transmit_response(p, "481 Call leg/transaction does not exist", req); - p->needdestroy = 1; - } - return; - } else if ((c = get_header(req, "X-ClientCode"))) { - /* Client code (from SNOM phone) */ - if (p->useclientcode) { - if (p->owner && p->owner->cdr) - ast_cdr_setuserfield(p->owner, c); - if (p->owner && ast_bridged_channel(p->owner) && ast_bridged_channel(p->owner)->cdr) - ast_cdr_setuserfield(ast_bridged_channel(p->owner), c); - transmit_response(p, "200 OK", req); - } else { - transmit_response(p, "403 Unauthorized", req); - } - return; - } - /* Other type of INFO message, not really understood by Asterisk */ - /* if (get_msg_text(buf, sizeof(buf), req)) { */ - - ast_log(LOG_WARNING, "Unable to parse INFO message from %s. Content %s\n", p->callid, buf); - transmit_response(p, "415 Unsupported media type", req); - return; ->>>>>>> 1.576 } /*--- sip_do_debug: Enable SIP Debugging in CLI ---*/ static int sip_do_debug_ip(int fd, int argc, char *argv[]) { -<<<<<<< chan_sip.c struct hostent *hp; struct ast_hostent ahp; char iabuf[INET_ADDRSTRLEN]; @@ -7899,36 +6107,6 @@ ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr), port); sipdebug = 1; return RESULT_SUCCESS; -======= - struct hostent *hp; - struct ast_hostent ahp; - char iabuf[INET_ADDRSTRLEN]; - int port = 0; - char *p, *arg; - - if (argc != 4) - return RESULT_SHOWUSAGE; - arg = argv[3]; - p = strstr(arg, ":"); - if (p) { - *p = '\0'; - p++; - port = atoi(p); - } - hp = ast_gethostbyname(arg, &ahp); - if (hp == NULL) { - return RESULT_SHOWUSAGE; - } - debugaddr.sin_family = AF_INET; - memcpy(&debugaddr.sin_addr, hp->h_addr, sizeof(debugaddr.sin_addr)); - debugaddr.sin_port = htons(port); - if (port == 0) - ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr)); - else - ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), debugaddr.sin_addr), port); - sipdebug = 1; - return RESULT_SUCCESS; ->>>>>>> 1.576 } static int sip_do_debug_peer(int fd, int argc, char *argv[]) @@ -7978,7 +6156,6 @@ return RESULT_SUCCESS; } -/*--- sip_do_history: Enable SIP History logging (CLI) ---*/ static int sip_do_history(int fd, int argc, char *argv[]) { if (argc != 2) { @@ -7989,7 +6166,6 @@ return RESULT_SUCCESS; } -/*--- sip_no_history: Disable SIP History logging (CLI) ---*/ static int sip_no_history(int fd, int argc, char *argv[]) { if (argc != 3) { @@ -8334,7 +6510,6 @@ /*--- handle_response: Handle SIP response in dialogue ---*/ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore) { -<<<<<<< chan_sip.c char *to; char *msg, *c; struct ast_channel *owner; @@ -8472,149 +6647,7 @@ if (p->owner->_state != AST_STATE_UP) { #ifdef OSP_SUPPORT time(&p->ospstart); -======= - char *to; - char *msg, *c; - struct ast_channel *owner; - struct sip_peer *peer; - int pingtime; - struct timeval tv; - int seqno=0; - char iabuf[INET_ADDRSTRLEN]; - - c = get_header(req, "Cseq"); - if (sscanf(c, "%d ", &seqno) != 1) { - ast_log(LOG_WARNING, "Unable to determine sequence number\n"); - } - msg = strchr(c, ' '); - if (!msg) msg = ""; else msg++; - owner = p->owner; - if (owner) - owner->hangupcause = hangup_sip2cause(resp); - /* Acknowledge whatever it is destined for */ - if ((resp >= 100) && (resp <= 199)) - __sip_semi_ack(p, seqno, 0, msg); - else - __sip_ack(p, seqno, 0, msg); - /* Get their tag if we haven't already */ - to = get_header(req, "To"); - to = strstr(to, "tag="); - if (to) { - to += 4; - strncpy(p->theirtag, to, sizeof(p->theirtag) - 1); - to = strchr(p->theirtag, ';'); - if (to) - *to = '\0'; - } - if (p->peerpoke) { - /* 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) { - int statechanged = 0; - int newstate = 0; - peer = p->peerpoke; - gettimeofday(&tv, NULL); - pingtime = (tv.tv_sec - peer->ps.tv_sec) * 1000 + - (tv.tv_usec - peer->ps.tv_usec) / 1000; - if (pingtime < 1) - pingtime = 1; - if ((peer->lastms < 0) || (peer->lastms > peer->maxms)) { - if (pingtime <= peer->maxms) { - ast_log(LOG_NOTICE, "Peer '%s' is now REACHABLE! (%dms / %dms)\n", peer->name, pingtime, peer->maxms); - statechanged = 1; - newstate = 1; - } - } else if ((peer->lastms > 0) && (peer->lastms <= peer->maxms)) { - if (pingtime > peer->maxms) { - ast_log(LOG_NOTICE, "Peer '%s' is now TOO LAGGED! (%dms / %dms)\n", peer->name, pingtime, peer->maxms); - statechanged = 1; - newstate = 2; - } - } - if (!peer->lastms) - statechanged = 1; - peer->lastms = pingtime; - peer->call = NULL; - if (statechanged) { - ast_device_state_changed("SIP/%s", peer->name); - if (newstate == 2) { - manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Lagged\r\nTime: %d\r\n", peer->name, pingtime); - } else { - manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Reachable\r\nTime: %d\r\n", peer->name, pingtime); - } - } - - if (peer->pokeexpire > -1) - ast_sched_del(sched, peer->pokeexpire); - if (!strcasecmp(msg, "INVITE")) - transmit_request(p, "ACK", seqno, 0, 0); - p->needdestroy = 1; - /* Try again eventually */ - if ((peer->lastms < 0) || (peer->lastms > peer->maxms)) - peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer); - else - peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_OK, sip_poke_peer_s, peer); - } - } else if (p->outgoing) { - /* Acknowledge sequence number */ - if (p->initid > -1) { - /* Don't auto congest anymore since we've gotten something useful back */ - ast_sched_del(sched, p->initid); - p->initid = -1; - } - switch(resp) { - case 100: /* 100 Trying */ - if (!strcasecmp(msg, "INVITE")) { - sip_cancel_destroy(p); - } - break; - case 183: /* 183 Session Progress */ - if (!strcasecmp(msg, "INVITE")) { - sip_cancel_destroy(p); - if (!ast_strlen_zero(get_header(req, "Content-Type"))) - process_sdp(p, req); - if (p->owner) { - /* Queue a progress frame */ - ast_queue_control(p->owner, AST_CONTROL_PROGRESS); - } - } - break; - case 180: /* 180 Ringing */ - if (!strcasecmp(msg, "INVITE")) { - sip_cancel_destroy(p); - if (p->owner) { - ast_queue_control(p->owner, AST_CONTROL_RINGING); - if (p->owner->_state != AST_STATE_UP) - ast_setstate(p->owner, AST_STATE_RINGING); - } - } - break; - case 200: /* 200 OK */ - if (!strcasecmp(msg, "NOTIFY")) { - /* They got the notify, this is the end */ - if (p->owner) { - ast_log(LOG_WARNING, "Notify answer on an owned channel?\n"); - ast_queue_hangup(p->owner); - } else { - if (!p->subscribed) { - p->needdestroy = 1; - } - } - } else if (!strcasecmp(msg, "INVITE")) { - /* 200 OK on invite - someone's answering our call */ - sip_cancel_destroy(p); - if (!ast_strlen_zero(get_header(req, "Content-Type"))) - process_sdp(p, req); - /* Save Record-Route for any later requests we make on this dialogue */ - build_route(p, req, 1); - if (p->owner) { - if (p->owner->_state != AST_STATE_UP) { -#ifdef OSP_SUPPORT - time(&p->ospstart); ->>>>>>> 1.576 #endif -<<<<<<< chan_sip.c ast_queue_control(p->owner, AST_CONTROL_ANSWER); } else { struct ast_frame af = { AST_FRAME_NULL, }; @@ -8843,236 +6876,6 @@ break; } } -======= - ast_queue_control(p->owner, AST_CONTROL_ANSWER); - } else { - struct ast_frame af = { AST_FRAME_NULL, }; - ast_queue_frame(p->owner, &af); - } - } else /* It's possible we're getting an ACK after we've tried to disconnect - by sending CANCEL */ - p->pendingbye = 1; - p->authtries = 0; - /* If I understand this right, the branch is different for a non-200 ACK only */ - transmit_request(p, "ACK", seqno, 0, 1); - check_pendings(p); - } else if (!strcasecmp(msg, "REGISTER")) { - /* char *exp; */ - int expires, expires_ms; - struct sip_registry *r; - r=p->registry; - if (r) { - r->regstate=REG_STATE_REGISTERED; - manager_event(EVENT_FLAG_SYSTEM, "Registry", "Channel: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate)); - ast_log(LOG_DEBUG, "Registration successful\n"); - if (r->timeout > -1) { - ast_log(LOG_DEBUG, "Cancelling timeout %d\n", r->timeout); - ast_sched_del(sched, r->timeout); - } - r->timeout=-1; - r->call = NULL; - p->registry = NULL; - p->needdestroy = 1; - /* set us up for re-registering */ - /* figure out how long we got registered for */ - if (r->expire > -1) - ast_sched_del(sched, r->expire); - /* according to section 6.13 of RFC, contact headers override - expires headers, so check those first */ - expires = 0; - if (!ast_strlen_zero(get_header(req, "Contact"))) { - char *contact = NULL; - char *tmptmp = NULL; - int start = 0; - for(;;) { - contact = __get_header(req, "Contact", &start); - /* this loop ensures we get a contact header about our register request */ - if(!ast_strlen_zero(contact)) { - if( (tmptmp=strstr(contact, p->our_contact))) { - contact=tmptmp; - break; - } - } else - break; - } - tmptmp = strstr(contact, "expires="); - if (tmptmp) { - if (sscanf(tmptmp + 8, "%d;", &expires) != 1) - expires = 0; - } - } - if (!expires) expires=atoi(get_header(req, "expires")); - if (!expires) expires=default_expiry; - - expires_ms = expires * 1000; - if (expires <= EXPIRY_GUARD_LIMIT) - expires_ms -= MAX((expires_ms * EXPIRY_GUARD_PCT),EXPIRY_GUARD_MIN); - else - expires_ms -= EXPIRY_GUARD_SECS * 1000; - - r->refresh= (int) expires_ms / 1000; - 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"); - - } - break; - case 401: /* Not authorized on REGISTER */ - if (!strcasecmp(msg, "INVITE")) { - /* First we ACK */ - transmit_request(p, "ACK", seqno, 0, 0); - /* Then we AUTH */ - if ((p->authtries > 1) || do_proxy_auth(p, req, "WWW-Authenticate", "Authorization", "INVITE", 1)) { - ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From")); - p->needdestroy = 1; - } - } else if (p->registry && !strcasecmp(msg, "REGISTER")) { - if ((p->authtries > 1) || do_register_auth(p, req, "WWW-Authenticate", "Authorization")) { - ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s'\n", get_header(&p->initreq, "From")); - p->needdestroy = 1; - } - } else - p->needdestroy = 1; - break; - case 407: /* 407 Proxy Authentication Required */ - if (!strcasecmp(msg, "INVITE")) { - /* First we ACK */ - transmit_request(p, "ACK", seqno, 0, 0); - /* Then we AUTH */ - /* But only if the packet wasn't marked as ignore in handle_request */ - if(!ignore){ - if ((p->authtries > 1) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", "INVITE", 1)) { - ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From")); - p->needdestroy = 1; - } - } - } else if (!strcasecmp(msg, "BYE") || !strcasecmp(msg, "REFER")) { - if (ast_strlen_zero(p->authname)) - ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n", - msg, ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port)); - if ((p->authtries > 1) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", msg, 0)) { - ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); - p->needdestroy = 1; - } - } else if (p->registry && !strcasecmp(msg, "REGISTER")) { - if ((p->authtries > 1) || do_register_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization")) { - ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s' (tries '%d')\n", get_header(&p->initreq, "From"), p->authtries); - p->needdestroy = 1; - } - } else - p->needdestroy = 1; - - break; - case 501: /* Not Implemented */ - if (!strcasecmp(msg, "INVITE")) { - if (p->owner) - ast_queue_control(p->owner, AST_CONTROL_CONGESTION); - } else - ast_log(LOG_WARNING, "Host '%s' does not implement '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), msg); - break; - default: - if ((resp >= 300) && (resp < 700)) { - if ((option_verbose > 2) && (resp != 487)) - ast_verbose(VERBOSE_PREFIX_3 "Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr)); - p->alreadygone = 1; - if (p->rtp) { - /* Immediately stop RTP */ - ast_rtp_stop(p->rtp); - } - if (p->vrtp) { - /* Immediately stop VRTP */ - ast_rtp_stop(p->vrtp); - } - /* XXX Locking issues?? XXX */ - switch(resp) { - case 300: /* Multiple Choices */ - case 301: /* Moved permenantly */ - case 302: /* Moved temporarily */ - case 305: /* Use Proxy */ - parse_moved_contact(p, req); - if (p->owner) - ast_queue_control(p->owner, AST_CONTROL_BUSY); - break; - case 487: - /* channel now destroyed - dec the inUse counter */ - if ( p->outgoing ) { - update_user_counter(p, DEC_OUT_USE); - } - else { - update_user_counter(p, DEC_IN_USE); - } - break; - case 482: /* SIP is incapable of performing a hairpin call, which - is yet another failure of not having a layer 2 (again, YAY - IETF for thinking ahead). So we treat this as a call - forward and hope we end up at the right place... */ - ast_log(LOG_DEBUG, "Hairpin detected, setting up call forward for what it's worth\n"); - if (p->owner) - snprintf(p->owner->call_forward, sizeof(p->owner->call_forward), "Local/%s@%s", p->username, p->context); - /* Fall through */ - case 486: /* Busy here */ - case 600: /* Busy everywhere */ - case 603: /* Decline */ - if (p->owner) - ast_queue_control(p->owner, AST_CONTROL_BUSY); - break; - case 480: /* Temporarily Unavailable */ - case 404: /* Not Found */ - case 410: /* Gone */ - case 400: /* Bad Request */ - case 500: /* Server error */ - case 503: /* Service Unavailable */ - if (owner) - ast_queue_control(p->owner, AST_CONTROL_CONGESTION); - break; - default: - /* Send hangup */ - if (owner) - ast_queue_hangup(p->owner); - break; - } - /* ACK on invite */ - if (!strcasecmp(msg, "INVITE")) - transmit_request(p, "ACK", seqno, 0, 0); - p->alreadygone = 1; - if (!p->owner) - p->needdestroy = 1; - } else if ((resp >= 100) && (resp < 200)) { - if (!strcasecmp(msg, "INVITE")) { - sip_cancel_destroy(p); - if (!ast_strlen_zero(get_header(req, "Content-Type"))) - process_sdp(p, req); - if (p->owner) { - /* Queue a progress frame */ - ast_queue_control(p->owner, AST_CONTROL_PROGRESS); - } - } - } else - ast_log(LOG_NOTICE, "Dunno anything about a %d %s response from %s\n", resp, rest, p->owner ? p->owner->name : ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr)); - } - } else { - if (sip_debug_test_pvt(p)) - ast_verbose("Message is %s\n", msg); - switch(resp) { - case 200: - /* Change branch since this is a 200 response */ - if (!strcasecmp(msg, "INVITE") || !strcasecmp(msg, "REGISTER") ) - transmit_request(p, "ACK", seqno, 0, 1); - break; - case 407: - if (!strcasecmp(msg, "BYE") || !strcasecmp(msg, "REFER")) { - if (ast_strlen_zero(p->authname)) - ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n", - msg, ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port)); - if ((p->authtries > 1) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", msg, 0)) { - ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); - p->needdestroy = 1; - } - } - break; - } - } ->>>>>>> 1.576 } struct sip_dual { @@ -9103,7 +6906,6 @@ return NULL; } -/*--- sip_park: Park a call ---*/ static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req) { struct sip_dual *d; @@ -9162,18 +6964,10 @@ return -1; } -static void ast_quiet_chan(struct ast_channel *chan) -{ - if (chan && chan->_state == AST_STATE_UP) { - if (chan->generatordata) - ast_deactivate_generator(chan); - } -} /*--- attempt_transfer: Attempt transfer of SIP call ---*/ static int attempt_transfer(struct sip_pvt *p1, struct sip_pvt *p2) { -<<<<<<< chan_sip.c if (!p1->owner || !p2->owner) { ast_log(LOG_WARNING, "Transfer attempted without dual ownership?\n"); return -1; @@ -9221,81 +7015,12 @@ return -1; } return 0; -======= - int res = 0; - struct ast_channel - *chana = NULL, - *chanb = NULL, - *bridgea = NULL, - *bridgeb = NULL, - *peera = NULL, - *peerb = NULL, - *peerc = NULL, - *peerd = NULL; - - if (!p1->owner || !p2->owner) { - ast_log(LOG_WARNING, "Transfer attempted without dual ownership?\n"); - return -1; - } - chana = p1->owner; - chanb = p2->owner; - bridgea = ast_bridged_channel(chana); - bridgeb = ast_bridged_channel(chanb); - - if (bridgea) { - peera = chana; - peerb = chanb; - peerc = bridgea; - peerd = bridgeb; - } else if (bridgeb) { - peera = chanb; - peerb = chana; - peerc = bridgeb; - peerd = bridgea; - } - - if (peera && peerb && peerc) { - ast_quiet_chan(peera); - ast_quiet_chan(peerb); - ast_quiet_chan(peerc); - ast_quiet_chan(peerd); - - if (peera->cdr && peerb->cdr) { - peerb->cdr = ast_cdr_append(peerb->cdr, peera->cdr); - } else if(peera->cdr) { - peerb->cdr = peera->cdr; - } - peera->cdr = NULL; - - if (peerb->cdr && peerc->cdr) { - peerb->cdr = ast_cdr_append(peerb->cdr, peerc->cdr); - } else if(peerc->cdr) { - peerb->cdr = peerc->cdr; - } - peerc->cdr = NULL; - - if (ast_channel_masquerade(peerb, peerc)) { - ast_log(LOG_WARNING, "Failed to masquerade %s into %s\n", peerb->name, peerc->name); - res = -1; - } - return res; - } else { - ast_log(LOG_NOTICE, "Transfer attempted with no bridged calls to transfer\n"); - if (chana) - ast_softhangup_nolock(chana, AST_SOFTHANGUP_DEV); - if (chanb) - ast_softhangup_nolock(chanb, AST_SOFTHANGUP_DEV); - return -1; - } - return 0; ->>>>>>> 1.576 } /*--- handle_request: Handle SIP requests (methods) ---*/ /* this is where all incoming requests go first */ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock) { -<<<<<<< chan_sip.c /* Called with p->lock held, as well as p->owner->lock if appropriate, keeping things relatively static */ struct sip_request resp; @@ -9836,548 +7561,6 @@ p->needdestroy = 1; } return 0; -======= - /* Called with p->lock held, as well as p->owner->lock if appropriate, keeping things - relatively static */ - struct sip_request resp; - char *cmd; - char *cseq; - char *from; - char *e; - char *useragent; - struct ast_channel *c=NULL; - struct ast_channel *transfer_to; - int seqno; - int len; - int ignore=0; - int respid; - int res; - int gotdest; - char iabuf[INET_ADDRSTRLEN]; - struct ast_frame af = { AST_FRAME_NULL, }; - int debug = sip_debug_test_pvt(p); - - /* Clear out potential response */ - memset(&resp, 0, sizeof(resp)); - /* Get Method and Cseq */ - cseq = get_header(req, "Cseq"); - cmd = req->header[0]; - /* Must have Cseq */ - if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq)) - return -1; - if (sscanf(cseq, "%i%n", &seqno, &len) != 1) { - ast_log(LOG_DEBUG, "No seqno in '%s'\n", cmd); - return -1; - } - /* Get the command */ - cseq += len; - - /* Determine the request URI for sip, sips or tel URIs */ - if( determine_firstline_parts( req ) < 0 ) { - return -1; - } - cmd= req->rlPart1; - e= req->rlPart2; - - /* Save useragent of the client */ - useragent = get_header(req, "User-Agent"); - strncpy(p->useragent, useragent, sizeof(p->useragent)-1); - - - if (strcasecmp(cmd, "SIP/2.0")) { - /* 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) && (strcasecmp(cmd, "CANCEL") || p->alreadygone)) { - /* 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; - } - if (ast_strlen_zero(p->theirtag)) { - from = get_header(req, "From"); - from = strstr(from, "tag="); - if (from) { - from += 4; - strncpy(p->theirtag, from, sizeof(p->theirtag) - 1); - from = strchr(p->theirtag, ';'); - if (from) - *from = '\0'; - } - } - snprintf(p->lastmsg, sizeof(p->lastmsg), "Rx: %s", cmd); - } else { - /* 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; - return 0; - } else if (p->ocseq && (p->ocseq < seqno)) { - 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 - respond appropriately */ - ignore=1; - } - } - - if (strcmp(cmd, "SIP/2.0") && (seqno >= p->icseq)) - /* Next should follow monotonically (but not necessarily - incrementally -- thanks again to the genius authors of SIP -- - increasing */ - p->icseq = seqno; - - /* Initialize the context if it hasn't been already */ - if (!strcasecmp(cmd, "OPTIONS")) { - res = get_destination(p, req); - build_contact(p); - /* XXX Should we authenticate OPTIONS? XXX */ - if (ast_strlen_zero(p->context)) - strncpy(p->context, default_context, sizeof(p->context) - 1); - if (res < 0) - 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 - 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. */ - if (!p->lastinvite) - p->needdestroy = 1; - } else if (!strcasecmp(cmd, "INVITE")) { - if (p->outgoing && p->owner && (p->owner->_state != AST_STATE_UP)) { - /* This is a call to ourself. Send ourselves an error code and stop - processing immediately, as SIP really has no good mechanism for - being able to call yourself */ - transmit_response(p, "482 Loop Detected", req); - /* We do NOT destroy p here, so that our response will be accepted */ - return 0; - } - /* Process the SDP portion */ - if (!ignore) { - /* Use this as the basis */ - if (debug) - ast_verbose("Using latest request as basis request\n"); - sip_cancel_destroy(p); - /* This call is no longer outgoing if it ever was */ - p->outgoing = 0; - /* This also counts as a pending invite */ - p->pendinginvite = seqno; - copy_request(&p->initreq, req); - check_via(p, req); - if (!ast_strlen_zero(get_header(req, "Content-Type"))) { - if (process_sdp(p, req)) - return -1; - } else { - p->jointcapability = p->capability; - ast_log(LOG_DEBUG, "Hm.... No sdp for the moment\n"); - } - /* Queue NULL frame to prod ast_rtp_bridge if appropriate */ - if (p->owner) - ast_queue_frame(p->owner, &af); - } else if (debug) - ast_verbose("Ignoring this request\n"); - if (!p->lastinvite && !ignore && !p->owner) { - /* Handle authentication if this is our first invite */ - res = check_user(p, req, cmd, e, 1, sin, ignore); - if (res) { - if (res < 0) { - ast_log(LOG_NOTICE, "Failed to authenticate user %s\n", get_header(req, "From")); - if (ignore) - transmit_response(p, "403 Forbidden", req); - else - transmit_response_reliable(p, "403 Forbidden", req, 1); - p->needdestroy = 1; - } - return 0; - } - /* Initialize the context if it hasn't been already */ - if (ast_strlen_zero(p->context)) - strncpy(p->context, default_context, sizeof(p->context) - 1); - /* Check number of concurrent calls -vs- incoming limit HERE */ - ast_log(LOG_DEBUG, "Check for res for %s\n", p->username); - res = update_user_counter(p,INC_IN_USE); - if (res) { - if (res < 0) { - ast_log(LOG_DEBUG, "Failed to place call for user %s, too many calls\n", p->username); - p->needdestroy = 1; - } - return 0; - } - /* Get destination right away */ - gotdest = get_destination(p, NULL); - get_rdnis(p, NULL); - extract_uri(p, req); - build_contact(p); - - if (gotdest) { - if (gotdest < 0) { - if (ignore) - transmit_response(p, "404 Not Found", req); - else - transmit_response_reliable(p, "404 Not Found", req, 1); - update_user_counter(p,DEC_IN_USE); - } else { - if (ignore) - transmit_response(p, "484 Address Incomplete", req); - else - transmit_response_reliable(p, "484 Address Incomplete", req, 1); - update_user_counter(p,DEC_IN_USE); - } - p->needdestroy = 1; - } else { - /* 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 */ - p->tag = rand(); - /* First invitation */ - c = sip_new(p, AST_STATE_DOWN, ast_strlen_zero(p->username) ? NULL : p->username ); - *recount = 1; - /* Save Record-Route for any later requests we make on this dialogue */ - build_route(p, req, 0); - if (c) { - /* Pre-lock the call */ - ast_mutex_lock(&c->lock); - } - } - - } else - c = p->owner; - if (!ignore && p) - p->lastinvite = seqno; - if (c) { - switch(c->_state) { - case AST_STATE_DOWN: - transmit_response(p, "100 Trying", req); - ast_setstate(c, AST_STATE_RING); - if (strcmp(p->exten, ast_pickup_ext())) { - if (ast_pbx_start(c)) { - ast_log(LOG_WARNING, "Failed to start PBX :(\n"); - /* Unlock locks so ast_hangup can do its magic */ - ast_mutex_unlock(&c->lock); - ast_mutex_unlock(&p->lock); - ast_hangup(c); - ast_mutex_lock(&p->lock); - if (ignore) - transmit_response(p, "503 Unavailable", req); - else - transmit_response_reliable(p, "503 Unavailable", req, 1); - c = NULL; - } - } else { - ast_mutex_unlock(&c->lock); - if (ast_pickup_call(c)) { - ast_log(LOG_NOTICE, "Nothing to pick up\n"); - if (ignore) - transmit_response(p, "503 Unavailable", req); - else - transmit_response_reliable(p, "503 Unavailable", req, 1); - p->alreadygone = 1; - /* Unlock locks so ast_hangup can do its magic */ - ast_mutex_unlock(&p->lock); - ast_hangup(c); - ast_mutex_lock(&p->lock); - c = NULL; - } else { - ast_mutex_unlock(&p->lock); - ast_setstate(c, AST_STATE_DOWN); - ast_hangup(c); - ast_mutex_lock(&p->lock); - c = NULL; - } - } - break; - case AST_STATE_RING: - transmit_response(p, "100 Trying", req); - break; - case AST_STATE_RINGING: - transmit_response(p, "180 Ringing", req); - break; - case AST_STATE_UP: - transmit_response_with_sdp(p, "200 OK", req, 1); - break; - default: - ast_log(LOG_WARNING, "Don't know how to handle INVITE in state %d\n", c->_state); - transmit_response(p, "100 Trying", req); - } - } else { - if (p && !p->needdestroy) { - ast_log(LOG_NOTICE, "Unable to create/find channel\n"); - if (ignore) - transmit_response(p, "503 Unavailable", req); - else - transmit_response_reliable(p, "503 Unavailable", req, 1); - p->needdestroy = 1; - } - } - } else if (!strcasecmp(cmd, "REFER")) { - ast_log(LOG_DEBUG, "We found a REFER!\n"); - if (ast_strlen_zero(p->context)) - strncpy(p->context, default_context, sizeof(p->context) - 1); - res = get_refer_info(p, req); - if (res < 0) - transmit_response_with_allow(p, "404 Not Found", req, 1); - else if (res > 0) - transmit_response_with_allow(p, "484 Address Incomplete", req, 1); - else { - int nobye = 0; - if (!ignore) { - if (p->refer_call) { - ast_log(LOG_DEBUG,"202 Accepted (supervised)\n"); - attempt_transfer(p, p->refer_call); - if (p->refer_call->owner) - ast_mutex_unlock(&p->refer_call->owner->lock); - ast_mutex_unlock(&p->refer_call->lock); - p->refer_call = NULL; - p->gotrefer = 1; - } else { - ast_log(LOG_DEBUG,"202 Accepted (blind)\n"); - c = p->owner; - if (c) { - transfer_to = ast_bridged_channel(c); - if (transfer_to) { - ast_moh_stop(transfer_to); - if (!strcmp(p->refer_to, ast_parking_ext())) { - /* Must release c's lock now, because it will not longer - be accessible after the transfer! */ - *nounlock = 1; - ast_mutex_unlock(&c->lock); - sip_park(transfer_to, c, req); - nobye = 1; - } else { - /* Must release c's lock now, because it will not longer - be accessible after the transfer! */ - *nounlock = 1; - ast_mutex_unlock(&c->lock); - ast_async_goto(transfer_to,p->context, p->refer_to,1); - } - } else { - ast_queue_hangup(p->owner); - } - } - p->gotrefer = 1; - } - transmit_response(p, "202 Accepted", req); - transmit_notify_with_sipfrag(p, seqno); - /* Always increment on a BYE */ - if (!nobye) { - transmit_request_with_auth(p, "BYE", 0, 1, 1); - p->alreadygone = 1; - } - } - } - } else if (!strcasecmp(cmd, "CANCEL")) { - check_via(p, req); - p->alreadygone = 1; - if (p->rtp) { - /* Immediately stop RTP */ - ast_rtp_stop(p->rtp); - } - if (p->vrtp) { - /* Immediately stop VRTP */ - ast_rtp_stop(p->vrtp); - } - if (p->owner) - ast_queue_hangup(p->owner); - else - p->needdestroy = 1; - if (p->initreq.len > 0) { - if (!ignore) - transmit_response_reliable(p, "487 Request Terminated", &p->initreq, 1); - transmit_response(p, "200 OK", req); - } else { - transmit_response(p, "481 Call Leg Does Not Exist", req); - } - } else if (!strcasecmp(cmd, "BYE")) { - copy_request(&p->initreq, req); - check_via(p, req); - p->alreadygone = 1; - if (p->rtp) { - /* Immediately stop RTP */ - ast_rtp_stop(p->rtp); - } - if (p->vrtp) { - /* Immediately stop VRTP */ - ast_rtp_stop(p->vrtp); - } - if (!ast_strlen_zero(get_header(req, "Also"))) { - ast_log(LOG_NOTICE, "Client '%s' using deprecated BYE/Also transfer method. Ask vendor to support REFER instead\n", - ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr)); - if (ast_strlen_zero(p->context)) - strncpy(p->context, default_context, sizeof(p->context) - 1); - res = get_also_info(p, req); - if (!res) { - c = p->owner; - if (c) { - transfer_to = ast_bridged_channel(c); - if (transfer_to) { - /* Don't actually hangup here... */ - ast_moh_stop(transfer_to); - ast_async_goto(transfer_to,p->context, p->refer_to,1); - } else - ast_queue_hangup(p->owner); - } - } else { - ast_log(LOG_WARNING, "Invalid transfer information from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr)); - ast_queue_hangup(p->owner); - } - } else if (p->owner) - ast_queue_hangup(p->owner); - else - p->needdestroy = 1; - transmit_response(p, "200 OK", req); - } else if (!strcasecmp(cmd, "MESSAGE")) { - if (!ignore) { - if (debug) - ast_verbose("Receiving message!\n"); - receive_message(p, req); - } - transmit_response(p, "200 OK", req); - } else if (!strcasecmp(cmd, "SUBSCRIBE")) { - if (!ignore) { - /* Use this as the basis */ - if (debug) - ast_verbose("Using latest SUBSCRIBE request as basis request\n"); - /* This call is no longer outgoing if it ever was */ - p->outgoing = 0; - copy_request(&p->initreq, req); - check_via(p, req); - } else if (debug) - ast_verbose("Ignoring this request\n"); - - if (!p->lastinvite) { - char mailbox[256]=""; - char rbox[256]; - int found = 0; - /* Handle authentication if this is our first subscribe */ - res = check_user_full(p, req, cmd, e, 0, sin, ignore, mailbox, sizeof(mailbox)); - if (res) { - if (res < 0) { - ast_log(LOG_NOTICE, "Failed to authenticate user %s for SUBSCRIBE\n", get_header(req, "From")); - p->needdestroy = 1; - } - return 0; - } - /* Initialize the context if it hasn't been already */ - if (ast_strlen_zero(p->context)) - strncpy(p->context, default_context, sizeof(p->context) - 1); - /* Get destination right away */ - gotdest = get_destination(p, NULL); - build_contact(p); - if (gotdest) { - if (gotdest < 0) - transmit_response(p, "404 Not Found", req); - else - transmit_response(p, "484 Address Incomplete", req); - p->needdestroy = 1; - } else { - /* Initialize tag */ - p->tag = rand(); - if (!strcmp(get_header(req, "Accept"), "application/dialog-info+xml")) - p->subscribed = 2; - else if (!strcmp(get_header(req, "Accept"), "application/simple-message-summary")) { - /* Looks like they actually want a mailbox */ - snprintf(rbox, sizeof(rbox), ",%s@%s,", p->exten, p->context); - if (strstr(mailbox, rbox)) - found++; - if (!found) { - snprintf(rbox, sizeof(rbox), ",%s,", p->exten); - if (strstr(mailbox, rbox)) - found++; - } - if (found) - transmit_response(p, "200 OK", req); - else { - 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 - c = p->owner; - - if (!ignore && p) - p->lastinvite = seqno; - if (p && !p->needdestroy) { - if (!(p->expiry = atoi(get_header(req, "Expires")))) { - transmit_response(p, "200 OK", req); - p->needdestroy = 1; - return 0; - } - /* The next line can be removed if the SNOM200 Expires bug is fixed */ - if (p->subscribed == 1) { - if (p->expiry>max_expiry) - p->expiry = max_expiry; - } - transmit_response(p, "200 OK", req); - sip_scheddestroy(p, (p->expiry+10)*1000); - transmit_state_notify(p, ast_extension_state(NULL, p->context, p->exten),1); - } - } else if (!strcasecmp(cmd, "INFO")) { - if (!ignore) { - if (debug) - ast_verbose("Receiving DTMF!\n"); - receive_info(p, req); - } else { /* if ignoring, transmit response */ - transmit_response(p, "200 OK", req); - } - } else if (!strcasecmp(cmd, "NOTIFY")) { - /* XXX we get NOTIFY's from some servers. WHY?? Maybe we should - look into this someday XXX */ - transmit_response(p, "200 OK", req); - if (!p->lastinvite) p->needdestroy = 1; - } else if (!strcasecmp(cmd, "REGISTER")) { - /* Use this as the basis */ - if (debug) - 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) - 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 - get our 200 OK */ - sip_scheddestroy(p, 15*1000); - } - } else if (!strcasecmp(cmd, "ACK")) { - /* Make sure we don't ignore this */ - if (seqno == p->pendinginvite) { - p->pendinginvite = 0; - __sip_ack(p, seqno, FLAG_RESPONSE, NULL); - 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)) - p->needdestroy = 1; - } else if (!strcasecmp(cmd, "SIP/2.0")) { - extract_uri(p, req); - while(*e && (*e < 33)) e++; - if (sscanf(e, "%i %n", &respid, &len) != 1) { - ast_log(LOG_WARNING, "Invalid response: '%s'\n", e); - } else { - handle_response(p, respid, e + len, req,ignore); - } - } else { - transmit_response_with_allow(p, "405 Method Not Allowed", req, 0); - 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) - p->needdestroy = 1; - } - return 0; ->>>>>>> 1.576 } /*--- sipsock_read: Read data from SIP socket ---*/ @@ -10454,7 +7637,6 @@ /*--- sip_send_mwi_to_peer: Send message waiting indication ---*/ static int sip_send_mwi_to_peer(struct sip_peer *peer) { -<<<<<<< chan_sip.c /* Called with peerl lock, but releases it */ struct sip_pvt *p; char name[256] = ""; @@ -10499,59 +7681,11 @@ transmit_notify_with_mwi(p, newmsgs, oldmsgs); sip_scheddestroy(p, 15000); return 0; -======= - /* Called with peerl lock, but releases it */ - struct sip_pvt *p; - char name[256] = ""; - char iabuf[INET_ADDRSTRLEN]; - 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"); - ast_mutex_unlock(&peerl.lock); - return -1; - } - strncpy(name, peer->name, sizeof(name) - 1); - peer->lastmsgssent = ((newmsgs << 8) | (oldmsgs)); - ast_mutex_unlock(&peerl.lock); - if (create_addr(p, name)) { - /* Maybe they're not registered, etc. */ - sip_destroy(p); - return 0; - } - /* Recalculate our side, and recalculate Call ID */ - if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip)) - memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); - /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */ - if (p->nat & SIP_NAT_RFC3581) - snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x;rport", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); - else /* UNIDEN UIP200 bug */ - snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); - build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain); - /* Send MWI */ - p->outgoing = 1; - transmit_notify_with_mwi(p, newmsgs, oldmsgs); - sip_scheddestroy(p, 15000); - return 0; ->>>>>>> 1.576 } /*--- do_monitor: The SIP monitoring thread ---*/ static void *do_monitor(void *data) { -<<<<<<< chan_sip.c int res; struct sip_pvt *sip; struct sip_peer *peer; @@ -10667,125 +7801,6 @@ /* Never reached */ return NULL; -======= - int res; - struct sip_pvt *sip; - struct sip_peer *peer; - time_t t; - int fastrestart =0; - int lastpeernum = -1; - int curpeernum; - int reloading; - - /* Add an I/O event to our UDP socket */ - 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 */ - for(;;) { - /* Check for a reload request */ - ast_mutex_lock(&sip_reload_lock); - reloading = sip_reloading; - sip_reloading = 0; - ast_mutex_unlock(&sip_reload_lock); - if (reloading) { - if (option_verbose > 0) - ast_verbose(VERBOSE_PREFIX_1 "Reloading SIP\n"); - sip_do_reload(); - } - /* Check for interfaces needing to be killed */ - ast_mutex_lock(&iflock); -restartsearch: - time(&t); - sip = iflist; - while(sip) { - ast_mutex_lock(&sip->lock); - if (sip->rtp && sip->owner && (sip->owner->_state == AST_STATE_UP) && sip->lastrtprx && (sip->rtptimeout || sip->rtpholdtimeout) && !sip->redirip.sin_addr.s_addr) { - if (t > sip->lastrtprx + sip->rtptimeout) { - /* 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 && - (t > sip->lastrtprx + sip->rtpholdtimeout))) { - /* Needs a hangup */ - if (sip->rtptimeout) { - while(sip->owner && ast_mutex_trylock(&sip->owner->lock)) { - ast_mutex_unlock(&sip->lock); - usleep(1); - ast_mutex_lock(&sip->lock); - } - if (sip->owner) { - ast_log(LOG_NOTICE, "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n", sip->owner->name, (long)(t - sip->lastrtprx)); - /* Issue a softhangup */ - ast_softhangup(sip->owner, AST_SOFTHANGUP_DEV); - ast_mutex_unlock(&sip->owner->lock); - } - } - } - } - } - if (sip->needdestroy && !sip->packets && !sip->owner) { - ast_mutex_unlock(&sip->lock); - __sip_destroy(sip, 1); - goto restartsearch; - } - ast_mutex_unlock(&sip->lock); - sip = sip->next; - } - ast_mutex_unlock(&iflock); - /* Don't let anybody kill us right away. Nobody should lock the interface list - and wait for the monitor list, but the other way around is okay. */ - ast_mutex_lock(&monlock); - /* Lock the network interface */ - ast_mutex_lock(&netlock); - /* Okay, now that we know what to do, release the network lock */ - ast_mutex_unlock(&netlock); - /* And from now on, we're okay to be killed, so release the monitor lock as well */ - ast_mutex_unlock(&monlock); - pthread_testcancel(); - /* Wait for sched or io */ - res = ast_sched_wait(sched); - if ((res < 0) || (res > 1000)) - res = 1000; - /* If we might need to send more mailboxes, don't wait long at all.*/ - if (fastrestart) - res = 1; - res = ast_io_wait(io, res); - ast_mutex_lock(&monlock); - if (res >= 0) - ast_sched_runq(sched); - - /* needs work to send mwi to realtime peers */ - ast_mutex_lock(&peerl.lock); - peer = peerl.peers; - time(&t); - fastrestart = 0; - curpeernum = 0; - while(peer) { - if ((curpeernum > lastpeernum) && !ast_strlen_zero(peer->mailbox) && ((t - peer->lastmsgcheck) > global_mwitime)) { - sip_send_mwi_to_peer(peer); - fastrestart = 1; - lastpeernum = curpeernum; - break; - } - curpeernum++; - peer = peer->next; - } - /* Remember, sip_send_mwi_to_peer releases the lock if we've called it */ - if (!peer) { - /* Reset where we come from */ - lastpeernum = -1; - ast_mutex_unlock(&peerl.lock); - } - ast_mutex_unlock(&monlock); - } - /* Never reached */ - return NULL; - ->>>>>>> 1.576 } /*--- restart_monitor: Start the channel monitor thread ---*/ @@ -10842,11 +7857,8 @@ } /*--- sip_poke_peer: Check availability of peer, also keep NAT open ---*/ -/* This is done with the interval in qualify= option in sip.conf */ -/* Default is 2 seconds */ static int sip_poke_peer(struct sip_peer *peer) { -<<<<<<< chan_sip.c struct sip_pvt *p; char iabuf[INET_ADDRSTRLEN]; if (!peer->maxms || !peer->addr.sin_addr.s_addr) { @@ -10889,56 +7901,6 @@ ast_sched_del(sched, peer->pokeexpire); p->peerpoke = peer; p->outgoing = 1; -======= - struct sip_pvt *p; - char iabuf[INET_ADDRSTRLEN]; - if (!peer->maxms || !peer->addr.sin_addr.s_addr) { - /* IF we have no IP, or this isn't to be monitored, return - imeediately after clearing things out */ - if (peer->pokeexpire > -1) - ast_sched_del(sched, peer->pokeexpire); - peer->lastms = 0; - peer->pokeexpire = -1; - peer->call = NULL; - return 0; - } - if (peer->call > 0) { - ast_log(LOG_NOTICE, "Still have a call...\n"); - sip_destroy(peer->call); - } - p = peer->call = sip_alloc(NULL, NULL, 0); - if (!peer->call) { - ast_log(LOG_WARNING, "Unable to allocate call for poking peer '%s'\n", peer->name); - return -1; - } - memcpy(&p->sa, &peer->addr, sizeof(p->sa)); - memcpy(&p->recv, &peer->addr, sizeof(p->sa)); - - /* Send options to peer's fullcontact */ - if (!ast_strlen_zero(peer->fullcontact)) { - strncpy (p->fullcontact, peer->fullcontact, sizeof(p->fullcontact)); - } - - if (!ast_strlen_zero(p->tohost)) - strncpy(p->tohost, peer->tohost, sizeof(p->tohost) - 1); - else - ast_inet_ntoa(p->tohost, sizeof(p->tohost), peer->addr.sin_addr); - - /* Recalculate our side, and recalculate Call ID */ - if (ast_sip_ouraddrfor(&p->sa.sin_addr,&p->ourip)) - memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); - /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */ - if (p->nat & SIP_NAT_RFC3581) - snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x;rport", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); - else - snprintf(p->via, sizeof(p->via), "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); - build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain); - - if (peer->pokeexpire > -1) - ast_sched_del(sched, peer->pokeexpire); - p->peerpoke = peer; - p->outgoing = 1; ->>>>>>> 1.576 #ifdef VOCAL_DATA_HACK strncpy(p->username, "__VOCAL_DATA_SHOULD_READ_THE_SIP_SPEC__", sizeof(p->username) - 1); transmit_invite(p, "INVITE", 0, NULL, NULL, NULL,NULL,NULL, 1); @@ -11087,7 +8049,6 @@ /*--- build_user: Initiate a SIP user structure from sip.conf ---*/ static struct sip_user *build_user(const char *name, struct ast_variable *v) { -<<<<<<< chan_sip.c struct sip_user *user; int format; struct ast_ha *oldha = NULL; @@ -11105,32 +8066,9 @@ user->trustrpid = global_trustrpid; user->dtmfmode = global_dtmfmode; user->progressinband = global_progressinband; -======= - struct sip_user *user; - int format; - struct ast_ha *oldha = NULL; - char *varname = NULL, *varval = NULL; - struct ast_variable *tmpvar = NULL; - - user = (struct sip_user *)malloc(sizeof(struct sip_user)); - if (user) { - memset(user, 0, sizeof(struct sip_user)); - strncpy(user->name, name, sizeof(user->name)-1); - oldha = user->ha; - user->ha = NULL; - /* set the usage flag to a sane staring value*/ - user->inUse = 0; - user->outUse = 0; - user->capability = global_capability; - user->canreinvite = global_canreinvite; - user->trustrpid = global_trustrpid; - user->dtmfmode = global_dtmfmode; - user->progressinband = global_progressinband; ->>>>>>> 1.576 #ifdef OSP_SUPPORT user->ospauth = global_ospauth; #endif -<<<<<<< chan_sip.c /* set default context */ strncpy(user->context, default_context, sizeof(user->context)-1); strncpy(user->language, default_language, sizeof(user->language)-1); @@ -11220,114 +8158,6 @@ user->trustrpid = ast_true(v->value); } else if (!strcasecmp(v->name, "progressinband")) { user->progressinband = ast_true(v->value); -======= - /* set default context */ - strncpy(user->context, default_context, sizeof(user->context)-1); - strncpy(user->language, default_language, sizeof(user->language)-1); - strncpy(user->musicclass, global_musicclass, sizeof(user->musicclass)-1); - while(v) { - if (!strcasecmp(v->name, "context")) { - strncpy(user->context, v->value, sizeof(user->context) - 1); - } else if (!strcasecmp(v->name, "setvar")) { - varname = ast_strdupa(v->value); - if (varname && (varval = strchr(varname,'='))) { - *varval = '\0'; - varval++; - if((tmpvar = ast_new_variable(varname, varval))) { - tmpvar->next = user->vars; - user->vars = tmpvar; - } - - } - } else if (!strcasecmp(v->name, "permit") || - !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); - } else if (!strcasecmp(v->name, "md5secret")) { - strncpy(user->md5secret, v->value, sizeof(user->md5secret)-1); - } else if (!strcasecmp(v->name, "promiscredir")) { - user->promiscredir = ast_true(v->value); - } else if (!strcasecmp(v->name, "dtmfmode")) { - if (!strcasecmp(v->value, "inband")) - user->dtmfmode=SIP_DTMF_INBAND; - else if (!strcasecmp(v->value, "rfc2833")) - user->dtmfmode = SIP_DTMF_RFC2833; - else if (!strcasecmp(v->value, "info")) - user->dtmfmode = SIP_DTMF_INFO; - else { - ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n", v->value); - user->dtmfmode = SIP_DTMF_RFC2833; - } - } else if (!strcasecmp(v->name, "canreinvite")) { - if (!strcasecmp(v->value, "update")) - user->canreinvite = REINVITE_UPDATE; - else - user->canreinvite = ast_true(v->value); - } else if (!strcasecmp(v->name, "nat")) { - if (!strcasecmp(v->value, "never")) - user->nat = SIP_NAT_NEVER; - else if (!strcasecmp(v->value, "route")) - user->nat = SIP_NAT_ROUTE; - else if (ast_true(v->value)) - user->nat = SIP_NAT_ALWAYS; - else - user->nat = SIP_NAT_RFC3581; - } else if (!strcasecmp(v->name, "callerid")) { - ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num)); - } else if (!strcasecmp(v->name, "callgroup")) { - user->callgroup = ast_get_group(v->value); - } else if (!strcasecmp(v->name, "pickupgroup")) { - user->pickupgroup = ast_get_group(v->value); - } else if (!strcasecmp(v->name, "language")) { - strncpy(user->language, v->value, sizeof(user->language)-1); - } else if (!strcasecmp(v->name, "musiconhold")) { - strncpy(user->musicclass, v->value, sizeof(user->musicclass)-1); - } else if (!strcasecmp(v->name, "accountcode")) { - strncpy(user->accountcode, v->value, sizeof(user->accountcode)-1); - } else if (!strcasecmp(v->name, "incominglimit")) { - user->incominglimit = atoi(v->value); - if (user->incominglimit < 0) - user->incominglimit = 0; - } else if (!strcasecmp(v->name, "outgoinglimit")) { - user->outgoinglimit = atoi(v->value); - if (user->outgoinglimit < 0) - user->outgoinglimit = 0; - } else if (!strcasecmp(v->name, "amaflags")) { - format = ast_cdr_amaflags2int(v->value); - if (format < 0) { - ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno); - } else { - user->amaflags = format; - } - } 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 - user->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 - user->capability &= ~format; - } else if (!strcasecmp(v->name, "insecure")) { - user->insecure = ast_true(v->value); - } else if (!strcasecmp(v->name, "callingpres")) { - user->callingpres = atoi(v->value); - } else if (!strcasecmp(v->name, "trustrpid")) { - user->trustrpid = ast_true(v->value); - } else if (!strcasecmp(v->name, "useclientcode")) { - user->useclientcode = ast_true(v->value); - } else if (!strcasecmp(v->name, "progressinband")) { - if (!strcasecmp(v->value, "never")) - user->progressinband = 0; - else if (ast_true(v->value)) - user->progressinband = 2; - else - user->progressinband = 1; ->>>>>>> 1.576 #ifdef OSP_SUPPORT } else if (!strcasecmp(v->name, "ospauth")) { if (!strcasecmp(v->value, "exclusive")) { @@ -11387,7 +8217,6 @@ /*--- build_peer: Build peer from config file ---*/ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int temponly) { -<<<<<<< chan_sip.c struct sip_peer *peer; struct sip_peer *prev; struct ast_ha *oldha = NULL; @@ -11450,75 +8279,9 @@ peer->promiscredir = global_promiscredir; peer->trustrpid = global_trustrpid; peer->progressinband = global_progressinband; -======= - struct sip_peer *peer; - struct sip_peer *prev; - struct ast_ha *oldha = NULL; - int maskfound=0; - int format; - int found=0; - - prev = NULL; - ast_mutex_lock(&peerl.lock); - if (temponly) { - peer = NULL; - } else { - peer = peerl.peers; - while(peer) { - if (!strcasecmp(peer->name, name)) { - break; - } - prev = peer; - peer = peer->next; - } - } - if (peer) { - found++; - /* Already in the list, remove it and it will be added back (or FREE'd) */ - if (prev) { - prev->next = peer->next; - } else { - peerl.peers = peer->next; - } - ast_mutex_unlock(&peerl.lock); - } else { - ast_mutex_unlock(&peerl.lock); - peer = malloc(sizeof(struct sip_peer)); - if (peer) { - memset(peer, 0, sizeof(struct sip_peer)); - peer->expire = -1; - peer->pokeexpire = -1; - } - } - if (peer) { - peer->lastmsgssent = -1; - if (!found) { - strncpy(peer->name, name, sizeof(peer->name)-1); - strncpy(peer->context, default_context, sizeof(peer->context)-1); - strncpy(peer->language, default_language, sizeof(peer->language)-1); - strncpy(peer->musicclass, global_musicclass, sizeof(peer->musicclass)-1); - peer->addr.sin_port = htons(DEFAULT_SIP_PORT); - peer->addr.sin_family = AF_INET; - peer->defaddr.sin_family = AF_INET; - peer->expiry = expiry; - } - oldha = peer->ha; - peer->ha = NULL; - peer->addr.sin_family = AF_INET; - peer->capability = global_capability; - /* Assume can reinvite */ - peer->canreinvite = global_canreinvite; - peer->rtptimeout = global_rtptimeout; - peer->rtpholdtimeout = global_rtpholdtimeout; - peer->dtmfmode = global_dtmfmode; - peer->promiscredir = global_promiscredir; - peer->trustrpid = global_trustrpid; - peer->progressinband = global_progressinband; ->>>>>>> 1.576 #ifdef OSP_SUPPORT peer->ospauth = global_ospauth; #endif -<<<<<<< chan_sip.c while(v) { if (!strcasecmp(v->name, "secret")) strncpy(peer->secret, v->value, sizeof(peer->secret)-1); @@ -11546,39 +8309,7 @@ peer->promiscredir = ast_true(v->value); else if (!strcasecmp(v->name, "fromuser")) strncpy(peer->fromuser, v->value, sizeof(peer->fromuser)-1); -======= - 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, "callerid")) { - ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name), peer->cid_num, sizeof(peer->cid_num)); - } 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); ->>>>>>> 1.576 else if (!strcasecmp(v->name, "dtmfmode")) { -<<<<<<< chan_sip.c if (!strcasecmp(v->value, "inband")) peer->dtmfmode=SIP_DTMF_INBAND; else if (!strcasecmp(v->value, "rfc2833")) @@ -11689,125 +8420,6 @@ peer->trustrpid = ast_true(v->value); } else if (!strcasecmp(v->name, "progressinband")) { peer->progressinband = ast_true(v->value); -======= - 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)) { - destroy_peer(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)) { - destroy_peer(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, "useclientcode")) { - peer->useclientcode = ast_true(v->value); - } else if (!strcasecmp(v->name, "trustrpid")) { - peer->trustrpid = ast_true(v->value); - } else if (!strcasecmp(v->name, "progressinband")) { - if (!strcasecmp(v->value, "never")) - peer->progressinband = 0; - else if (ast_true(v->value)) - peer->progressinband = 2; - else - peer->progressinband = 1; ->>>>>>> 1.576 #ifdef OSP_SUPPORT } else if (!strcasecmp(v->name, "ospauth")) { if (!strcasecmp(v->value, "exclusive")) { @@ -11832,14 +8444,8 @@ } /*--- reload_config: Re-read SIP.conf config file ---*/ -/* This function reloads all config data, except for - active peers (with registrations). They will only - change configuration data at restart, not at reload. - SIP debug and recordhistory state will not change - */ static int reload_config(void) { -<<<<<<< chan_sip.c struct ast_config *cfg; struct ast_variable *v; struct sip_peer *peer; @@ -11962,155 +8568,6 @@ global_trustrpid = ast_true(v->value); } else if (!strcasecmp(v->name, "progressinband")) { global_progressinband = ast_true(v->value); -======= - struct ast_config *cfg; - struct ast_variable *v; - struct sip_peer *peer; - struct sip_user *user; - struct ast_hostent ahp; - char *cat; - char *utype; - struct hostent *hp; - int format; - int oldport = ntohs(bindaddr.sin_port); - char iabuf[INET_ADDRSTRLEN]; - - - if (gethostname(ourhost, sizeof(ourhost))) { - ast_log(LOG_WARNING, "Unable to get hostname, SIP disabled\n"); - return 0; - } - cfg = ast_load(config); - - /* We *must* have a config file otherwise stop immediately */ - if (!cfg) { - ast_log(LOG_NOTICE, "Unable to load config %s, SIP disabled\n", config); - return 0; - } - - - sip_prefs_free(); - - /* Reset IP addresses */ - memset(&bindaddr, 0, sizeof(bindaddr)); - memset(&localaddr, 0, sizeof(localaddr)); - memset(&externip, 0, sizeof(externip)); - - /* Initialize some reasonable defaults at SIP reload */ - global_nat = SIP_NAT_RFC3581; - strncpy(default_context, DEFAULT_CONTEXT, sizeof(default_context) - 1); - default_language[0] = '\0'; - default_fromdomain[0] = '\0'; - strncpy(default_useragent, DEFAULT_USERAGENT, sizeof(default_useragent) - 1); - strncpy(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime) - 1); - global_realm[sizeof(global_realm)-1] = '\0'; - strncpy(global_musicclass, "default", sizeof(global_musicclass) - 1); - strncpy(default_callerid, DEFAULT_CALLERID, sizeof(default_callerid) - 1); - global_canreinvite = REINVITE_INVITE; - videosupport = 0; - relaxdtmf = 0; - ourport = DEFAULT_SIP_PORT; - global_rtptimeout = 0; - global_rtpholdtimeout = 0; - pedanticsipchecking = 0; - global_dtmfmode = SIP_DTMF_RFC2833; - global_promiscredir = 0; - global_trustrpid = 0; - global_progressinband = 0; - global_mwitime = DEFAULT_MWITIME; - srvlookup = 0; - autocreatepeer = 0; - regcontext[0] = '\0'; - tos = 0; - expiry = DEFAULT_EXPIRY; - -#ifdef OSP_SUPPORT - global_ospauth = 0; /* OSP = Open Settlement Protocol */ -#endif - - /* Read the [general] config section of sip.conf (or from realtime config) */ - v = ast_variable_browse(cfg, "general"); - while(v) { - /* Create the interface list */ - if (!strcasecmp(v->name, "context")) { - strncpy(default_context, v->value, sizeof(default_context)-1); - } else if (!strcasecmp(v->name, "realm")) { - strncpy(global_realm, v->value, sizeof(global_realm)-1); - global_realm[sizeof(global_realm)-1] = '\0'; - } else if (!strcasecmp(v->name, "useragent")) { - strncpy(default_useragent, v->value, sizeof(default_useragent)-1); - ast_log(LOG_DEBUG, "Setting User Agent Name to %s\n", - default_useragent); - } else if (!strcasecmp(v->name, "relaxdtmf")) { - relaxdtmf = ast_true(v->value); - } else if (!strcasecmp(v->name, "promiscredir")) { - global_promiscredir = ast_true(v->value); - } else if (!strcasecmp(v->name, "dtmfmode")) { - if (!strcasecmp(v->value, "inband")) - global_dtmfmode=SIP_DTMF_INBAND; - else if (!strcasecmp(v->value, "rfc2833")) - global_dtmfmode = SIP_DTMF_RFC2833; - else if (!strcasecmp(v->value, "info")) - global_dtmfmode = SIP_DTMF_INFO; - else { - ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n", v->value); - global_dtmfmode = SIP_DTMF_RFC2833; - } - } else if (!strcasecmp(v->name, "checkmwi")) { - if ((sscanf(v->value, "%d", &global_mwitime) != 1) || (global_mwitime < 0)) { - ast_log(LOG_WARNING, "'%s' is not a valid MWI time setting at line %d. Using default (10).\n", v->value, v->lineno); - global_mwitime = DEFAULT_MWITIME; - } - } else if (!strcasecmp(v->name, "rtptimeout")) { - if ((sscanf(v->value, "%d", &global_rtptimeout) != 1) || (global_rtptimeout < 0)) { - ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); - global_rtptimeout = 0; - } - } else if (!strcasecmp(v->name, "rtpholdtimeout")) { - if ((sscanf(v->value, "%d", &global_rtpholdtimeout) != 1) || (global_rtpholdtimeout < 0)) { - ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); - global_rtpholdtimeout = 0; - } - } else if (!strcasecmp(v->name, "videosupport")) { - videosupport = ast_true(v->value); - } else if (!strcasecmp(v->name, "notifymimetype")) { - strncpy(default_notifymime, v->value, sizeof(default_notifymime) - 1); - } else if (!strcasecmp(v->name, "musicclass")) { - strncpy(global_musicclass, v->value, sizeof(global_musicclass) - 1); - } else if (!strcasecmp(v->name, "language")) { - strncpy(default_language, v->value, sizeof(default_language)-1); - } else if (!strcasecmp(v->name, "regcontext")) { - strncpy(regcontext, v->value, sizeof(regcontext) - 1); - /* Create context if it doesn't exist already */ - if (!ast_context_find(regcontext)) - ast_context_create(NULL, regcontext, type); - } else if (!strcasecmp(v->name, "callerid")) { - strncpy(default_callerid, v->value, sizeof(default_callerid)-1); - } else if (!strcasecmp(v->name, "fromdomain")) { - strncpy(default_fromdomain, v->value, sizeof(default_fromdomain)-1); - } else if (!strcasecmp(v->name, "nat")) { - if (!strcasecmp(v->value, "rfc3581")) - global_nat = SIP_NAT_RFC3581; - else if (!strcasecmp(v->value, "route")) - global_nat = SIP_NAT_ROUTE; - else if (ast_true(v->value)) - global_nat = SIP_NAT_ALWAYS; - else - global_nat = SIP_NAT_NEVER; - } else if (!strcasecmp(v->name, "autocreatepeer")) { - autocreatepeer = ast_true(v->value); - } else if (!strcasecmp(v->name, "srvlookup")) { - srvlookup = ast_true(v->value); - } else if (!strcasecmp(v->name, "trustrpid")) { - global_trustrpid = ast_true(v->value); - } else if (!strcasecmp(v->name, "progressinband")) { - if (!strcasecmp(v->value, "never")) - global_progressinband = 0; - else if (ast_true(v->value)) - global_progressinband = 2; - else - global_progressinband = 1; ->>>>>>> 1.576 #ifdef OSP_SUPPORT } else if (!strcasecmp(v->name, "ospauth")) { if (!strcasecmp(v->value, "exclusive")) { @@ -12120,7 +8577,6 @@ } else global_ospauth = 0; #endif -<<<<<<< chan_sip.c } else if (!strcasecmp(v->name, "pedantic")) { pedanticsipchecking = ast_true(v->value); } else if (!strcasecmp(v->name, "canreinvite")) { @@ -12202,175 +8658,7 @@ */ v = v->next; } -======= - } else if (!strcasecmp(v->name, "pedantic")) { - pedanticsipchecking = ast_true(v->value); - } else if (!strcasecmp(v->name, "canreinvite")) { - if (!strcasecmp(v->value, "update")) - global_canreinvite = REINVITE_UPDATE; - else - global_canreinvite = ast_true(v->value); - } else if (!strcasecmp(v->name, "maxexpirey") || !strcasecmp(v->name, "maxexpiry")) { - max_expiry = atoi(v->value); - if (max_expiry < 1) - max_expiry = DEFAULT_MAX_EXPIRY; - } else if (!strcasecmp(v->name, "defaultexpiry") || !strcasecmp(v->name, "defaultexpirey")) { - default_expiry = atoi(v->value); - if (default_expiry < 1) - default_expiry = DEFAULT_DEFAULT_EXPIRY; - } else if (!strcasecmp(v->name, "bindaddr")) { - if (!(hp = ast_gethostbyname(v->value, &ahp))) { - ast_log(LOG_WARNING, "Invalid address: %s\n", v->value); - } else { - memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr)); - } - } else if (!strcasecmp(v->name, "localnet")) { - struct ast_ha *na; - if (!(na = ast_append_ha("d", v->value, localaddr))) - ast_log(LOG_WARNING, "Invalid localnet value: %s\n", v->value); - else - localaddr = na; - } 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))) - 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) - ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value); - else { - global_capability |= format; - sip_pref_append(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 { - global_capability &= ~format; - sip_pref_remove(format); - } - } else if (!strcasecmp(v->name, "register")) { - sip_register(v->value, v->lineno); - } else if (!strcasecmp(v->name, "recordhistory")) { - recordhistory = ast_true(v->value); - } else if (!strcasecmp(v->name, "tos")) { - if (sscanf(v->value, "%i", &format) == 1) - tos = format & 0xff; - else if (!strcasecmp(v->value, "lowdelay")) - tos = IPTOS_LOWDELAY; - else if (!strcasecmp(v->value, "throughput")) - tos = IPTOS_THROUGHPUT; - else if (!strcasecmp(v->value, "reliability")) - tos = IPTOS_RELIABILITY; - else if (!strcasecmp(v->value, "mincost")) - tos = IPTOS_MINCOST; - else if (!strcasecmp(v->value, "none")) - tos = 0; - else - ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno); - } else if (!strcasecmp(v->name, "port")) { - if (sscanf(v->value, "%i", &ourport) == 1) { - bindaddr.sin_port = htons(ourport); - } else { - ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config); - } - } - /* else if (strcasecmp(v->name,"type")) - * ast_log(LOG_WARNING, "Ignoring %s\n", v->name); - */ - v = v->next; - } - - /* Load peers, users and friends */ - cat = ast_category_browse(cfg, NULL); - while(cat) { - if (strcasecmp(cat, "general")) { - utype = ast_variable_retrieve(cfg, cat, "type"); - if (utype) { - if (!strcasecmp(utype, "user") || !strcasecmp(utype, "friend")) { - user = build_user(cat, ast_variable_browse(cfg, cat)); - if (user) { - ast_mutex_lock(&userl.lock); - user->next = userl.users; - userl.users = user; - ast_mutex_unlock(&userl.lock); - } - } - if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) { - peer = build_peer(cat, ast_variable_browse(cfg, cat), 0); - if (peer) { - ast_mutex_lock(&peerl.lock); - peer->next = peerl.peers; - peerl.peers = peer; - ast_mutex_unlock(&peerl.lock); - } - } else if (strcasecmp(utype, "user")) { - ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf"); - } - } else - ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat); - } - cat = ast_category_browse(cfg, cat); - } - - /* Find our IP address */ - if (ntohl(bindaddr.sin_addr.s_addr)) { - memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip)); - } else { - hp = ast_gethostbyname(ourhost, &ahp); - if (!hp) { - ast_log(LOG_WARNING, "Unable to get IP address for %s, SIP disabled\n", ourhost); - if (!__ourip.s_addr) { - ast_destroy(cfg); - return 0; - } - } else - memcpy(&__ourip, hp->h_addr, sizeof(__ourip)); - } - if (!ntohs(bindaddr.sin_port)) - bindaddr.sin_port = ntohs(DEFAULT_SIP_PORT); - bindaddr.sin_family = AF_INET; - ast_mutex_lock(&netlock); - if ((sipsock > -1) && (ntohs(bindaddr.sin_port) != oldport)) { - close(sipsock); - sipsock = -1; - } - if (sipsock < 0) { - sipsock = socket(AF_INET, SOCK_DGRAM, 0); - if (sipsock < 0) { - ast_log(LOG_WARNING, "Unable to create SIP socket: %s\n", strerror(errno)); - } else { - /* Allow SIP clients on the same host to access us: */ - const int reuseFlag = 1; - setsockopt(sipsock, SOL_SOCKET, SO_REUSEADDR, - (const char*)&reuseFlag, - sizeof reuseFlag); - - if (bind(sipsock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) { - ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n", - ast_inet_ntoa(iabuf, sizeof(iabuf), bindaddr.sin_addr), ntohs(bindaddr.sin_port), - strerror(errno)); - close(sipsock); - sipsock = -1; - } else { - 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))) - ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); - } - } - } - ast_mutex_unlock(&netlock); ->>>>>>> 1.576 -<<<<<<< chan_sip.c cat = ast_category_browse(cfg, NULL); while(cat) { if (strcasecmp(cat, "general")) { @@ -12455,11 +8743,6 @@ ast_destroy(cfg); return 0; -======= - /* Release configuration from memory */ - ast_destroy(cfg); - return 0; ->>>>>>> 1.576 } static struct ast_rtp *sip_get_rtp_peer(struct ast_channel *chan) @@ -12762,7 +9045,6 @@ int unload_module() { -<<<<<<< chan_sip.c struct sip_pvt *p, *pl; /* First, take us out of the channel loop */ @@ -12838,87 +9120,6 @@ ast_mutex_destroy(®l.lock); return 0; -======= - struct sip_pvt *p, *pl; - - /* First, take us out of the channel loop */ - ast_unregister_application(app_dtmfmode); - ast_cli_unregister(&cli_show_users); - ast_cli_unregister(&cli_show_channels); - ast_cli_unregister(&cli_show_channel); - ast_cli_unregister(&cli_show_history); - ast_cli_unregister(&cli_show_peer); - ast_cli_unregister(&cli_show_peers); - ast_cli_unregister(&cli_show_peers_include); - ast_cli_unregister(&cli_show_peers_exclude); - ast_cli_unregister(&cli_show_peers_begin); - ast_cli_unregister(&cli_show_registry); - ast_cli_unregister(&cli_show_subscriptions); - ast_cli_unregister(&cli_debug); - ast_cli_unregister(&cli_debug_ip); - ast_cli_unregister(&cli_debug_peer); - ast_cli_unregister(&cli_no_debug); - ast_cli_unregister(&cli_history); - ast_cli_unregister(&cli_no_history); - ast_cli_unregister(&cli_sip_reload); - ast_cli_unregister(&cli_inuse_show); - ast_rtp_proto_unregister(&sip_rtp); - ast_channel_unregister(type); - if (!ast_mutex_lock(&iflock)) { - /* Hangup all interfaces if they have an owner */ - p = iflist; - while(p) { - if (p->owner) - ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); - p = p->next; - } - iflist = NULL; - ast_mutex_unlock(&iflock); - } else { - ast_log(LOG_WARNING, "Unable to lock the interface list\n"); - return -1; - } - if (!ast_mutex_lock(&monlock)) { - if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) { - pthread_cancel(monitor_thread); - pthread_kill(monitor_thread, SIGURG); - pthread_join(monitor_thread, NULL); - } - monitor_thread = AST_PTHREADT_STOP; - ast_mutex_unlock(&monlock); - } else { - ast_log(LOG_WARNING, "Unable to lock the monitor\n"); - return -1; - } - - if (!ast_mutex_lock(&iflock)) { - /* Destroy all the interfaces and free their memory */ - p = iflist; - while(p) { - pl = p; - p = p->next; - /* Free associated memory */ - ast_mutex_destroy(&pl->lock); - if(pl->vars) { - ast_destroy_realtime(pl->vars); - pl->vars = NULL; - } - free(pl); - } - iflist = NULL; - ast_mutex_unlock(&iflock); - } else { - ast_log(LOG_WARNING, "Unable to lock the interface list\n"); - return -1; - } - /* Free memory for local network address mask */ - ast_free_ha(localaddr); - ast_mutex_destroy(&userl.lock); - ast_mutex_destroy(&peerl.lock); - ast_mutex_destroy(®l.lock); - - return 0; ->>>>>>> 1.576 } int usecount()