Browse code

XJAB module - new presence status code: terminated -- used when the connection with Jabber server is closed - code cleaning

Daniel-Constantin Mierla authored on 09/05/2003 11:23:40
Showing 6 changed files
... ...
@@ -592,41 +592,13 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
592 592
 		goto error;
593 593
 	}
594 594
 	
595
-	/** skip 'sip:' in destination address */
596
-	if(dst.s[0]=='s' && dst.s[1]=='i' && dst.s[2]=='p')
597
-	{
598
-		dst.s += 3;
599
-		dst.len -= 3;
600
-		fl = 1;
601
-		while(*dst.s == ' ' || *dst.s == '\t' || *dst.s == ':')
602
-		{
603
-			dst.s++;
604
-			dst.len--;
605
-			fl = 0;
606
-		}
607
-		if(fl)
608
-		{
609
-			dst.s -= 3;
610
-			dst.len += 3;
611
-		}
612
-#ifdef XJ_EXTRA_DEBUG
613
-		DBG("XJAB:xjab_manage_sipmsg: DESTINATION corrected [%.*s].\n", 
614
-				dst.len, dst.s);
615
-#endif
616
-	}
617
-	// check for parameters
618
-	pc = dst.s;
619
-	while(pc < dst.s + dst.len && *pc!=';')
620
-		pc++;
621
-	if(pc < dst.s+dst.len)
622
-	{
623
-		dst.len = pc - dst.s;
595
+	/** skip 'sip:' and parameters in destination address */
596
+	_XJ_ADJUST_SIPADDR(dst.s,dst.len,pc, fl);
624 597
 #ifdef XJ_EXTRA_DEBUG
625
-		DBG("XJAB:xjab_manage_sipmsg: DESTINATION corrected again [%.*s].\n", 
598
+	DBG("XJAB:xjab_manage_sipmsg: DESTINATION after correction [%.*s].\n",
626 599
 				dst.len, dst.s);
627 600
 #endif
628
-	}
629
-
601
+	
630 602
 prepare_job:
631 603
 	//putting the SIP message parts in share memory to be accessible by workers
632 604
     jsmsg = (xj_sipmsg)shm_malloc(sizeof(t_xj_sipmsg));
... ...
@@ -741,8 +713,8 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
741 713
 {
742 714
 	xj_sipmsg jsmsg = NULL;
743 715
 	t_xj_jkey jkey, *jp;
744
-	int pipe, fl;
745
-
716
+	int pipe, fl, f;
717
+	char *p, *p0;
746 718
 	if(!to || !from || !cbf)
747 719
 		return;
748 720
 
... ...
@@ -768,7 +740,16 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
768 740
 	jsmsg->msg.len = 0;
769 741
 	jsmsg->msg.s = NULL;
770 742
 	
771
-	jsmsg->to.len = to->len;
743
+	p = to->s;
744
+	fl = to->len;
745
+	/** skip 'sip:' and parameters in destination address */
746
+	_XJ_ADJUST_SIPADDR(p, fl, p0, f);
747
+#ifdef XJ_EXTRA_DEBUG
748
+	DBG("XJAB:xj_register_watcher: DESTINATION after correction [%.*s].\n",
749
+				fl, p);
750
+#endif
751
+
752
+	jsmsg->to.len = fl;
772 753
 	if((jsmsg->to.s = (char*)shm_malloc(jsmsg->to.len+1)) == NULL)
773 754
 	{
774 755
 		if(jsmsg->msg.s)
... ...
@@ -776,7 +757,7 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
776 757
 		shm_free(jsmsg);
777 758
 		goto error;
778 759
 	}
779
-	strncpy(jsmsg->to.s, to->s, jsmsg->to.len);
760
+	strncpy(jsmsg->to.s, p, jsmsg->to.len);
780 761
 
781 762
 	jsmsg->jkey = jp;
782 763
 	jsmsg->type = XJ_REG_WATCHER;
... ...
@@ -26,6 +26,14 @@
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 27
  */ 
28 28
 
29
+/***
30
+ * ---
31
+ *
32
+ * History
33
+ * -------
34
+ * 2003-05-09  added macro for ajusting a SIP address, (dcm)
35
+ */
36
+
29 37
 
30 38
 #ifndef _XJAB_BASE_H_
31 39
 #define _XJAB_BASE_H_
... ...
@@ -44,6 +52,30 @@
44 52
 #define XJ_FLAG_OPEN		0
45 53
 #define XJ_FLAG_CLOSE		1
46 54
 
55
+/** skip 'sip:' and parameters in a SIP address */
56
+#define _XJ_ADJUST_SIPADDR(_s, _l, _p, _f) \
57
+	if((_s)[0]=='s' && (_s)[1]=='i' && (_s)[2]=='p') \
58
+	{ \
59
+		(_s) += 3; \
60
+		(_l) -= 3; \
61
+		(_f) = 1; \
62
+		while(*(_s)==' ' || *(_s)=='\t' || *(_s)==':') \
63
+		{ \
64
+			(_s)++; \
65
+			(_l)--; \
66
+			(_f)=0; \
67
+		} \
68
+		if((_f)) \
69
+		{ \
70
+			(_s) -= 3; \
71
+			(_l) += 3; \
72
+		} \
73
+	} \
74
+	(_p) = (_s); \
75
+	while((_p)<(_s)+(_l) && *(_p)!=';' && *(_p)!=' ') \
76
+		(_p)++; \
77
+	if((_p) < (_s)+(_l)) \
78
+		(_l) = (_p) - (_s);
47 79
 
48 80
 typedef void (*pa_callback_f)(str* _user, int _state, void *p);
49 81
 
... ...
@@ -275,7 +275,7 @@ int xj_jcon_user_auth(xj_jcon jbc, char *username, char *passwd,
275 275
 		//sprintf(msg_buff, "%s%s", jbc->stream_id, passwd);
276 276
 		strcpy(msg_buff, jbc->stream_id);
277 277
 		strcat(msg_buff, passwd);
278
-		DBG("XJAB:xj_jcon_user_auth: [%s:%s]\n", jbc->stream_id, passwd);
278
+		//DBG("XJAB:xj_jcon_user_auth: [%s:%s]\n", jbc->stream_id, passwd);
279 279
 		p1 = shahash(msg_buff);
280 280
 
281 281
 		z = xode_insert_tag(y, "digest");
... ...
@@ -49,7 +49,7 @@ xj_pres_cell xj_pres_cell_new()
49 49
 	prc->key = 0;
50 50
 	prc->userid.s = NULL;
51 51
 	prc->userid.len = 0;
52
-	prc->state = XJ_PRES_STATE_OFFLINE;
52
+	prc->state = XJ_PS_OFFLINE;
53 53
 	prc->status = XJ_PRES_STATUS_NULL;
54 54
 	prc->cbf = NULL;
55 55
 	prc->cbp = NULL;
... ...
@@ -241,7 +241,6 @@ xj_pres_cell xj_pres_list_check(xj_pres_list prl, str* uid)
241 241
 
242 242
 	if(!prl || !uid || !uid->s || uid->len<=0 || prl->nr<=0 || prl->clist==NULL)
243 243
 		return NULL;
244
-	
245 244
 	lkey = xj_get_hash(uid, NULL);
246 245
 
247 246
 	p = prl->clist;
... ...
@@ -267,7 +266,7 @@ void xj_pres_list_notifyall(xj_pres_list prl, int s)
267 266
 	while(p)
268 267
 	{
269 268
 		if(p->cbf)
270
-			(*(p->cbf))(&(p->userid),(s==XJ_PRES_STATE_CHECK)?p->state:s,
269
+			(*(p->cbf))(&(p->userid),(s==XJ_PS_CHECK)?p->state:s,
271 270
 					p->cbp);
272 271
 		p = p->next;
273 272
 	}
... ...
@@ -32,10 +32,11 @@
32 32
 #include "../../str.h"
33 33
 #include "xjab_base.h"
34 34
 
35
-#define XJ_PRES_STATE_CHECK		-1
36
-#define XJ_PRES_STATE_OFFLINE	0
37
-#define XJ_PRES_STATE_ONLINE	1
38
-#define XJ_PRES_STATE_REFUSED	2
35
+#define XJ_PS_CHECK			-1
36
+#define XJ_PS_OFFLINE		0
37
+#define XJ_PS_ONLINE		1
38
+#define XJ_PS_TERMINATED	2
39
+#define XJ_PS_REFUSED		3
39 40
 
40 41
 #define XJ_PRES_STATUS_NULL		0
41 42
 #define XJ_PRES_STATUS_SUBS		1
... ...
@@ -31,11 +31,14 @@
31 31
  *
32 32
  * History
33 33
  * -------
34
- * 2003-02-28  send NOTIFYs even the connection is closed by user, (dcm)
35 34
  * 2003-01-20  xj_worker_precess function cleaning - some part of it moved to
36
- *              xj_worker_check_jcons function, (dcm)
37
- * 2003-03-11  major locking changes - uses locking.h (andrei)
38
- *
35
+ *             xj_worker_check_jcons function, (dcm)
36
+ * 2003-02-28  send NOTIFYs even the connection is closed by user, (dcm)
37
+ * 2003-03-11  major locking changes - uses locking.h, (andrei)
38
+ * 2003-05-07  added new presence status - 'terminated' - when connection
39
+ *             with Jabber server is lost or closed, (dcm)
40
+ * 2003-05-09  added new presence status - 'refused' - when the presence
41
+ *             subscription request is refused by target, (dcm)
39 42
  */
40 43
 
41 44
 #include <string.h>
... ...
@@ -563,6 +566,15 @@ step_z:
563 566
 		
564 567
 		if(jsmsg->type == XJ_REG_WATCHER)
565 568
 		{ // register a presence watcher
569
+			if(!jsmsg->cbf)
570
+			{
571
+#ifdef XJ_EXTRA_DEBUG
572
+				DBG("XJAB:xj_worker:%d: NULL PA callback"
573
+					" function\n", _xj_pid);
574
+#endif
575
+				goto step_w;
576
+			}
577
+
566 578
 			if(!xj_jconf_check_addr(&jsmsg->to, jwl->aliases->dlm))
567 579
 			{ // is for a conference - ignore?!?!
568 580
 #ifdef XJ_EXTRA_DEBUG
... ...
@@ -570,7 +582,7 @@ step_z:
570 582
 					_xj_pid);
571 583
 #endif
572 584
 				// set as offline
573
-				(*(jsmsg->cbf))(&jsmsg->to, 0, jsmsg->p);
585
+				(*(jsmsg->cbf))(&jsmsg->to, XJ_PS_OFFLINE, jsmsg->p);
574 586
 				goto step_w;
575 587
 			}
576 588
 			
... ...
@@ -583,6 +595,10 @@ step_z:
583 595
 				prc = xj_pres_list_check(jbc->plist, &sto);
584 596
 				if(!prc)
585 597
 				{
598
+#ifdef XJ_EXTRA_DEBUG
599
+					DBG("XJAB:xj_worker:%d: NEW presence"
600
+						" cell for %.*s.\n", _xj_pid, sto.len, sto.s);
601
+#endif
586 602
 					prc = xj_pres_cell_new();
587 603
 					if(!prc)
588 604
 					{
... ...
@@ -592,6 +608,8 @@ step_z:
592 608
 					}
593 609
 					if(xj_pres_cell_init(prc, &sto, jsmsg->cbf, jsmsg->p)<0)
594 610
 					{
611
+						DBG("XJAB:xj_worker:%d: cannot init the presence"
612
+							" cell for %.*s.\n", _xj_pid, sto.len, sto.s);
595 613
 						xj_pres_cell_free(prc);
596 614
 						goto step_w;
597 615
 					}
... ...
@@ -606,9 +624,15 @@ step_z:
606 624
 						prc->status = XJ_PRES_STATUS_WAIT; 
607 625
 				}
608 626
 				else
627
+				{
609 628
 					xj_pres_cell_update(prc, jsmsg->cbf, jsmsg->p);
610
-				// send presence info to SIP subscriber
611
-				(*(prc->cbf))(&jsmsg->to, prc->state, prc->cbp);
629
+#ifdef XJ_EXTRA_DEBUG
630
+					DBG("XJAB:xj_worker:%d: calling CBF(%.*s,%d)\n", _xj_pid,
631
+						jsmsg->to.len, jsmsg->to.s, prc->state);
632
+#endif
633
+					// send presence info to SIP subscriber
634
+					(*(prc->cbf))(&jsmsg->to, prc->state, prc->cbp);
635
+				}
612 636
 			}
613 637
 			goto step_w;
614 638
 		}
... ...
@@ -848,7 +872,7 @@ step_xx:
848 872
  */
849 873
 int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
850 874
 {
851
-	int i, err=0;
875
+	int j, err=0;
852 876
 	char *p, *to, *from, *msg, *type, *emsg, *ecode, lbuf[4096], fbuf[128];
853 877
 	xj_jconf jcf = NULL;
854 878
 	str ts, tf;
... ...
@@ -860,17 +884,18 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
860 884
 		return -1;
861 885
 
862 886
 	sid = jbc->jkey->id;	
863
-	x = xode_from_strx(buf, len, &err, &i);
887
+	x = xode_from_strx(buf, len, &err, &j);
864 888
 #ifdef XJ_EXTRA_DEBUG
865
-	DBG("XJAB:xj_parse_jab: XODE ret:%d pos:%d\n", err, i);
889
+	DBG("XJAB:xj_parse_jab: XODE ret:%d pos:%d\n", err, j);
866 890
 #endif	
867 891
 	if(err && pos != NULL)
868
-		*pos= i;
892
+		*pos= j;
869 893
 	if(x == NULL)
870 894
 		return -1;
871
-	
872 895
 	lbuf[0] = 0;
873 896
 	ecode = NULL;
897
+
898
+/******************** XMPP 'MESSAGE' HANDLING **********************/
874 899
 	
875 900
 	if(!strncasecmp(xode_get_name(x), "message", 7))
876 901
 	{
... ...
@@ -985,9 +1010,10 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
985 1010
 #endif
986 1011
 		}
987 1012
 		goto ready;
988
-	} // end MESSAGE
1013
+	}
1014
+/*------------------- END 'MESSAGE' HANDLING ----------------------*/
989 1015
 	
990
-	/*** PRESENCE HANDLING ***/
1016
+/******************** XMPP 'PRESENCE' HANDLING *********************/
991 1017
 	if(!strncasecmp(xode_get_name(x), "presence", 8))
992 1018
 	{
993 1019
 #ifdef XJ_EXTRA_DEBUG
... ...
@@ -1005,58 +1031,7 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
1005 1031
 			ts.len = p - from;
1006 1032
 		else
1007 1033
 			ts.len = strlen(from);
1008
-		if(type!=NULL && !strncasecmp(type, "error", 5))
1009
-		{
1010
-			if((jcf=xj_jcon_check_jconf(jbc, from))!=NULL)
1011
-			{
1012
-				tf.s = from;
1013
-				tf.len = strlen(from);
1014
-				if((y = xode_get_tag(x, "error")) == NULL)
1015
-					goto ready;
1016
-				if ((p = xode_get_attrib(y, "code")) != NULL
1017
-						&& atoi(p) == 409)
1018
-				{
1019
-					xj_send_sip_msgz(als->proxy, sid, &tf,
1020
-							XJ_DMSG_ERR_JCONFNICK, &jbc->jkey->flag);
1021
-					goto ready;
1022
-				}
1023
-				xj_send_sip_msgz(als->proxy,sid,&tf,XJ_DMSG_ERR_JCONFREFUSED,
1024
-						&jbc->jkey->flag);
1025
-			}
1026 1034
 
1027
-			goto ready;
1028
-		}
1029
-		if(type!=NULL && !strncasecmp(type, "subscribe", 9))
1030
-		{
1031
-			xj_jcon_send_presence(jbc, from, "subscribed", NULL, NULL);
1032
-			goto ready;
1033
-		}
1034
-		if(type!=NULL && !strncasecmp(type, "unavailable", 11))
1035
-		{
1036
-#ifdef XJ_EXTRA_DEBUG
1037
-			DBG("XJAB:xj_manage_jab: user <%s> is offline\n", from);
1038
-#endif
1039
-			prc = xj_pres_list_check(jbc->plist, &ts);
1040
-			if(prc)
1041
-			{
1042
-				prc->state = XJ_PRES_STATE_OFFLINE;
1043
-				// call callback function
1044
-				if(prc->cbf)
1045
-				{
1046
-					tf.s = fbuf;
1047
-					tf.len = 0;
1048
-					if(xj_address_translation(&ts,&tf,als,XJ_ADDRTR_B2A)==0)
1049
-					{
1050
-#ifdef XJ_EXTRA_DEBUG
1051
-						DBG("XJAB:xj_manage_jab: calling CBF(%.*s,0)\n",
1052
-							tf.len, tf.s);
1053
-#endif
1054
-						(*(prc->cbf))(&tf, prc->state, prc->cbp);
1055
-					}
1056
-				}
1057
-			}
1058
-			goto ready;
1059
-		}
1060 1035
 		if(type == NULL || !strncasecmp(type, "online", 6)
1061 1036
 			|| !strncasecmp(type, "available", 9))
1062 1037
 		{
... ...
@@ -1101,26 +1076,15 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
1101 1076
 			else
1102 1077
 			{
1103 1078
 #ifdef XJ_EXTRA_DEBUG
1104
-				DBG("XJAB:xj_manage_jab: user <%s> is online\n", from);
1079
+				DBG("XJAB:xj_manage_jab: user <%.*s> is online\n",ts.len,ts.s);
1105 1080
 #endif
1106 1081
 				prc = xj_pres_list_check(jbc->plist, &ts);
1107 1082
 				if(prc)
1108 1083
 				{
1109
-					prc->state = XJ_PRES_STATE_ONLINE;
1110
-					// call callback function
1111
-					if(prc->cbf)
1084
+					if(prc->state != XJ_PS_ONLINE)
1112 1085
 					{
1113
-						tf.s = fbuf;
1114
-						tf.len = 0;
1115
-						if(xj_address_translation(&ts,&tf,als,XJ_ADDRTR_B2A)
1116
-							==0)
1117
-						{
1118
-#ifdef XJ_EXTRA_DEBUG
1119
-							DBG("XJAB:xj_manage_jab: calling CBF(%.*s,1)\n",
1120
-								tf.len, tf.s);
1121
-#endif
1122
-							(*(prc->cbf))(&tf, prc->state, prc->cbp);
1123
-						}
1086
+						prc->state = XJ_PS_ONLINE;
1087
+						goto call_pa_cbf;
1124 1088
 					}
1125 1089
 				}
1126 1090
 				else
... ...
@@ -1145,15 +1109,81 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
1145 1109
 					}
1146 1110
 					prc = xj_pres_list_add(jbc->plist, prc);
1147 1111
 					if(prc)
1148
-						prc->state = XJ_PRES_STATE_ONLINE;
1112
+					{
1113
+						prc->state = XJ_PS_ONLINE;
1114
+						goto call_pa_cbf;
1115
+					}
1149 1116
 				}
1150 1117
 			}
1118
+			goto ready;
1119
+		}
1120
+		
1121
+		if(strchr(from, '@') == NULL)
1122
+			goto ready;
1123
+	
1124
+		
1125
+		if(!strncasecmp(type, "error", 5))
1126
+		{
1127
+			if((jcf=xj_jcon_check_jconf(jbc, from))!=NULL)
1128
+			{
1129
+				tf.s = from;
1130
+				tf.len = strlen(from);
1131
+				if((y = xode_get_tag(x, "error")) == NULL)
1132
+					goto ready;
1133
+				if ((p = xode_get_attrib(y, "code")) != NULL
1134
+						&& atoi(p) == 409)
1135
+				{
1136
+					xj_send_sip_msgz(als->proxy, sid, &tf,
1137
+							XJ_DMSG_ERR_JCONFNICK, &jbc->jkey->flag);
1138
+					goto ready;
1139
+				}
1140
+				xj_send_sip_msgz(als->proxy,sid,&tf,XJ_DMSG_ERR_JCONFREFUSED,
1141
+						&jbc->jkey->flag);
1142
+			}
1143
+			goto ready;
1144
+		}
1145
+		if(type!=NULL && !strncasecmp(type, "subscribe", 9))
1146
+		{
1147
+			xj_jcon_send_presence(jbc, from, "subscribed", NULL, NULL);
1148
+			goto ready;
1149
+		}
1150
+
1151
+		prc = xj_pres_list_check(jbc->plist, &ts);
1152
+		if(!prc)
1153
+			goto ready;
1151 1154
 
