Browse code

dmq: Set send_socket to the correct address

Documentation says the server_address is the address used to send messages
from. Make the code actually do this.

UDP is hardcoded for now because DMQ doesn't work with other protocols (yet).

Alex Hermann authored on 17/07/2014 11:02:12
Showing 3 changed files
... ...
@@ -60,6 +60,7 @@ int pid = 0;
60 60
 /* module parameters */
61 61
 int num_workers = DEFAULT_NUM_WORKERS;
62 62
 str dmq_server_address = {0, 0};
63
+str dmq_server_socket = {0, 0};
63 64
 struct sip_uri dmq_server_uri;
64 65
 
65 66
 str dmq_notification_address = {0, 0};
... ...
@@ -127,6 +128,36 @@ struct module_exports exports = {
127 127
 	child_init                  	/* per-child init function */
128 128
 };
129 129
 
130
+
131
+static int make_socket_str_from_uri(struct sip_uri *uri, str *socket) {
132
+	if(!uri->host.s || !uri->host.len) {
133
+		LM_ERR("no host in uri\n");
134
+		return -1;
135
+	}
136
+
137
+	socket->len = uri->host.len + uri->port.len + 6;
138
+	socket->s = pkg_malloc(socket->len);
139
+	if(socket->s==NULL) {
140
+		LM_ERR("no more pkg\n");
141
+		return -1;
142
+	}
143
+	memcpy(socket->s, "udp:", 4);
144
+	socket->len = 4;
145
+
146
+	memcpy(socket->s + socket->len, uri->host.s, uri->host.len);
147
+	socket->len += uri->host.len;
148
+
149
+	if(uri->port.s && uri->port.len) {
150
+		socket->s[socket->len++] = ':';
151
+		memcpy(socket->s + socket->len, uri->port.s, uri->port.len);
152
+		socket->len += uri->port.len;
153
+	}
154
+	socket->s[socket->len] = '\0';
155
+
156
+	return 0;
157
+}
158
+
159
+
130 160
 /**
131 161
  * init module function
132 162
  */
... ...
@@ -178,6 +209,12 @@ static int mod_init(void)
178 178
 		return -1;
179 179
 	}
180 180
 
181
+	/* create socket string out of the server_uri */
182
+	if(make_socket_str_from_uri(&dmq_server_uri, &dmq_server_socket) < 0) {
183
+		LM_ERR("failed to create socket out of server_uri\n");
184
+		return -1;
185
+	}
186
+
181 187
 	/* allocate workers array */
182 188
 	workers = shm_malloc(num_workers * sizeof(*workers));
183 189
 	if(workers == NULL) {
... ...
@@ -268,6 +305,9 @@ static void destroy(void) {
268 268
 		self_node->status = DMQ_NODE_DISABLED;
269 269
 		request_nodelist(notification_node, 1);
270 270
 	}
271
+	if (dmq_server_socket.s) {
272
+		pkg_free(dmq_server_socket.s);
273
+	}
271 274
 }
272 275
 
273 276
 static int handle_dmq_fixup(void** param, int param_no)
... ...
@@ -44,6 +44,7 @@ extern dmq_peer_t* dmq_notification_peer;
44 44
 extern str dmq_server_address;
45 45
 extern dmq_peer_list_t* peer_list;
46 46
 extern str dmq_request_method;
47
+extern str dmq_server_socket;
47 48
 extern struct sip_uri dmq_server_uri;
48 49
 extern str dmq_notification_address;
49 50
 extern struct sip_uri dmq_notification_uri;
... ...
@@ -202,6 +202,8 @@ int dmq_send_message(dmq_peer_t* peer, str* body, dmq_node_t* node,
202 202
 	
203 203
 	set_uac_req(&uac_r, &dmq_request_method, &str_hdr, body, NULL,
204 204
 			TMCB_LOCAL_COMPLETED, dmq_tm_callback, (void*)cb_param);
205
+	uac_r.ssock = &dmq_server_socket;
206
+
205 207
 	result = tmb.t_request(&uac_r, &to,
206 208
 			       &to, &from,
207 209
 			       NULL);