Skip to content

Commit

Permalink
[proto_msrp] added msrp_fwd_reply() to API
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-iancu committed Mar 15, 2022
1 parent e19ed6e commit 5abdbde
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 13 deletions.
3 changes: 2 additions & 1 deletion modules/proto_msrp/msrp_api.h
Expand Up @@ -39,7 +39,8 @@ typedef int (*send_reply_f)( void *hdl, struct msrp_msg *req,
typedef int (*fwd_request_f)( void *hdl, struct msrp_msg *req,
str *hdrs, int hdrs_no);

typedef int (*fwd_reply_f)( void *hdl, struct msrp_msg *rpl);
typedef int (*fwd_reply_f)( void *hdl, struct msrp_msg *rpl,
struct msrp_cell *cell);


struct msrp_binds {
Expand Down
92 changes: 81 additions & 11 deletions modules/proto_msrp/msrp_signaling.c
Expand Up @@ -89,7 +89,7 @@ int msrp_send_reply( void *hdl, struct msrp_msg *req, int code, str* reason,
*/
len += MSRP_PREFIX_LEN + req->fl.ident.len + 1 + 3
+ (reason?(1 + reason->len):0) + CRLF_LEN;

/* headers
* headers = To-Path CRLF From-Path CRLF 1*( header CRLF )
*/
Expand Down Expand Up @@ -393,16 +393,17 @@ int msrp_fwd_request( void *hdl, struct msrp_msg *req, str *hdrs, int hdrs_no)
}


int msrp_fwd_reply( void *hdl, struct msrp_msg *rpl)
int msrp_fwd_reply( void *hdl, struct msrp_msg *rpl, struct msrp_cell *cell)
{
char *buf, *p;
char *buf, *p, *s;
struct msrp_url *to, *from;
int i, len;

if (rpl==NULL)
if (rpl==NULL || cell==NULL)
return -1;

/* we need both TO and FROM path hdrs to be parsed, none are
* parsed for sure at this point */
/* we need both TO and FROM path hdrs to be parsed. The TO should be
* already, so let's do the FROM */
if (rpl->from_path->parsed == NULL) {
rpl->from_path->parsed = parse_msrp_path( &rpl->from_path->body);
if (rpl->from_path->parsed == NULL) {
Expand All @@ -421,13 +422,72 @@ int msrp_fwd_reply( void *hdl, struct msrp_msg *rpl)
return -1;
}

/* WIP - we need the transactional support
*/
p = NULL; buf = p; p = buf;
to = from;
/* the len will be the same after moving the URL, the only diff will
* be imposed by the diff in ident len (twice!) */
len = rpl->len + 2 * (cell->recv_ident.len - rpl->fl.ident.len);


return -1;
/* allocate the buffer */
buf = pkg_malloc( len );
if (buf==NULL) {
LM_ERR("failed to pkg allocate the request buffer\n");
return -3;
}


/* start building */
p = buf;
s = rpl->buf;

/* copy everything up to the ident, which needs to be replaced here */
append_string( p, s, (int)(rpl->fl.ident.s-s));
/* put back the ident received in the request */
append_string( p, cell->recv_ident.s, cell->recv_ident.len);
/* TO is the first hdr, so copy everything up to its first URL (which
* needs to be skipped here) */
s = rpl->fl.ident.s + rpl->fl.ident.len;
append_string( p, s, (int)(to->whole.s-s));
/* copy starting with the second URL, all the way to the first FROM URL */
s = to->next->whole.s;
append_string( p, s, (int)(from->whole.s-s));
/* first place here the first TO URL that was skipped */
append_string( p, to->whole.s, to->whole.len);
*(p++) = ' ';
/* copy starting with the first FROM URL */
s = from->whole.s;
append_string( p, s,
(int)(rpl->buf+rpl->len-s-rpl->fl.ident.len-CRLF_LEN-1));
/* put back the received ident */
append_string( p, cell->recv_ident.s, cell->recv_ident.len);
s = rpl->buf+rpl->len-CRLF_LEN-1;
append_string( p, s, CRLF_LEN+1 );

if (p-buf!=len) {
LM_BUG("computed %d, but wrote %d :(\n",len,(int)(p-buf));
goto error;
}
#ifdef MSRP_DEBUG
LM_DBG("----|\n%.*s|-----\n",len,buf);
#endif


/* now, send it out, back to the same spot where the request came from */
i = msg_send( cell->recv.send_sock, PROTO_MSRP, &cell->recv.to,
cell->recv.proto_reserved1 /*conn-id*/,
buf, len, NULL);
if (i<0) {
/* sending failed, TODO - close the connection */
LM_ERR("failed to fwd MSRP request\n");
goto error;
}


pkg_free(buf);
return 0;

error:
pkg_free(buf);
return -3;
}


Expand Down Expand Up @@ -579,6 +639,7 @@ static struct msrp_cell* _build_transaction(struct msrp_msg *req, int hash,

cell = shm_malloc( sizeof(struct msrp_cell)
+ ident->len
+ req->fl.ident.len
+ req->from_path->body.len
+ to->whole.len
+ (req->message_id?req->message_id->body.len:0)
Expand All @@ -598,6 +659,10 @@ static struct msrp_cell* _build_transaction(struct msrp_msg *req, int hash,
cell->ident.len = ident->len;
append_string( p, ident->s, ident->len);

cell->recv_ident.s = p;
cell->recv_ident.len = req->fl.ident.len;
append_string( p, req->fl.ident.s, req->fl.ident.len);

cell->from_full.s = p;
cell->from_full.len = req->from_path->body.len;
append_string( p, req->from_path->body.s, req->from_path->body.len);
Expand Down Expand Up @@ -625,6 +690,11 @@ static struct msrp_cell* _build_transaction(struct msrp_msg *req, int hash,
req->failure_report->body.len);
}

init_su( &cell->recv.to, &req->rcv.src_ip, req->rcv.src_port);
cell->recv.proto = req->rcv.proto;
cell->recv.proto_reserved1 = req->rcv.proto_reserved1;
cell->recv.send_sock = req->rcv.bind_address;

return cell;
}

Expand Down
9 changes: 8 additions & 1 deletion modules/proto_msrp/msrp_signaling.h
Expand Up @@ -29,8 +29,15 @@

struct msrp_cell {
unsigned short hash;
/* the computed ident for sending the request on this transaction */
str ident;
/* info on where the request was recv'ed from */
struct dest_info recv;
/* the received/inbound ident for the request */
str recv_ident;
/* FROM PATH as received in the request */
str from_full;
/* TO PATH (only first URL) as received in the request */
str to_top;
str message_id;
str byte_range;
Expand Down Expand Up @@ -60,6 +67,6 @@ int msrp_send_reply( void *hdl, struct msrp_msg *req, int code, str* reason,
int msrp_fwd_request( void *hdl, struct msrp_msg *req,
str *hdrs, int hdrs_no);

int msrp_fwd_reply( void *hdl, struct msrp_msg *rpl);
int msrp_fwd_reply( void *hdl, struct msrp_msg *rpl, struct msrp_cell *cell);

#endif

0 comments on commit 5abdbde

Please sign in to comment.