1155
+		if(!strncasecmp(type, "unavailable", 11))
1156
+		{
1157
+#ifdef XJ_EXTRA_DEBUG
1158
+			DBG("XJAB:xj_manage_jab: user <%s> is offline\n", from);
1159
+#endif
1160
+			if(prc->state != XJ_PS_OFFLINE)
1161
+			{
1162
+				prc->state = XJ_PS_OFFLINE;
1163
+				goto call_pa_cbf;
1164
+			}
1165
+			goto ready;
1152 1166
 		}
1153 1167
 		
1168
+		if(!strncasecmp(type, "unsubscribed", 12))
1169
+		{
1170
+#ifdef XJ_EXTRA_DEBUG
1171
+			DBG("XJAB:xj_manage_jab: user <%s> does not allow to see his"
1172
+				" presence status\n", from);
1173
+#endif
1174
+			if(prc->state != XJ_PS_REFUSED)
1175
+			{
1176
+				prc->state = XJ_PS_REFUSED;
1177
+				goto call_pa_cbf;
1178
+			}
1179
+		}
1180
+	
1181
+		// ignoring unknown types
1154 1182
 		goto ready;
1155
-	} // end PRESENCE
1183
+	}
1184
+/*------------------- END XMPP 'PRESENCE' HANDLING ----------------*/
1156 1185
 	
