static int w_msrp_set_dst(sip_msg_t* msg, char* taddr, char* fsock) { str rtaddr = {0}; str rfsock = {0}; msrp_frame_t *mf; int ret; if(fixup_get_svalue(msg, (gparam_t*)taddr, &rtaddr)!=0) { LM_ERR("invalid target address parameter\n"); return -1; } if(fixup_get_svalue(msg, (gparam_t*)fsock, &rfsock)!=0) { LM_ERR("invalid local socket parameter\n"); return -1; } mf = msrp_get_current_frame(); if(mf==NULL) return -1; ret = msrp_env_set_dstinfo(mf, &rtaddr, &rfsock, 0); if(ret==0) ret = 1; return ret; }
static int ki_msrp_set_dst(sip_msg_t* msg, str* rtaddr, str* rfsock) { msrp_frame_t *mf; int ret; mf = msrp_get_current_frame(); if(mf==NULL) return -1; ret = msrp_env_set_dstinfo(mf, rtaddr, rfsock, 0); if(ret==0) ret = 1; return ret; }
int msrp_cmap_lookup(msrp_frame_t *mf) { unsigned int idx; unsigned int hid; str sesid; msrp_citem_t *itb; int ret; if(_msrp_cmap_head==NULL || mf==NULL) return -1; if(mf->fline.rtypeid==MSRP_REQ_AUTH) { LM_DBG("save cannot be used for AUTH\n"); return -2; } if(msrp_frame_get_sessionid(mf, &sesid)<0) { LM_ERR("cannot get session id\n"); return -3; } LM_DBG("searching for session [%.*s]\n", sesid.len, sesid.s); hid = msrp_get_hashid(&sesid); idx = msrp_get_slot(hid, _msrp_cmap_head->mapsize); ret = 0; lock_get(&_msrp_cmap_head->cslots[idx].lock); for(itb=_msrp_cmap_head->cslots[idx].first; itb; itb=itb->next) { if(itb->citemid>hid) { break; } else { if(itb->sessionid.len == sesid.len && memcmp(itb->sessionid.s, sesid.s, sesid.len)==0) { LM_DBG("found session [%.*s]\n", sesid.len, sesid.s); ret = msrp_env_set_dstinfo(mf, &itb->addr, &itb->sock, 0); break; } } } lock_release(&_msrp_cmap_head->cslots[idx].lock); if(itb==NULL) return -4; return (ret<0)?-5:0; }
int msrp_relay(msrp_frame_t *mf) { struct dest_info *dst; struct tcp_connection *con = NULL; char reqbuf[MSRP_MAX_FRAME_SIZE]; msrp_hdr_t *tpath; msrp_hdr_t *fpath; msrp_env_t *env; str_array_t *sar; char *p; char *l; int port; if(mf->buf.len>=MSRP_MAX_FRAME_SIZE-1) return -1; tpath = msrp_get_hdr_by_id(mf, MSRP_HDR_TO_PATH); if(tpath==NULL) { LM_ERR("To-Path header not found\n"); return -1; } fpath = msrp_get_hdr_by_id(mf, MSRP_HDR_FROM_PATH); if(fpath==NULL) { LM_ERR("From-Path header not found\n"); return -1; } l = q_memchr(tpath->body.s, ' ', tpath->body.len); if(l==NULL) { LM_DBG("To-Path has only one URI -- nowehere to forward\n"); return -1; } p = reqbuf; memcpy(p, mf->buf.s, tpath->body.s - mf->buf.s); p += tpath->body.s - mf->buf.s; memcpy(p, l + 1, fpath->body.s - l - 1); p += fpath->body.s - l - 1; memcpy(p, tpath->body.s, l + 1 - tpath->body.s); p += l + 1 - tpath->body.s; memcpy(p, fpath->name.s + 11, mf->buf.s + mf->buf.len - fpath->name.s - 11); p += mf->buf.s + mf->buf.len - fpath->name.s - 11; env = msrp_get_env(); if(env->envflags&MSRP_ENV_DSTINFO) { dst = &env->dstinfo; goto done; } if(msrp_parse_hdr_to_path(mf)<0) { LM_ERR("error parsing To-Path header\n"); return -1; } sar = (str_array_t*)tpath->parsed.data; if(sar==NULL || sar->size<2) { LM_DBG("To-Path has no next hop URI -- nowehere to forward\n"); return -1; } if(msrp_env_set_dstinfo(mf, &sar->list[1], NULL, 0)<0) { LM_ERR("unable to set destination address\n"); return -1; } dst = &env->dstinfo; done: if (dst->send_flags.f & SND_F_FORCE_CON_REUSE) { port = su_getport(&dst->to); if (likely(port)) { ticks_t con_lifetime; struct ip_addr ip; con_lifetime = cfg_get(tcp, tcp_cfg, con_lifetime); su2ip_addr(&ip, &dst->to); con = tcpconn_get(dst->id, &ip, port, NULL, con_lifetime); } else if (likely(dst->id)) { con = tcpconn_get(dst->id, 0, 0, 0, 0); } if (con == NULL) { LM_WARN("TCP/TLS connection not found\n"); return -1; } if (unlikely((con->rcv.proto == PROTO_WS || con->rcv.proto == PROTO_WSS) && sr_event_enabled(SREV_TCP_WS_FRAME_OUT))) { ws_event_info_t wsev; memset(&wsev, 0, sizeof(ws_event_info_t)); wsev.type = SREV_TCP_WS_FRAME_OUT; wsev.buf = reqbuf; wsev.len = p - reqbuf; wsev.id = con->id; return sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev); } else if (tcp_send(dst, 0, reqbuf, p - reqbuf) < 0) { LM_ERR("forwarding frame failed\n"); return -1; } } else if (tcp_send(dst, 0, reqbuf, p - reqbuf) < 0) { LM_ERR("forwarding frame failed\n"); return -1; } return 0; }