Skip to content

Commit

Permalink
sipsess: add a function pointer for the content description
Browse files Browse the repository at this point in the history
This allows the application to postpone the encoding of the content description
(e.g. the SDP) until the source address of the SIP transport is known.

sipsess_connect() uses this for the INVITE. Other SIP session types do not set
the new function pointer.
  • Loading branch information
cspiel1 committed Oct 22, 2021
1 parent 2b34587 commit 43a050c
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 23 deletions.
5 changes: 4 additions & 1 deletion include/re_sipsess.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ struct sipsess;


typedef void (sipsess_conn_h)(const struct sip_msg *msg, void *arg);
typedef int (sipsess_desc_h)(struct mbuf **descp, const struct sa *src,
const struct sa *dst, void *arg);
typedef int (sipsess_offer_h)(struct mbuf **descp, const struct sip_msg *msg,
void *arg);
typedef int (sipsess_answer_h)(const struct sip_msg *msg, void *arg);
Expand All @@ -30,9 +32,10 @@ int sipsess_connect(struct sipsess **sessp, struct sipsess_sock *sock,
const char *to_uri, const char *from_name,
const char *from_uri, const char *cuser,
const char *routev[], uint32_t routec,
const char *ctype, struct mbuf *desc,
const char *ctype,
sip_auth_h *authh, void *aarg, bool aref,
const char *callid,
sipsess_desc_h *desch,
sipsess_offer_h *offerh, sipsess_answer_h *answerh,
sipsess_progr_h *progrh, sipsess_estab_h *estabh,
sipsess_info_h *infoh, sipsess_refer_h *referh,
Expand Down
4 changes: 3 additions & 1 deletion src/sipevent/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)


static int send_handler(enum sip_transp tp, const struct sa *src,
const struct sa *dst, struct mbuf *mb, void *arg)
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
struct sip_contact contact;
struct sipnot *not = arg;
(void)dst;
(void)contp;

sip_contact_set(&contact, not->cuser, src, tp);

Expand Down
4 changes: 3 additions & 1 deletion src/sipevent/subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,13 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)


static int send_handler(enum sip_transp tp, const struct sa *src,
const struct sa *dst, struct mbuf *mb, void *arg)
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
struct sip_contact contact;
struct sipsub *sub = arg;
(void)dst;
(void)contp;

sip_contact_set(&contact, sub->cuser, src, tp);

Expand Down
4 changes: 3 additions & 1 deletion src/sipreg/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,14 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)


static int send_handler(enum sip_transp tp, const struct sa *src,
const struct sa *dst, struct mbuf *mb, void *arg)
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
struct sipreg *reg = arg;
int err;

(void)dst;
(void)contp;

reg->laddr = *src;
reg->tp = tp;
Expand Down
2 changes: 1 addition & 1 deletion src/sipsess/accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int sipsess_accept(struct sipsess **sessp, struct sipsess_sock *sock,
return EINVAL;

err = sipsess_alloc(&sess, sock, cuser, ctype, NULL, authh, aarg, aref,
offerh, answerh, NULL, estabh, infoh, referh,
NULL, offerh, answerh, NULL, estabh, infoh, referh,
closeh, arg);
if (err)
return err;
Expand Down
4 changes: 3 additions & 1 deletion src/sipsess/ack.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ static void tmr_handler(void *arg)


static int send_handler(enum sip_transp tp, const struct sa *src,
const struct sa *dst, struct mbuf *mb, void *arg)
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
struct sipsess_ack *ack = arg;
(void)src;
(void)contp;

mem_deref(ack->mb);
ack->mb = mem_ref(mb);
Expand Down
63 changes: 47 additions & 16 deletions src/sipsess/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,53 @@ static int invite(struct sipsess *sess);


static int send_handler(enum sip_transp tp, const struct sa *src,
const struct sa *dst, struct mbuf *mb, void *arg)
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
struct sip_contact contact;
struct sipsess *sess = arg;
(void)dst;
struct mbuf *desc = NULL;
struct mbuf *cont = NULL;
int err;

if (sess->desch) {
err = sess->desch(&desc, src, dst, sess->arg);
if (err)
return err;
}

sip_contact_set(&contact, sess->cuser, src, tp);
err = mbuf_printf(mb, "%H", sip_contact_print, &contact);
if (err)
goto out;

return mbuf_printf(mb, "%H", sip_contact_print, &contact);
cont = mbuf_alloc(1024);
if (!cont) {
err = ENOMEM;
goto out;
}

err |= mbuf_printf(cont,
"%s%s%s"
"Content-Length: %zu\r\n"
"\r\n"
"%b",
desc ? "Content-Type: " : "",
desc ? sess->ctype : "",
desc ? "\r\n" : "",
mbuf_get_left(desc),
mbuf_buf(desc),
mbuf_get_left(desc));
cont->pos = 0;

if (err)
mem_deref(cont);
else
*contp = cont;

out:
mem_deref(desc);
return err;
}