1186
+/******************** XMPP 'IQ' HANDLING ***************************/
1157 1187
 	if(!strncasecmp(xode_get_name(x), "iq", 2))
1158 1188
 	{
1159 1189
 #ifdef XJ_EXTRA_DEBUG
... ...
@@ -1201,51 +1231,6 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
1201 1231
 						}
1202 1232
 						goto next_sibling;
1203 1233
 					}
1204
-					/*** else
1205
-					{ // user item
1206
-						ts.s = from;
1207
-						ts.len = strlen(from);
1208
-						DBG("XJAB:xj_manage_jab:%s is in roster\n", from);
1209
-						if(xj_pres_list_check(jbc->plist, &ts))
1210
-						{
1211
-							DBG("XJAB:xj_manage_jab:%s already in presence"
1212
-								" list\n", from);
1213
-							goto next_sibling;
1214
-						}
1215
-
1216
-						prc = xj_pres_cell_new();
1217
-						if(prc == NULL)
1218
-						{
1219
-							DBG("XJAB:xj_manage_jab: cannot create presence"
1220
-								" cell for %s\n", from);
1221
-							goto next_sibling;
1222
-						}
1223
-						if(xj_pres_cell_init(prc, &ts, NULL, NULL)<0)
1224
-						{
1225
-							DBG("XJAB:xj_manage_jab: cannot init presence"
1226
-								" cell for %s\n", from);
1227
-							xj_pres_cell_free(prc);
1228
-							goto next_sibling;
1229
-						}
1230
-						prc = xj_pres_list_add(jbc->plist, prc);
1231
-						if(prc)
1232
-						{
1233
-							p = xode_get_attrib(z, "subscription");
1234
-							if(p && !strncasecmp(p, "none", 4))
1235
-							{
1236
-								DBG("XJAB:xj_manage_jab: wait for permission"
1237
-									" from %s\n", from);
1238
-								prc->status = XJ_PRES_STATUS_WAIT; 
1239
-							}
1240
-							else
1241
-							{
1242
-								DBG("XJAB:xj_manage_jab: permission granted"
1243
-									" from %s\n", from);
1244
-								prc->status = XJ_PRES_STATUS_SUBS;
1245
-							}
1246
-						}
1247
-					} 
1248
-					***/
1249 1234
 				}
