Module: sip-router
Branch: mariusbucur/dmq
Commit: 34ae039f6949affb42a005ef8f39313c30eca75b
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=34ae039…
Author: Marius Bucur <marius(a)marius-bucur.ro>
Committer: Marius Bucur <marius(a)marius-bucur.ro>
Date: Fri May 6 09:55:31 2011 +0300
changed build_node_str so that parameters are added to the sip uri
---
modules_k/dmq/dmq.c | 5 ++++
modules_k/dmq/dmq_funcs.c | 1 +
modules_k/dmq/dmqnode.c | 47 +++++++++++++++++++++++++++++++++++++
modules_k/dmq/dmqnode.h | 3 ++
modules_k/dmq/notification_peer.c | 9 -------
5 files changed, 56 insertions(+), 9 deletions(-)
diff --git a/modules_k/dmq/dmq.c b/modules_k/dmq/dmq.c
index 9dbf52c..c8fbff9 100644
--- a/modules_k/dmq/dmq.c
+++ b/modules_k/dmq/dmq.c
@@ -251,6 +251,11 @@ static int child_init(int rank) {
*/
static void destroy(void) {
/* TODO unregister dmq node, free resources */
+ if(dmq_notification_address.s) {
+ LM_DBG("unregistering node %.*s\n", STR_FMT(&self_node->orig_uri));
+ self_node->status = DMQ_NODE_DISABLED;
+ request_nodelist(notification_node, 1);
+ }
}
static int handle_dmq_fixup(void** param, int param_no) {
diff --git a/modules_k/dmq/dmq_funcs.c b/modules_k/dmq/dmq_funcs.c
index b0164db..8a97c99 100644
--- a/modules_k/dmq/dmq_funcs.c
+++ b/modules_k/dmq/dmq_funcs.c
@@ -80,6 +80,7 @@ int bcast_dmq_message(dmq_peer_t* peer, str* body, dmq_node_t* except,
dmq_resp_
* - any inactive nodes
*/
if((except && cmp_dmq_node(node, except)) || node->local || node->status
!= DMQ_NODE_ACTIVE) {
+ LM_DBG("skipping node %.*s\n", STR_FMT(&node->orig_uri));
node = node->next;
continue;
}
diff --git a/modules_k/dmq/dmqnode.c b/modules_k/dmq/dmqnode.c
index 6465e01..25334bc 100644
--- a/modules_k/dmq/dmqnode.c
+++ b/modules_k/dmq/dmqnode.c
@@ -12,6 +12,23 @@ str dmq_node_active_str = str_init("active");
str dmq_node_disabled_str = str_init("disabled");
str dmq_node_timeout_str = str_init("timeout");
+str* get_status_str(int status) {
+ switch(status) {
+ case DMQ_NODE_ACTIVE: {
+ return &dmq_node_active_str;
+ }
+ case DMQ_NODE_DISABLED: {
+ return &dmq_node_disabled_str;
+ }
+ case DMQ_NODE_TIMEOUT: {
+ return &dmq_node_timeout_str;
+ }
+ default: {
+ return 0;
+ }
+ }
+}
+
dmq_node_list_t* init_dmq_node_list() {
dmq_node_list_t* node_list = shm_malloc(sizeof(dmq_node_list_t));
memset(node_list, 0, sizeof(dmq_node_list_t));
@@ -63,6 +80,11 @@ error:
return -1;
}
+inline int set_default_dmq_node_params(dmq_node_t* node) {
+ node->status = DMQ_NODE_ACTIVE;
+ return 0;
+}
+
inline dmq_node_t* build_dmq_node(str* uri, int shm) {
dmq_node_t* ret;
param_hooks_t hooks;
@@ -79,6 +101,7 @@ inline dmq_node_t* build_dmq_node(str* uri, int shm) {
memset(ret, 0, sizeof(*ret));
pkg_str_dup(&ret->orig_uri, uri);
}
+ set_default_dmq_node_params(ret);
if(parse_uri(ret->orig_uri.s, ret->orig_uri.len, &ret->uri) < 0) {
LM_ERR("error parsing uri\n");
goto error;
@@ -198,4 +221,28 @@ inline dmq_node_t* add_dmq_node(dmq_node_list_t* list, str* uri) {
return newnode;
error:
return NULL;
+}
+
+int build_node_str(dmq_node_t* node, char* buf, int buflen) {
+ /* sip:host:port;status=[status] */
+ int len = 0;
+ if(buflen < node->orig_uri.len + 32) {
+ LM_ERR("no more space left for node string\n");
+ return -1;
+ }
+ memcpy(buf + len, "sip:", 4);
+ len += 4;
+ memcpy(buf + len, node->uri.host.s, node->uri.host.len);
+ len += node->uri.host.len;
+ memcpy(buf + len, ":", 1);
+ len += 1;
+ memcpy(buf + len, node->uri.port.s, node->uri.port.len);
+ len += node->uri.port.len;
+ memcpy(buf + len, ";", 1);
+ len += 1;
+ memcpy(buf + len, "status=", 7);
+ len += 7;
+ memcpy(buf + len, get_status_str(node->status)->s,
get_status_str(node->status)->len);
+ len += get_status_str(node->status)->len;
+ return len;
}
\ No newline at end of file
diff --git a/modules_k/dmq/dmqnode.h b/modules_k/dmq/dmqnode.h
index c16d534..3bd69b0 100644
--- a/modules_k/dmq/dmqnode.h
+++ b/modules_k/dmq/dmqnode.h
@@ -47,6 +47,9 @@ void shm_free_node(dmq_node_t* node);
void pkg_free_node(dmq_node_t* node);
int set_dmq_node_params(dmq_node_t* node, param_t* params);
+str* get_status_str(int status);
+int build_node_str(dmq_node_t* node, char* buf, int buflen);
+
extern dmq_node_t* self_node;
extern dmq_node_t* notification_node;
diff --git a/modules_k/dmq/notification_peer.c b/modules_k/dmq/notification_peer.c
index c8c261c..f06693a 100644
--- a/modules_k/dmq/notification_peer.c
+++ b/modules_k/dmq/notification_peer.c
@@ -153,15 +153,6 @@ error:
return -1;
}
-int build_node_str(dmq_node_t* node, char* buf, int buflen) {
- if(buflen < node->orig_uri.len) {
- LM_ERR("no more space left for node string\n");
- return -1;
- }
- memcpy(buf, node->orig_uri.s, node->orig_uri.len);
- return node->orig_uri.len;
-}
-
/**
* builds the body of a notification message from the list of servers
* the result will look something like: