Browse code

presence_dialoginfo: handle all states to get most relevant xml

- patch from FS#341

(cherry picked from commit f845465eb96770e0c02c92ae862cdc94f561e29e)

Daniel-Constantin Mierla authored on 06/01/2014 23:58:20
Showing 1 changed files
... ...
@@ -32,6 +32,12 @@
32 32
  */
33 33
 
34 34
 #define MAX_INT_LEN 11 /* 2^32: 10 chars + 1 char sign */
35
+#define DEF_TRYING_NODE 1
36
+#define DEF_PROCEEDING_NODE 2
37
+#define DEF_EARLY_NODE 4
38
+#define DEF_CONFIRMED_NODE 8
39
+#define DEF_TERMINATED_NODE 16
40
+
35 41
 
36 42
 #include <string.h>
37 43
 #include <stdlib.h>
... ...
@@ -103,6 +109,9 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
103 103
 	xmlNodePtr terminated_node = NULL;
104 104
 	xmlNodePtr early_node = NULL;
105 105
 	xmlNodePtr confirmed_node = NULL;
106
+	xmlNodePtr proceed_node = NULL;
107
+	xmlNodePtr trying_node = NULL;
108
+
106 109
 
107 110
 	char *state = NULL;
108 111
 	xmlChar *dialog_id = NULL;
... ...
@@ -236,39 +245,61 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
236 236
 							LM_DBG("state element content = %s\n", state);
237 237
 							if (strcasecmp(state,"terminated") == 0)
238 238
 							{
239
+								LM_DBG("found terminated state\n" );
239 240
 								terminated_node = node;
240 241
 							} else if (strcasecmp(state,"confirmed") == 0 && node_id == i) {
241 242
 								/*  here we check if confirmed is terminated or not
242 243
 								 *  if it is not we are in the middle of the conversation
243 244
 								 */
244
-								if(check_relevant_state(dialog_id, xml_array, j) > 1)
245
+								if(check_relevant_state(dialog_id, xml_array, j) >= DEF_TERMINATED_NODE)
245 246
 								{
246
-									LM_DBG("confirmed state for dialog %s, but it was terminated\n", dialog_id );
247
+									LM_DBG("confirmed state for dialog %s, but it is not latest state\n", dialog_id );
247 248
 								}else{
248
-									LM_DBG("confirmed state for dialog %s, and it is not terminated\n", dialog_id );
249
+									LM_DBG("confirmed state for dialog %s and latest state for this dialog\n", dialog_id );
249 250
 									confirmed_node = node;
250 251
 								}
251 252
 
252 253
 
253 254
 							} else if (strcasecmp(state,"early") == 0 && node_id == i) {
254
-								if(check_relevant_state(dialog_id, xml_array, j)  > 0)
255
+								if(check_relevant_state(dialog_id, xml_array, j)  >= DEF_CONFIRMED_NODE)
255 256
 								{
256
-									LM_DBG("early state for dialog %s, but it was confirmed or terminated\n", dialog_id );
257
+									LM_DBG("early state for dialog %s, but it is not latest state\n", dialog_id );
257 258
 								}else{
258
-									LM_DBG("early state for dialog %s and it is still relevant\n", dialog_id );
259
+									LM_DBG("early state for dialog %s and latest state for this dialog\n", dialog_id );
259 260
 									early_node = node;
260 261
 								}
262
+							} else if (strcasecmp(state,"proceeding") == 0 && node_id == i) {
263
+								if(check_relevant_state(dialog_id, xml_array, j)  >= DEF_EARLY_NODE)
264
+								{
265
+									LM_DBG("proceeding state for dialog %s, but it is not latest state\n", dialog_id );
266
+								}else{
267
+									LM_DBG("proceeding state for dialog %s and latest state for this dialog\n", dialog_id );
268
+									proceed_node = node;
269
+								}
270
+							} else if (strcasecmp(state,"trying") == 0 && node_id == i) {
271
+								if(check_relevant_state(dialog_id, xml_array, j)  >= DEF_PROCEEDING_NODE)
272
+								{
273
+									LM_DBG("trying state for dialog %s, but it is not latest state\n", dialog_id );
274
+								}else{
275
+									LM_DBG("trying state for dialog %s and latest state for this dialog\n", dialog_id );
276
+									trying_node = node;
277
+								}
261 278
 							}