1250 1235
 next_sibling:
1251 1236
 				z = xode_get_nextsibling(z);
... ...
@@ -1253,8 +1238,24 @@ next_sibling:
1253 1238
 		}
1254 1239
 		
1255 1240
 		goto ready;
1256
-	} // end IQ
1241
+	}
1242
+/*------------------- END XMPP 'IQ' HANDLING ----------------------*/
1257 1243
 
1244
+call_pa_cbf:
1245
+	if(prc && prc->cbf)
1246
+	{
1247
+		// call the PA callback function
1248
+		tf.s = fbuf;
1249
+		tf.len = 0;
1250
+		if(xj_address_translation(&ts,&tf,als,XJ_ADDRTR_B2A)==0)
1251
+		{
1252
+#ifdef XJ_EXTRA_DEBUG
1253
+			DBG("XJAB:xj_manage_jab: calling CBF(%.*s,%d)\n",
1254
+				tf.len, tf.s, prc->state);
1255
+#endif
1256
+			(*(prc->cbf))(&tf, prc->state, prc->cbp);
1257
+		}
1258
+	}
1258 1259
 ready:
1259 1260
 	xode_free(x);
1260 1261
 	return err;
... ...
@@ -1299,30 +1300,7 @@ int xj_send_sip_msg(str *proxy, str *to, str *from, str *msg, int *cbp)
1299 1300
 		return -1;