Expand Down Expand Up @@ -138,19 +176,10 @@ static int invite(struct sipsess *sess)
return sip_drequestf(&sess->req, sess->sip, true, "INVITE",
sess->dlg, 0, sess->auth,
send_handler, invite_resp_handler, sess,
"%b"
"%s%s%s"
"Content-Length: %zu\r\n"
"\r\n"
"%b",
sess->hdrs ? mbuf_buf(sess->hdrs) : NULL,
sess->hdrs ? mbuf_get_left(sess->hdrs) :(size_t)0,
sess->desc ? "Content-Type: " : "",
sess->desc ? sess->ctype : "",
sess->desc ? "\r\n" : "",
sess->desc ? mbuf_get_left(sess->desc) :(size_t)0,
sess->desc ? mbuf_buf(sess->desc) : NULL,
sess->desc ? mbuf_get_left(sess->desc):(size_t)0);
sess->hdrs ? mbuf_get_left(sess->hdrs) :(size_t)0
);
}


Expand Down Expand Up @@ -186,9 +215,10 @@ int sipsess_connect(struct sipsess **sessp, struct sipsess_sock *sock,
const char *to_uri, const char *from_name,
const char *from_uri, const char *cuser,
const char *routev[], uint32_t routec,
const char *ctype, struct mbuf *desc,
const char *ctype,
sip_auth_h *authh, void *aarg, bool aref,
const char *callid,
sipsess_desc_h *desch,
sipsess_offer_h *offerh, sipsess_answer_h *answerh,
sipsess_progr_h *progrh, sipsess_estab_h *estabh,
sipsess_info_h *infoh, sipsess_refer_h *referh,
Expand All @@ -200,7 +230,8 @@ int sipsess_connect(struct sipsess **sessp, struct sipsess_sock *sock,
if (!sessp || !sock || !to_uri || !from_uri || !cuser || !ctype)
return EINVAL;

err = sipsess_alloc(&sess, sock, cuser, ctype, desc, authh, aarg, aref,
err = sipsess_alloc(&sess, sock, cuser, ctype, NULL, authh, aarg, aref,
desch,
offerh, answerh, progrh, estabh, infoh, referh,
closeh, arg);
if (err)
Expand Down
4 changes: 3 additions & 1 deletion src/sipsess/modify.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ static void reinvite_resp_handler(int err, const struct sip_msg *msg,


static int send_handler(enum sip_transp tp, const struct sa *src,
const struct sa *dst, struct mbuf *mb, void *arg)
const struct sa *dst, struct mbuf *mb,
struct mbuf **contp, void *arg)
{
struct sip_contact contact;
struct sipsess *sess = arg;
(void)dst;
(void)contp;

sip_contact_set(&contact, sess->cuser, src, tp);

Expand Down
2 changes: 2 additions & 0 deletions src/sipsess/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ static void destructor(void *arg)
int sipsess_alloc(struct sipsess **sessp, struct sipsess_sock *sock,
const char *cuser, const char *ctype, struct mbuf *desc,
sip_auth_h *authh, void *aarg, bool aref,
sipsess_desc_h *desch,
sipsess_offer_h *offerh, sipsess_answer_h *answerh,
sipsess_progr_h *progrh, sipsess_estab_h *estabh,
sipsess_info_h *infoh, sipsess_refer_h *referh,
Expand Down Expand Up @@ -184,6 +185,7 @@ int sipsess_alloc(struct sipsess **sessp, struct sipsess_sock *sock,
sess->sock = mem_ref(sock);
sess->desc = mem_ref(desc);
sess->sip = mem_ref(sock->sip);
sess->desch = desch;
sess->offerh = offerh ? offerh : internal_offer_handler;
sess->answerh = answerh ? answerh : internal_answer_handler;
sess->progrh = progrh ? progrh : internal_progress_handler;
Expand Down
2 changes: 2 additions & 0 deletions src/sipsess/sipsess.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct sipsess {
char *close_hdrs;
struct mbuf *hdrs;
struct mbuf *desc;
sipsess_desc_h *desch;
sipsess_offer_h *offerh;
sipsess_answer_h *answerh;
sipsess_progr_h *progrh;
Expand Down Expand Up @@ -68,6 +69,7 @@ struct sipsess_request {
int sipsess_alloc(struct sipsess **sessp, struct sipsess_sock *sock,
const char *cuser, const char *ctype, struct mbuf *desc,
sip_auth_h *authh, void *aarg, bool aref,
sipsess_desc_h *desch,
sipsess_offer_h *offerh, sipsess_answer_h *answerh,
sipsess_progr_h *progrh, sipsess_estab_h *estabh,
sipsess_info_h *infoh, sipsess_refer_h *referh,
Expand Down

0 comments on commit 43a050c

Please sign in to comment.