Exemplo n.º 1
0
static int w_msrp_reply(struct sip_msg* msg, char* code, char* text,
		char *hdrs)
{
	str rcode;
	str rtext;
	str rhdrs;
	msrp_frame_t *mf;
	int ret;

	if(fixup_get_svalue(msg, (gparam_t*)code, &rcode)!=0)
	{
		LM_ERR("no reply status code\n");
		return -1;
	}

	if(fixup_get_svalue(msg, (gparam_t*)text, &rtext)!=0)
	{
		LM_ERR("no reply status phrase\n");
		return -1;
	}

	if(hdrs!=NULL && fixup_get_svalue(msg, (gparam_t*)hdrs, &rhdrs)!=0)
	{
		LM_ERR("invalid extra headers\n");
		return -1;
	}

	mf = msrp_get_current_frame();
	if(mf==NULL)
		return -1;

	ret = msrp_reply(mf, &rcode, &rtext, (hdrs!=NULL)?&rhdrs:NULL);
	if(ret==0) ret = 1;
	return ret;
}
Exemplo n.º 2
0
static int ki_msrp_reply(sip_msg_t* msg, str* rcode, str* rtext,
		str *rhdrs)
{
	msrp_frame_t *mf;
	int ret;

	mf = msrp_get_current_frame();
	if(mf==NULL)
		return -1;

	ret = msrp_reply(mf, rcode, rtext,
			(rhdrs!=NULL && rhdrs->len>0)?rhdrs:NULL);
	if(ret==0) ret = 1;
	return ret;
}
Exemplo n.º 3
0
int msrp_cmap_save(msrp_frame_t *mf)
{
    unsigned int idx;
    unsigned int hid;
    str fpeer;
#define MSRP_SBUF_SIZE	256
    char sbuf[MSRP_SBUF_SIZE];
    str srcaddr;
    str srcsock;
    int msize;
    int expires;
    msrp_citem_t *it;
    msrp_citem_t *itb;

    if(_msrp_cmap_head==NULL || mf==NULL)
        return -1;
    if(mf->fline.rtypeid!=MSRP_REQ_AUTH)
    {
        LM_DBG("save can be used only for AUTH\n");
        return -2;
    }

    if(msrp_frame_get_expires(mf, &expires)<0)
        expires = msrp_auth_max_expires;
    if(expires<msrp_auth_min_expires)
    {
        LM_DBG("expires is lower than min value\n");
        srcaddr.len = snprintf(sbuf, MSRP_SBUF_SIZE, "Min-Expires: %d\r\n",
                               msrp_auth_min_expires);
        msrp_reply(mf, &msrp_reply_423_code, &msrp_reply_423_text,
                   &srcaddr);
        return -3;
    }
    if(expires>msrp_auth_max_expires)
    {
        LM_DBG("expires is greater than max value\n");
        srcaddr.len = snprintf(sbuf, MSRP_SBUF_SIZE, "Max-Expires: %d\r\n",
                               msrp_auth_max_expires);
        msrp_reply(mf, &msrp_reply_423_code, &msrp_reply_423_text,
                   &srcaddr);
        return -4;
    }
    if(msrp_frame_get_first_from_path(mf, &fpeer)<0)
    {
        LM_ERR("cannot get first path uri\n");
        return -1;
    }

    if(sruid_next(&_msrp_sruid)<0)
    {
        LM_ERR("cannot get next msrp uid\n");
        return -1;
    }
    hid = msrp_get_hashid(&_msrp_sruid.uid);
    idx = msrp_get_slot(hid, _msrp_cmap_head->mapsize);

    srcaddr.s = sbuf;
    if (msrp_tls_module_loaded)
    {
        memcpy(srcaddr.s, "msrps://", 8);
        srcaddr.s+=8;
    } else {
        memcpy(srcaddr.s, "msrp://", 7);
        srcaddr.s+=7;
    }
    strcpy(srcaddr.s, ip_addr2a(&mf->tcpinfo->rcv->src_ip));
    strcat(srcaddr.s, ":");
    strcat(srcaddr.s, int2str(mf->tcpinfo->rcv->src_port, NULL));
    srcaddr.s = sbuf;
    srcaddr.len = strlen(srcaddr.s);
    srcsock = mf->tcpinfo->rcv->bind_address->sock_str;
    LM_DBG("saving connection info for [%.*s] [%.*s] (%u/%u)\n",
           fpeer.len, fpeer.s, _msrp_sruid.uid.len, _msrp_sruid.uid.s,
           idx, hid);
    LM_DBG("frame received from [%.*s] via [%.*s]\n",
           srcaddr.len, srcaddr.s, srcsock.len, srcsock.s);

    msize = sizeof(msrp_citem_t) + (_msrp_sruid.uid.len
                                    + fpeer.len + srcaddr.len + srcsock.len + 4)*sizeof(char);

    /* build the item */
    it = (msrp_citem_t*)shm_malloc(msize);
    if(it==NULL)
    {
        LM_ERR("no more shm\n");
        return -1;
    }
    memset(it, 0, msize);
    it->citemid = hid;

    it->sessionid.s = (char*)it +  + sizeof(msrp_citem_t);
    it->sessionid.len = _msrp_sruid.uid.len;
    memcpy(it->sessionid.s, _msrp_sruid.uid.s, _msrp_sruid.uid.len);
    it->sessionid.s[it->sessionid.len] = '\0';

    it->peer.s = it->sessionid.s + it->sessionid.len + 1;
    it->peer.len = fpeer.len;
    memcpy(it->peer.s, fpeer.s, fpeer.len);
    it->peer.s[it->peer.len] = '\0';

    it->addr.s = it->peer.s + it->peer.len + 1;
    it->addr.len = srcaddr.len;
    memcpy(it->addr.s, srcaddr.s, srcaddr.len);
    it->addr.s[it->addr.len] = '\0';

    it->sock.s = it->addr.s + it->addr.len + 1;
    it->sock.len = srcsock.len;
    memcpy(it->sock.s, srcsock.s, srcsock.len);
    it->sock.s[it->sock.len] = '\0';

    it->expires = time(NULL) + expires;
    it->conid = mf->tcpinfo->con->id;

    /* insert item in cmap */
    lock_get(&_msrp_cmap_head->cslots[idx].lock);
    if(_msrp_cmap_head->cslots[idx].first==NULL) {
        _msrp_cmap_head->cslots[idx].first = it;
    } else {
        for(itb=_msrp_cmap_head->cslots[idx].first; itb; itb=itb->next)
        {
            if(itb->citemid>it->citemid || itb->next==NULL) {
                if(itb->next==NULL) {
                    itb->next=it;
                    it->prev = itb;
                } else {
                    it->next = itb;
                    if(itb->prev==NULL) {
                        _msrp_cmap_head->cslots[idx].first = it;
                    } else {
                        itb->prev->next = it;
                    }
                    it->prev = itb->prev;
                    itb->prev = it;
                }
                break;
            }
        }
    }
    _msrp_cmap_head->cslots[idx].lsize++;
    lock_release(&_msrp_cmap_head->cslots[idx].lock);

    if(mf->tcpinfo->rcv->proto==PROTO_TLS || mf->tcpinfo->rcv->proto==PROTO_WSS)
    {
        srcaddr.len = snprintf(sbuf, MSRP_SBUF_SIZE,
                               "Use-Path: msrps://%.*s/%.*s;tcp\r\nExpires: %d\r\n",
                               (msrp_use_path_addr.s)?msrp_use_path_addr.len:(srcsock.len-4),
                               (msrp_use_path_addr.s)?msrp_use_path_addr.s:(srcsock.s+4),
                               _msrp_sruid.uid.len, _msrp_sruid.uid.s,
                               expires);
    } else {
        srcaddr.len = snprintf(sbuf, MSRP_SBUF_SIZE,
                               "Use-Path: msrp://%.*s/%.*s;tcp\r\nExpires: %d\r\n",
                               (msrp_use_path_addr.s)?msrp_use_path_addr.len:(srcsock.len-4),
                               (msrp_use_path_addr.s)?msrp_use_path_addr.s:(srcsock.s+4),
                               _msrp_sruid.uid.len, _msrp_sruid.uid.s,
                               expires);
    }
    srcaddr.s = sbuf;

    if(msrp_reply(mf, &msrp_reply_200_code, &msrp_reply_200_text,
                  &srcaddr)<0)
        return -5;
    return 0;
}