2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
22 jpacket
jpacket_new(xmlnode x
)
29 p
= pmalloc(xmlnode_pool(x
),sizeof(_jpacket
));
32 return jpacket_reset(p
);
35 jpacket
jpacket_reset(jpacket p
)
41 memset(p
,0,sizeof(_jpacket
));
43 p
->p
= xmlnode_pool(x
);
45 if(strncmp(xmlnode_get_name(x
),"message",7) == 0)
47 p
->type
= JPACKET_MESSAGE
;
48 }else if(strncmp(xmlnode_get_name(x
),"presence",8) == 0)
50 p
->type
= JPACKET_PRESENCE
;
51 val
= xmlnode_get_attrib(x
, "type");
53 p
->subtype
= JPACKET__AVAILABLE
;
54 else if(strcmp(val
,"unavailable") == 0)
55 p
->subtype
= JPACKET__UNAVAILABLE
;
56 else if(strcmp(val
,"probe") == 0)
57 p
->subtype
= JPACKET__PROBE
;
58 else if(*val
== 's' || *val
== 'u')
59 p
->type
= JPACKET_S10N
;
60 else if(strcmp(val
,"available") == 0)
61 { /* someone is using type='available' which is frowned upon */
62 xmlnode_hide_attrib(x
,"type");
63 p
->subtype
= JPACKET__AVAILABLE
;
65 p
->type
= JPACKET_UNKNOWN
;
66 }else if(strncmp(xmlnode_get_name(x
),"iq",2) == 0)
69 p
->iq
= xmlnode_get_tag(x
,"?xmlns");
70 p
->iqns
= xmlnode_get_attrib(p
->iq
,"xmlns");
73 /* set up the jids if any, flag packet as unknown if they are unparseable */
74 val
= xmlnode_get_attrib(x
,"to");
76 if((p
->to
= jid_new(p
->p
, val
)) == NULL
)
77 p
->type
= JPACKET_UNKNOWN
;
78 val
= xmlnode_get_attrib(x
,"from");
80 if((p
->from
= jid_new(p
->p
, val
)) == NULL
)
81 p
->type
= JPACKET_UNKNOWN
;
87 int jpacket_subtype(jpacket p
)
92 if(ret
!= JPACKET__UNKNOWN
)
95 ret
= JPACKET__NONE
; /* default, when no type attrib is specified */
96 type
= xmlnode_get_attrib(p
->x
, "type");
97 if(j_strcmp(type
,"error") == 0)
102 case JPACKET_MESSAGE
:
103 if(j_strcmp(type
,"chat") == 0)
105 else if(j_strcmp(type
,"groupchat") == 0)
106 ret
= JPACKET__GROUPCHAT
;
107 else if(j_strcmp(type
,"headline") == 0)
108 ret
= JPACKET__HEADLINE
;
111 if(j_strcmp(type
,"subscribe") == 0)
112 ret
= JPACKET__SUBSCRIBE
;
113 else if(j_strcmp(type
,"subscribed") == 0)
114 ret
= JPACKET__SUBSCRIBED
;
115 else if(j_strcmp(type
,"unsubscribe") == 0)
116 ret
= JPACKET__UNSUBSCRIBE
;
117 else if(j_strcmp(type
,"unsubscribed") == 0)
118 ret
= JPACKET__UNSUBSCRIBED
;
121 if(j_strcmp(type
,"get") == 0)
123 else if(j_strcmp(type
,"set") == 0)
125 else if(j_strcmp(type
,"result") == 0)
126 ret
= JPACKET__RESULT
;