Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outgoing calls early callid #135

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/re_fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ int str_bool(bool *val, const char *str);
int str_hex(uint8_t *hex, size_t len, const char *str);
void str_ncpy(char *dst, const char *src, size_t n);
int str_dup(char **dst, const char *src);
int str_x64dup(char **dst, uint64_t val);
int str_cmp(const char *s1, const char *s2);
int str_casecmp(const char *s1, const char *s2);
size_t str_len(const char *s);
Expand Down
1 change: 1 addition & 0 deletions include/re_sip.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ int sip_dialog_fork(struct sip_dialog **dlgp, struct sip_dialog *odlg,
int sip_dialog_update(struct sip_dialog *dlg, const struct sip_msg *msg);
bool sip_dialog_rseq_valid(struct sip_dialog *dlg, const struct sip_msg *msg);
const char *sip_dialog_callid(const struct sip_dialog *dlg);
int sip_dialog_set_callid(struct sip_dialog *dlg, const char *callid);
const char *sip_dialog_uri(const struct sip_dialog *dlg);
uint32_t sip_dialog_lseq(const struct sip_dialog *dlg);
bool sip_dialog_established(const struct sip_dialog *dlg);
Expand Down
1 change: 1 addition & 0 deletions include/re_sipsess.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int sipsess_connect(struct sipsess **sessp, struct sipsess_sock *sock,
const char *routev[], uint32_t routec,
const char *ctype, struct mbuf *desc,
sip_auth_h *authh, void *aarg, bool aref,
const char *callid,
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
26 changes: 26 additions & 0 deletions src/fmt/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <re_mem.h>
#include <re_fmt.h>

enum {
X64_STRSIZE = 17,
};

/**
* Convert a ascii hex string to binary format
Expand Down Expand Up @@ -85,6 +88,29 @@ int str_dup(char **dst, const char *src)
}


/**
* Converts an uint64_t to a 0-terminated string
*
* @param dst Pointer to destination string (set on return)
* @param val Value
*
* @return 0 if success, otherwise errorcode
*/
int str_x64dup(char **dst, uint64_t val)
{
char *str;

str = mem_alloc(X64_STRSIZE, NULL);
if (!str)
return ENOMEM;

(void)re_snprintf(str, X64_STRSIZE, "%016llx", val);

*dst = str;
return 0;
}


/**
* Compare two 0-terminated strings
*
Expand Down
30 changes: 10 additions & 20 deletions src/sip/dialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

enum {
ROUTE_OFFSET = 7,
X64_STRSIZE = 17,
};

struct sip_dialog {
Expand All @@ -45,22 +44,6 @@ struct route_enc {
};


static int x64_strdup(char **strp, uint64_t val)
{
char *str;

str = mem_alloc(X64_STRSIZE, NULL);
if (!str)
return ENOMEM;

(void)re_snprintf(str, X64_STRSIZE, "%016llx", val);

*strp = str;

return 0;
}


static void destructor(void *arg)
{
struct sip_dialog *dlg = arg;
Expand Down Expand Up @@ -113,11 +96,11 @@ int sip_dialog_alloc(struct sip_dialog **dlgp,
if (err)
goto out;

err = x64_strdup(&dlg->callid, rand_u64());
err = str_x64dup(&dlg->callid, rand_u64());
if (err)
goto out;

err = x64_strdup(&dlg->ltag, ltag);
err = str_x64dup(&dlg->ltag, ltag);
if (err)
goto out;

Expand Down Expand Up @@ -225,7 +208,7 @@ int sip_dialog_accept(struct sip_dialog **dlgp, const struct sip_msg *msg)
if (err)
goto out;

err = x64_strdup(&dlg->ltag, msg->tag);
err = str_x64dup(&dlg->ltag, msg->tag);
if (err)
goto out;

Expand Down Expand Up @@ -583,6 +566,13 @@ const char *sip_dialog_callid(const struct sip_dialog *dlg)
}


int sip_dialog_set_callid(struct sip_dialog *dlg, const char *callid)
{
dlg->callid = mem_deref(dlg->callid);
return str_dup(&dlg->callid, callid);
}


/**
* Get the local sequence number from a SIP Dialog
*
Expand Down
7 changes: 7 additions & 0 deletions src/sipsess/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ int sipsess_connect(struct sipsess **sessp, struct sipsess_sock *sock,
const char *routev[], uint32_t routec,
const char *ctype, struct mbuf *desc,
sip_auth_h *authh, void *aarg, bool aref,
const char *callid,
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 @@ -231,6 +232,12 @@ int sipsess_connect(struct sipsess **sessp, struct sipsess_sock *sock,
if (err)
goto out;

if (str_isset(callid))
err = sip_dialog_set_callid(sess->dlg, callid);

if (err)
goto out;

hash_append(sock->ht_sess,
hash_joaat_str(sip_dialog_callid(sess->dlg)),
&sess->he, sess);
Expand Down