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 109
 	xmlNodePtr terminated_node = NULL;
104 110
 	xmlNodePtr early_node = NULL;
105 111
 	xmlNodePtr confirmed_node = NULL;
112
+	xmlNodePtr proceed_node = NULL;
113
+	xmlNodePtr trying_node = NULL;
114
+
106 115
 
107 116
 	char *state = NULL;
108 117
 	xmlChar *dialog_id = NULL;
... ...
@@ -236,39 +245,61 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
236 245
 							LM_DBG("state element content = %s\n", state);
237 246
 							if (strcasecmp(state,"terminated") == 0)
238 247
 							{
248
+								LM_DBG("found terminated state\n" );
239 249
 								terminated_node = node;
240 250
 							} else if (strcasecmp(state,"confirmed") == 0 && node_id == i) {
241 251
 								/*  here we check if confirmed is terminated or not
242 252
 								 *  if it is not we are in the middle of the conversation
243 253
 								 */
244
-								if(check_relevant_state(dialog_id, xml_array, j) > 1)
254
+								if(check_relevant_state(dialog_id, xml_array, j) >= DEF_TERMINATED_NODE)
245 255
 								{
246
-									LM_DBG("confirmed state for dialog %s, but it was terminated\n", dialog_id );
256
+									LM_DBG("confirmed state for dialog %s, but it is not latest state\n", dialog_id );
247 257
 								}else{
248
-									LM_DBG("confirmed state for dialog %s, and it is not terminated\n", dialog_id );
258
+									LM_DBG("confirmed state for dialog %s and latest state for this dialog\n", dialog_id );
249 259
 									confirmed_node = node;
250 260
 								}
251 261
 
252 262
 
253 263
 							} else if (strcasecmp(state,"early") == 0 && node_id == i) {
254
-								if(check_relevant_state(dialog_id, xml_array, j)  > 0)
264
+								if(check_relevant_state(dialog_id, xml_array, j)  >= DEF_CONFIRMED_NODE)
255 265
 								{
256
-									LM_DBG("early state for dialog %s, but it was confirmed or terminated\n", dialog_id );
266
+									LM_DBG("early state for dialog %s, but it is not latest state\n", dialog_id );
257 267
 								}else{
258
-									LM_DBG("early state for dialog %s and it is still relevant\n", dialog_id );
268
+									LM_DBG("early state for dialog %s and latest state for this dialog\n", dialog_id );
259 269
 									early_node = node;
260 270
 								}
271
+							} else if (strcasecmp(state,"proceeding") == 0 && node_id == i) {
272
+								if(check_relevant_state(dialog_id, xml_array, j)  >= DEF_EARLY_NODE)
273
+								{
274
+									LM_DBG("proceeding state for dialog %s, but it is not latest state\n", dialog_id );
275
+								}else{
276
+									LM_DBG("proceeding state for dialog %s and latest state for this dialog\n", dialog_id );
277
+									proceed_node = node;
278
+								}
279
+							} else if (strcasecmp(state,"trying") == 0 && node_id == i) {
280
+								if(check_relevant_state(dialog_id, xml_array, j)  >= DEF_PROCEEDING_NODE)
281
+								{
282
+									LM_DBG("trying state for dialog %s, but it is not latest state\n", dialog_id );
283
+								}else{
284
+									LM_DBG("trying state for dialog %s and latest state for this dialog\n", dialog_id );
285
+									trying_node = node;
286
+								}
261 287
 							}
262 288
 							if(early_node != NULL) {
263 289
 								winner_dialog_node = early_node;
264
-							} else {
265
-								if(confirmed_node != NULL)
266
-								{
290
+							} else if(confirmed_node != NULL) {
267 291
 									winner_dialog_node = confirmed_node;
268
-								}else {
292
+							} else if(proceed_node != NULL) {
293
+									winner_dialog_node = proceed_node;
294
+							} else if(trying_node != NULL) {
295
+									winner_dialog_node = trying_node;
296
+							} else if(terminated_node != NULL) {
269 297
 									winner_dialog_node = terminated_node;
270
-								}
298
+							} else {
299
+								/* assume a failure somewhere and all above nodes are NULL */
300
+								winner_dialog_node = node;
271 301
 							}