1300 1301
 
1301 1302
 	// from correction
1302
-	/****
1303
-	beg = crt = 0;
1304
-	end = -1;
1305
-	while(crt < from->len && from->s[crt]!='@')
1306
-	{
1307
-		if(from->s[crt]==delim)
1308
-		{
1309
-			beg = end + 1;
1310
-			end = crt;
1311
-		}
1312
-		crt++;
1313
-	}
1314
-	***/
1315 1303
 	tfrom.len = 0;
1316
-	/***
1317
-	if(end > 0)
1318
-	{ // put display name
1319
-		buf[0] = '"';
1320
-		strncpy(buf+1,from->s+beg,end-beg);
1321
-		tfrom.len = end-beg+1;
1322
-		buf[tfrom.len++] = '"';
1323
-		buf[tfrom.len++] = ' ';
1324
-	}
1325
-	***/
1326 1304
 	strncpy(buf+tfrom.len, "<sip:", 5);
1327 1305
 	tfrom.len += 5;
1328 1306
 	strncpy(buf+tfrom.len, from->s, from->len);
... ...
@@ -1337,8 +1315,6 @@ int xj_send_sip_msg(str *proxy, str *to, str *from, str *msg, int *cbp)
1337 1315
 	
1338 1316
 	strncat(buf1,tfrom.s,tfrom.len);
