Module: sip-router Branch: master Commit: ca6b59ee93096fcff4aa7d7798c79b27aa749158 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ca6b59ee...
Author: Marius Bucur marius.bucur@1and1.ro Committer: Marius Bucur marius.bucur@1and1.ro Date: Thu Feb 2 15:25:23 2012 +0200
Added config function send_dmq message which exposes the same functionality as the API function.
---
modules_k/dmq/dmq.c | 9 +++++++-- modules_k/dmq/dmq_funcs.c | 40 ++++++++++++++++++++++++++++++++++++++++ modules_k/dmq/dmq_funcs.h | 1 + modules_k/dmq/peer.c | 3 +++ modules_k/dmq/peer.h | 2 +- 5 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/modules_k/dmq/dmq.c b/modules_k/dmq/dmq.c index 7a62302..62fa6e6 100644 --- a/modules_k/dmq/dmq.c +++ b/modules_k/dmq/dmq.c @@ -93,11 +93,14 @@ static int mod_init(void); static int child_init(int); static void destroy(void); static int handle_dmq_fixup(void** param, int param_no); +static int send_dmq_fixup(void** param, int param_no); static int parse_server_address(str* uri, struct sip_uri* parsed_uri);
static cmd_export_t cmds[] = { {"handle_dmq_message", (cmd_function)handle_dmq_message, 0, handle_dmq_fixup, 0, REQUEST_ROUTE}, + {"send_dmq_message", (cmd_function)cfg_send_dmq_message, 3, send_dmq_fixup, 0, + ANY_ROUTE}, {"bind_dmq", (cmd_function)bind_dmq, 0, 0, 0, REQUEST_ROUTE}, {0, 0, 0, 0, 0, 0} @@ -262,14 +265,16 @@ static int handle_dmq_fixup(void** param, int param_no) { return 0; }
+static int send_dmq_fixup(void** param, int param_no) { + return fixup_spve_null(param, 1); +} + static int parse_server_address(str* uri, struct sip_uri* parsed_uri) { if(!uri->s) { - LM_ERR("server address missing\n"); goto empty; } uri->len = strlen(uri->s); if(!uri->len) { - LM_ERR("empty server address\n"); goto empty; } if(parse_uri(uri->s, uri->len, parsed_uri) < 0) { diff --git a/modules_k/dmq/dmq_funcs.c b/modules_k/dmq/dmq_funcs.c index a71da87..988563a 100644 --- a/modules_k/dmq/dmq_funcs.c +++ b/modules_k/dmq/dmq_funcs.c @@ -149,6 +149,46 @@ error: return -1; }
+int cfg_send_dmq_message(struct sip_msg* msg, char* peer, char* to, char* body) { + str peer_str; + get_str_fparam(&peer_str, msg, (fparam_t*)peer); + str to_str; + get_str_fparam(&to_str, msg, (fparam_t*)to); + str body_str; + get_str_fparam(&body_str, msg, (fparam_t*)body); + LM_INFO("cfg_send_dmq_message: %.*s - %.*s - %.*s\n", + peer_str.len, peer_str.s, + to_str.len, to_str.s, + body_str.len, body_str.s); + + dmq_peer_t* destination_peer = find_peer(peer_str); + if(!destination_peer) { + LM_INFO("cannot find peer %.*s\n", peer_str.len, peer_str.s); + dmq_peer_t new_peer; + new_peer.callback = empty_peer_callback; + new_peer.description.s = ""; + new_peer.description.len = 0; + new_peer.peer_id = peer_str; + destination_peer = register_dmq_peer(&new_peer); + if(!destination_peer) { + LM_ERR("error in register_dmq_peer\n"); + goto error; + } + } + dmq_node_t* to_dmq_node = find_dmq_node_uri(node_list, &to_str); + if(!to_dmq_node) { + LM_ERR("cannot find dmq_node: %.*s\n", to_str.len, to_str.s); + goto error; + } + if(send_dmq_message(destination_peer, &body_str, to_dmq_node, ¬ification_callback, 1) < 0) { + LM_ERR("cannot send dmq message\n"); + goto error; + } + return 0; +error: + return -1; +} + /* pings the servers in the nodelist * if the server does not reply to the ping, it is removed from the list * the ping messages are actualy notification requests diff --git a/modules_k/dmq/dmq_funcs.h b/modules_k/dmq/dmq_funcs.h index 1c6dd91..7381da6 100644 --- a/modules_k/dmq/dmq_funcs.h +++ b/modules_k/dmq/dmq_funcs.h @@ -21,6 +21,7 @@ typedef struct dmq_cback_param { dmq_node_t* node; } dmq_cback_param_t;
+int cfg_send_dmq_message(struct sip_msg* msg, char* peer, char* to, char* body); dmq_peer_t* register_dmq_peer(dmq_peer_t* peer); int send_dmq_message(dmq_peer_t* peer, str* body, dmq_node_t* node, dmq_resp_cback_t* resp_cback, int max_forwards); int bcast_dmq_message(dmq_peer_t* peer, str* body, dmq_node_t* except, dmq_resp_cback_t* resp_cback, int max_forwards); diff --git a/modules_k/dmq/peer.c b/modules_k/dmq/peer.c index 588445f..84dfc1c 100644 --- a/modules_k/dmq/peer.c +++ b/modules_k/dmq/peer.c @@ -43,3 +43,6 @@ dmq_peer_t* find_peer(str peer_id) { return search_peer_list(peer_list, &foo_peer); }
+int empty_peer_callback(struct sip_msg* msg, peer_reponse_t* resp) { + return 0; +} \ No newline at end of file diff --git a/modules_k/dmq/peer.h b/modules_k/dmq/peer.h index b2ec9a2..5ccb980 100644 --- a/modules_k/dmq/peer.h +++ b/modules_k/dmq/peer.h @@ -39,7 +39,7 @@ typedef dmq_peer_t* (*register_dmq_peer_t)(dmq_peer_t*);
dmq_peer_t* add_peer(dmq_peer_list_t* peer_list, dmq_peer_t* peer); dmq_peer_t* find_peer(str peer_id); - +int empty_peer_callback(struct sip_msg* msg, peer_reponse_t* resp);
#endif
Hi Marius,
On 2/2/12 2:26 PM, Marius Ovidiu Bucur wrote:
Module: sip-router Branch: master Commit: ca6b59ee93096fcff4aa7d7798c79b27aa749158 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ca6b59ee...
Author: Marius Bucurmarius.bucur@1and1.ro Committer: Marius Bucurmarius.bucur@1and1.ro Date: Thu Feb 2 15:25:23 2012 +0200
Added config function send_dmq message which exposes the same functionality as the API function.
thanks for addition.
I was thinking it may make sense to rename the dmq module config functions to start with dmq_* instead of having dmq somewhere in the middle -- just to suggest kind of namespace. It is a suggestion, followed by many of the old or recent modules, to have a module specific prefix -- up to you at the end of the day...
Cheers, Daniel