302
+							/*
272 303
 							if(winner_dialog_node == NULL) {
273 304
 								priority = get_dialog_state_priority(state);
274 305
 								if (priority > winner_priority) {
... ...
@@ -277,6 +308,7 @@ str* agregate_xmls(str* pres_user, str* pres_domain, str** body_array, int n)
277 308
 									winner_dialog_node = node;
278 309
 								}
279 310
 							}
311
+							*/
280 312
 							xmlFree(state);
281 313
 						}
282 314
 					}
... ...
@@ -336,7 +368,7 @@ error:
336 368
 	return NULL;
337 369
 }
338 370
 
339
-
371
+/*
340 372
 int get_dialog_state_priority(char *state) {
341 373
 	if (strcasecmp(state,"terminated") == 0)
342 374
 		return 0;
... ...
@@ -351,8 +383,9 @@ int get_dialog_state_priority(char *state) {
351 383
 
352 384
 	return 0;
353 385
 }
386
+*/
354 387
 
355
-/* returns 2 -> terminated, 1 -> confirmed, 3 -> both */
388
+/* returns 16 -> terminated, 8 -> confirmed, 4 -> early */
356 389
 int check_relevant_state (xmlChar * dialog_id, xmlDocPtr * xml_array, int total_nodes)
357 390
 {
358 391
 	int result = 0;
... ...
@@ -391,7 +424,7 @@ int check_relevant_state (xmlChar * dialog_id, xmlDocPtr * xml_array, int total_
391 424
 							{
392 425
 								LM_DBG ("Found terminated in dialog %s\n",
393 426
 										dialog_id);
394
-								result += 2;
427
+								result += DEF_TERMINATED_NODE;
395 428
 							}
396 429
 							/* check if state is confirmed for this dialog. */
397 430
 							if ((strcasecmp (state, "confirmed") == 0)
... ...
@@ -399,8 +432,30 @@ int check_relevant_state (xmlChar * dialog_id, xmlDocPtr * xml_array, int total_
399 432
 									&& (strcasecmp ((char*)dialog_id_tmp, (char*)dialog_id) == 0))
400 433
 							{
401 434
 								LM_DBG ("Found confirmed in dialog %s\n", dialog_id);
402
-								result += 1;
435
+								result += DEF_CONFIRMED_NODE;
403 436
 							}
437
+							if ((strcasecmp (state, "early") == 0)
438
+									&& (node_id == i) && (node_id >= 0)
439
+									&& (strcasecmp ((char*)dialog_id_tmp, (char*)dialog_id) == 0))
440
+							{
441
+								LM_DBG ("Found early in dialog %s\n", dialog_id);
442
+								result += DEF_EARLY_NODE;
443
+							}
444
+							if ((strcasecmp (state, "proceeding") == 0)
445
+									&& (node_id == i) && (node_id >= 0)
446
+									&& (strcasecmp ((char*)dialog_id_tmp, (char*)dialog_id) == 0))
447
+							{
448
+								LM_DBG ("Found proceeding in dialog %s\n", dialog_id);
449
+								result += DEF_PROCEEDING_NODE;
450
+							}
451
+							if ((strcasecmp (state, "trying") == 0)
452
+									&& (node_id == i) && (node_id >= 0)
453
+									&& (strcasecmp ((char*)dialog_id_tmp, (char*)dialog_id) == 0))
454
+							{
455
+								LM_DBG ("Found trying in dialog %s\n", dialog_id);
456
+								result += DEF_TRYING_NODE;
457
+							}
458
+
404 459
 
405 460
 							xmlFree (state);
406 461
 						}