1339 1317
 	str_hdr.len += tfrom.len;
1340
-	//strncat(buf1,"sip:193.175.135.68:5060",23);
1341
-	//str_hdr.len += 23;
1342 1318
 	
1343 1319
 	strcat(buf1, CRLF);
1344 1320
 	str_hdr.len += CRLF_LEN;
... ...
@@ -1494,11 +1470,11 @@ void xj_worker_check_jcons(xj_wlist jwl, xj_jcon_pool jcp, int ltime, fd_set *ps
1494 1470
 		if(jcp->ojc[i]->plist)
1495 1471
 		{
1496 1472
 #ifdef XJ_EXTRA_DEBUG
1497
-			DBG("XJAB:xj_worker:%d: sending offline status to SIP"
1473
+			DBG("XJAB:xj_worker:%d: sending 'terminated' status to SIP"
1498 1474
 					"subscriber\n", _xj_pid);
1499 1475
 #endif
1500 1476
 			xj_pres_list_notifyall(jcp->ojc[i]->plist,
1501
-					XJ_PRES_STATE_OFFLINE);
1477
+					XJ_PS_TERMINATED);
1502 1478
 		}
1503 1479
 		FD_CLR(jcp->ojc[i]->sock, pset);
1504 1480
 		xj_jcon_disconnect(jcp->ojc[i]);