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

dispatcher: add attrs param to rpc 'add' call #2336

Merged
merged 1 commit into from May 28, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/modules/dispatcher/dispatch.c
Expand Up @@ -2419,15 +2419,16 @@ void ds_add_dest_cb(ds_set_t *node, int i, void *arg)
}

/* add dispatcher entry to in-memory dispatcher list */
int ds_add_dst(int group, str *address, int flags)
int ds_add_dst(int group, str *address, int flags, str *attrs)
{
int setn, priority;
str attrs;

setn = _ds_list_nr;
priority = 0;
attrs.s = 0;
attrs.len = 0;

if (attrs->len == 0) {
attrs->s = 0;
}

*next_idx = (*crt_idx + 1) % 2;
ds_avl_destroy(&ds_lists[*next_idx]);
Expand All @@ -2436,7 +2437,7 @@ int ds_add_dst(int group, str *address, int flags)
ds_iter_set(_ds_list, &ds_add_dest_cb, NULL);

// add new destination
if(add_dest2list(group, *address, flags, priority, &attrs,
if(add_dest2list(group, *address, flags, priority, attrs,
*next_idx, &setn) != 0) {
LM_WARN("unable to add destination %.*s to set %d", address->len, address->s, group);
if(ds_load_mode==1) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/dispatcher/dispatch.h
Expand Up @@ -140,7 +140,7 @@ int ds_select_dst_limit(sip_msg_t *msg, int set, int alg, uint32_t limit,
int mode);
int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode);
int ds_update_dst(struct sip_msg *msg, int upos, int mode);
int ds_add_dst(int group, str *address, int flags);
int ds_add_dst(int group, str *address, int flags, str *attrs);
int ds_remove_dst(int group, str *address);
int ds_update_state(sip_msg_t *msg, int group, str *address, int state,
ds_rctx_t *rctx);
Expand Down
5 changes: 3 additions & 2 deletions src/modules/dispatcher/dispatcher.c
Expand Up @@ -1800,15 +1800,16 @@ static void dispatcher_rpc_add(rpc_t *rpc, void *ctx)
{
int group, flags;
str dest;
str attrs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix also the indentation here, since the S needs to be added below.


flags = 0;

if(rpc->scan(ctx, "dS*d", &group, &dest, &flags) < 2) {
if(rpc->scan(ctx, "dS*d", &group, &dest, &flags, &attrs) < 3) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here is missing and extra S in scan's 2nd parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above condition needs some update. Because attrs is optional, then it is still fine to go on with return code 2 (which represents the number of items/params scanned).

Probably return code has to be stored in a variable, e.g., then if ret<2 is error, if ret==2 then attrs.s=NULL and attrs.len=0 (or attrs=STR_NULL when declared).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'm going to fix.

rpc->fault(ctx, 500, "Invalid Parameters");
return;
}

if(ds_add_dst(group, &dest, flags) != 0) {
if(ds_add_dst(group, &dest, flags, &attrs) != 0) {
rpc->fault(ctx, 500, "Adding dispatcher dst failed");
return;
}
Expand Down
6 changes: 5 additions & 1 deletion src/modules/dispatcher/doc/dispatcher_admin.xml
Expand Up @@ -1938,15 +1938,19 @@ DEST: {
<listitem><para>_flags_ (optional): as described in the list file format,
default 0</para></listitem>

<listitem><para>_attrs_ (optional): as described in the list file format,
default ""</para></listitem>

</itemizedlist>
<para>
Example:
</para>
<programlisting format="linespecific">
...
# prototype: &sercmd; dispatcher.add _group_ _address_ _flags_
# prototype: &sercmd; dispatcher.add _group_ _address_ _flags_ _attrs_
&sercmd; dispatcher.add 2 sip:127.0.0.1:5080
&sercmd; dispatcher.add 3 sip:127.0.0.1:5075 8
&sercmd; dispatcher.add 3 sip:127.0.0.1:5075 0 duid=abc;socket=udp:127.0.0.1:5060
...
</programlisting>
</section>
Expand Down