Browse code

dmq: Let the handler know about the sending node

Try to find a node based on the from uri of the incoming request and hand
it to the request handler.

Alex Hermann authored on 13/11/2014 19:54:26 • Charles Chance committed on 13/11/2014 21:57:34
Showing 7 changed files
... ...
@@ -187,7 +187,7 @@ int run_init_callbacks() {
187 187
 /**
188 188
  * @brief dmq notification callback
189 189
  */
190
-int dmq_notification_callback(struct sip_msg* msg, peer_reponse_t* resp)
190
+int dmq_notification_callback(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq_node)
191 191
 {
192 192
 	int nodes_recv;
193 193
 	str* response_body = NULL;
... ...
@@ -37,7 +37,7 @@ extern str notification_content_type;
37 37
 extern int *dmq_init_callback_done;
38 38
 
39 39
 int add_notification_peer();
40
-int dmq_notification_callback(struct sip_msg* msg, peer_reponse_t* resp);
40
+int dmq_notification_callback(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq_node);
41 41
 int extract_node_list(dmq_node_list_t* update_list, struct sip_msg* msg);
42 42
 str* build_notification_body();
43 43
 int build_node_str(dmq_node_t* node, char* buf, int buflen);
... ...
@@ -97,7 +97,7 @@ dmq_peer_t* find_peer(str peer_id)
97 97
 /**
98 98
  * @empty callback
99 99
  */
100
-int empty_peer_callback(struct sip_msg* msg, peer_reponse_t* resp)
100
+int empty_peer_callback(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq_node)
101 101
 {
102 102
 	return 0;
103 103
 }
... ...
@@ -28,6 +28,7 @@
28 28
 
29 29
 #include <string.h>
30 30
 #include <stdlib.h>
31
+#include "dmqnode.h"
31 32
 #include "../../lock_ops.h"
32 33
 #include "../../str.h"
33 34
 #include "../../mem/mem.h"
... ...
@@ -41,7 +42,7 @@ typedef struct peer_response {
41 42
 	str body;
42 43
 } peer_reponse_t;
43 44
 
44
-typedef int(*peer_callback_t)(struct sip_msg*, peer_reponse_t* resp);
45
+typedef int(*peer_callback_t)(struct sip_msg*, peer_reponse_t* resp, dmq_node_t* node);
45 46
 typedef int(*init_callback_t)();
46 47
 
47 48
 typedef struct dmq_peer {
... ...
@@ -66,7 +67,7 @@ typedef dmq_peer_t* (*register_dmq_peer_t)(dmq_peer_t*);
66 67
 
67 68
 dmq_peer_t* add_peer(dmq_peer_list_t* peer_list, dmq_peer_t* peer);
68 69
 dmq_peer_t* find_peer(str peer_id);
69
-int empty_peer_callback(struct sip_msg* msg, peer_reponse_t* resp);
70
+int empty_peer_callback(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq_node);
70 71
 
71 72
 #endif
72 73
 
... ...
@@ -29,6 +29,8 @@
29 29
 #include "../../data_lump_rpl.h"
30 30
 #include "../../mod_fix.h"
31 31
 #include "../../sip_msg_clone.h"
32
+#include "../../parser/parse_from.h"
33
+#include "../../parser/parse_to.h"
32 34
 
33 35
 /**
34 36
  * @brief set the body of a response
... ...
@@ -74,6 +76,7 @@ void worker_loop(int id)
74 76
 	dmq_job_t* current_job;
75 77
 	peer_reponse_t peer_response;
76 78
 	int ret_value;
79
+	dmq_node_t *dmq_node = NULL;
77 80
 
78 81
 	worker = &workers[id];
79 82
 	for(;;) {
... ...
@@ -88,7 +91,14 @@ void worker_loop(int id)
88 91
 			current_job = job_queue_pop(worker->queue);
89 92
 			/* job_queue_pop might return NULL if queue is empty */
90 93
 			if(current_job) {
91
-				ret_value = current_job->f(current_job->msg, &peer_response);
94
+				/* extract the from uri */
95
+				if (parse_from_header(current_job->msg) < 0) {
96
+					LM_ERR("bad sip message or missing From hdr\n");
97
+				} else {
98
+					dmq_node = find_dmq_node_uri(node_list, &((struct to_body*)current_job->msg->from->parsed)->uri);
99
+				}
100
+
101
+				ret_value = current_job->f(current_job->msg, &peer_response, dmq_node);
92 102
 				if(ret_value < 0) {
93 103
 					LM_ERR("running job failed\n");
94 104
 					continue;
... ...
@@ -89,7 +89,7 @@ int ht_dmq_broadcast(str* body) {
89 89
 /**
90 90
  * @brief ht dmq callback
91 91
  */
92
-int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp)
92
+int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq_node)
93 93
 {
94 94
 	int content_length;
95 95
 	str body;
... ...
@@ -40,7 +40,7 @@ typedef enum {
40 40
 } ht_dmq_action_t;
41 41
 
42 42
 int ht_dmq_initialize();
43
-int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp);
43
+int ht_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp, dmq_node_t* dmq_node);
44 44
 int ht_dmq_replicate_action(ht_dmq_action_t action, str* htname, str* cname, int type, int_str* val, int mode);
45 45
 int ht_dmq_replay_action(ht_dmq_action_t action, str* htname, str* cname, int type, int_str* val, int mode);
46 46
 int ht_dmq_resp_callback_f(struct sip_msg* msg, int code, dmq_node_t* node, void* param);