All pastes #18921 Raw Edit

Stuff

public cpp v1 · immutable
#18921 ·published 2005-07-31 06:56 UTC
rendered paste body
static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, char *vxml_url){        char invite[256]="";        char from[256];        char to[256];        char tmp[80];        char iabuf[INET_ADDRSTRLEN];        char *l = default_callerid, *n=NULL;        int x;        char urioptions[256]="";        if (ast_test_flag(p, SIP_USEREQPHONE)) {                char onlydigits = 1;                x=0;                /* Test p->username against allowed characters in AST_DIGIT_ANY                If it matches the allowed characters list, then sipuser = ";user=phone"                If not, then sipuser = ""                */                /* + is allowed in first position in a tel: uri */                if (p->username && p->username[0] == '+')                        x=1;                for (; x<strlen(p->username); x++) {                        if (!strchr(AST_DIGIT_ANYNUM, p->username[x])) {                                onlydigits = 0;                                break;                        }                }                /* If we have only digits, add ;user=phone to the uri */                if (onlydigits)                        strcpy(urioptions, ";user=phone");        }        snprintf(p->lastmsg, sizeof(p->lastmsg), "Init: %s", sip_methods[sipmethod].text);        if (p->owner) {                l = p->owner->cid.cid_num;                n = p->owner->cid.cid_name;        }        if (!l || (!ast_isphonenumber(l) && default_callerid[0]))                        l = default_callerid;        /* if user want's his callerid restricted */        if ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {                l = CALLERID_UNKNOWN;                n = l;        }        if (!n || ast_strlen_zero(n))                n = l;        /* Allow user to be overridden */        if (!ast_strlen_zero(p->fromuser))                l = p->fromuser;        else /* Save for any further attempts */                ast_copy_string(p->fromuser, l, sizeof(p->fromuser));        /* Allow user to be overridden */        if (!ast_strlen_zero(p->fromname))                n = p->fromname;        else /* Save for any further attempts */                ast_copy_string(p->fromname, n, sizeof(p->fromname));        if ((ourport != 5060) && ast_strlen_zero(p->fromdomain))        /* Needs to be 5060 */                snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=as%08x", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, ourport, p->tag);        else                snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=as%08x", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, p->tag);        /* If we're calling a registred SIP peer, use the fullcontact to dial to the peer */        if (!ast_strlen_zero(p->fullcontact)) {                /* If we have full contact, trust it */                char *scan, *addr, *port_str, *expiry_str, *username, *contact;                /* try to split this fullcontact into the invite contact */                scan=p->fullcontact; /*ast_copy_string(scan,p->fullcontact,sizeof(scan));*/                addr = strsep(&scan, ":");                port_str = strsep(&scan, ":");                expiry_str = strsep(&scan, ":");                username = strsep(&scan, ":");                contact = scan; /* Contact include sip: and has to be the last part of the database entry as long as we use : as a separator */                ast_log(LOG_DEBUG,"contact is: %s\n",contact);                ast_copy_string(invite,contact,sizeof(contact));                ast_log(LOG_DEBUG,"Our invite is still:%s",invite);                /*ast_copy_string(invite, p->fullcontact, sizeof(invite));*/        /* Otherwise, use the username while waiting for registration */        } else if (!ast_strlen_zero(p->username)) {                if (ntohs(p->sa.sin_port) != 5060) {            /* Needs to be 5060 */                        snprintf(invite, sizeof(invite), "sip:%s@%s:%d%s",p->username, p->tohost, ntohs(p->sa.sin_port), urioptions);                } else {                        snprintf(invite, sizeof(invite), "sip:%s@%s%s",p->username, p->tohost, urioptions);                }        } else if (ntohs(p->sa.sin_port) != 5060) {             /* Needs to be 5060 */                snprintf(invite, sizeof(invite), "sip:%s:%d%s", p->tohost, ntohs(p->sa.sin_port), urioptions);        } else {                snprintf(invite, sizeof(invite), "sip:%s%s", p->tohost, urioptions);        }        ast_copy_string(p->uri, invite, sizeof(p->uri));        /* If there is a VXML URL append it to the SIP URL */        if (vxml_url)        {                snprintf(to, sizeof(to), "<%s>;%s", invite, vxml_url);        } else {                snprintf(to, sizeof(to), "<%s>", invite);        }        memset(req, 0, sizeof(struct sip_request));        ast_log(LOG_DEBUG,"Our invite is still:%s",invite);        init_req(req, sipmethod, invite);        snprintf(tmp, sizeof(tmp), "%d %s", ++p->ocseq, sip_methods[sipmethod].text);        add_header(req, "Via", p->via);        /* SLD: FIXME?: do Route: here too?  I think not cos this is the first request.         * OTOH, then we won't have anything in p->route anyway */        add_header(req, "From", from);        ast_copy_string(p->exten, l, sizeof(p->exten));        build_contact(p);        ast_log(LOG_DEBUG,"ADDING NEW HEADER:%s\n",to);        add_header(req, "To", to);        add_header(req, "Contact", p->our_contact);        add_header(req, "Call-ID", p->callid);        add_header(req, "CSeq", tmp);        add_header(req, "User-Agent", default_useragent);}