262 279
 							if(early_node != NULL) {
263 280
 								winner_dialog_node = early_node;
264
-							} else {
265
-								if(confirmed_node != NULL)
266
-								{
281
+							} else if(confirmed_node != NULL) {
267 282
 									winner_dialog_node = confirmed_node;
268
-								}else {
283
+							} else if(proceed_node != NULL) {
284
+									winner_dialog_node = proceed_node;
285
+							} else if(trying_node != NULL) {
286
+									winner_dialog_node = trying_node;
287
+							} else if(terminated_node != NULL) {
269 288
 									winner_dialog_node = terminated_node;
270
-								}
289
+							} else {
290
+								/* assume a failure somewhere and all above nodes are NULL */
291
+								winner_dialog_node = node;
271 292
 							}
293
+							/*
272 294
 							if(winner_dialog_node == NULL) {
273 295
 								priority = get_dialog_state_priority(state);
274 296
 								if (priority > winner_priority) {
... ...
@@ -277,6 +308,7 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
277 277
 									winner_dialog_node = node;
278 278
 								}
279 279
 							}
280
+							*/
280 281
 							xmlFree(state);
281 282
 						}
282 283
 					}
... ...
@@ -336,7 +368,7 @@ error:
336 336
 	return NULL;
337 337
 }
338 338
 
339
-
339
+/*
340 340
 int get_dialog_state_priority(char *state) {
341 341
 	if (strcasecmp(state,"terminated") == 0)
342 342
 		return 0;
... ...
@@ -351,8 +383,9 @@ int get_dialog_state_priority(char *state) {
351 351
 
352 352
 	return 0;
353 353
 }
354
+*/
354 355
 
355
-/* returns 2 -> terminated, 1 -> confirmed, 3 -> both */
356
+/* returns 16 -> terminated, 8 -> confirmed, 4 -> early */
356 357
 int check_relevant_state (xmlChar * dialog_id, xmlDocPtr * xml_array, int total_nodes)
357 358
 {
358 359
 	int result = 0;
... ...
@@ -391,7 +424,7 @@ int check_relevant_state (xmlChar * dialog_id, xmlDocPtr * xml_array, int total_
391 391
 							{
392 392
 								LM_DBG ("Found terminated in dialog %s\n",
393 393
 										dialog_id);
394
-								result += 2;
394
+								result += DEF_TERMINATED_NODE;
395 395
 							}
396 396
 							/* check if state is confirmed for this dialog. */
397 397
 							if ((strcasecmp (state, "confirmed") == 0)
... ...
@@ -399,8 +432,30 @@ int check_relevant_state (xmlChar * dialog_id, xmlDocPtr * xml_array, int total_
399 399
 									&& (strcasecmp ((char*)dialog_id_tmp, (char*)dialog_id) == 0))
400 400
 							{
401 401
 								LM_DBG ("Found confirmed in dialog %s\n", dialog_id);
402
-								result += 1;
402
+								result += DEF_CONFIRMED_NODE;
403 403
 							}
404
+							if ((strcasecmp (state, "early") == 0)
405
+									&& (node_id == i) && (node_id >= 0)
406
+									&& (strcasecmp ((char*)dialog_id_tmp, (char*)dialog_id) == 0))
407
+							{
408
+								LM_DBG ("Found early in dialog %s\n", dialog_id);
409
+								result += DEF_EARLY_NODE;
410
+							}
411
+							if ((strcasecmp (state, "proceeding") == 0)
412
+									&& (node_id == i) && (node_id >= 0)
413
+									&& (strcasecmp ((char*)dialog_id_tmp, (char*)dialog_id) == 0))
414
+							{
415
+								LM_DBG ("Found proceeding in dialog %s\n", dialog_id);
416
+								result += DEF_PROCEEDING_NODE;
417
+							}
418
+							if ((strcasecmp (state, "trying") == 0)
419
+									&& (node_id == i) && (node_id >= 0)
420
+									&& (strcasecmp ((char*)dialog_id_tmp, (char*)dialog_id) == 0))
421
+							{
422
+								LM_DBG ("Found trying in dialog %s\n", dialog_id);
423
+								result += DEF_TRYING_NODE;
424
+							}
425
+
404 426
 
405 427
 							xmlFree (state);
406 428
 						}