Mercurial > pidgin.yaz
comparison src/protocols/jabber/jpacket.c @ 2086:424a40f12a6c
[gaim-migrate @ 2096]
moving protocols from plugins/ to src/protocols. making it so that you can select which protocols are compiled statically.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 31 Jul 2001 01:00:39 +0000 |
parents | |
children | 4e7cefc55971 |
comparison
equal
deleted
inserted
replaced
2085:7ebb4322f89b | 2086:424a40f12a6c |
---|---|
1 /* | |
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. | |
6 * | |
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. | |
11 * | |
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. | |
15 * | |
16 * Jabber | |
17 * Copyright (C) 1998-1999 The Jabber Team http://jabber.org/ | |
18 */ | |
19 | |
20 #include "jabber.h" | |
21 | |
22 jpacket jpacket_new(xmlnode x) | |
23 { | |
24 jpacket p; | |
25 | |
26 if(x == NULL) | |
27 return NULL; | |
28 | |
29 p = pmalloc(xmlnode_pool(x),sizeof(_jpacket)); | |
30 p->x = x; | |
31 | |
32 return jpacket_reset(p); | |
33 } | |
34 | |
35 jpacket jpacket_reset(jpacket p) | |
36 { | |
37 char *val; | |
38 xmlnode x; | |
39 | |
40 x = p->x; | |
41 memset(p,0,sizeof(_jpacket)); | |
42 p->x = x; | |
43 p->p = xmlnode_pool(x); | |
44 | |
45 if(strncmp(xmlnode_get_name(x),"message",7) == 0) | |
46 { | |
47 p->type = JPACKET_MESSAGE; | |
48 }else if(strncmp(xmlnode_get_name(x),"presence",8) == 0) | |
49 { | |
50 p->type = JPACKET_PRESENCE; | |
51 val = xmlnode_get_attrib(x, "type"); | |
52 if(val == NULL) | |
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; | |
64 }else | |
65 p->type = JPACKET_UNKNOWN; | |
66 }else if(strncmp(xmlnode_get_name(x),"iq",2) == 0) | |
67 { | |
68 p->type = JPACKET_IQ; | |
69 p->iq = xmlnode_get_tag(x,"?xmlns"); | |
70 p->iqns = xmlnode_get_attrib(p->iq,"xmlns"); | |
71 } | |
72 | |
73 /* set up the jids if any, flag packet as unknown if they are unparseable */ | |
74 val = xmlnode_get_attrib(x,"to"); | |
75 if(val != NULL) | |
76 if((p->to = jid_new(p->p, val)) == NULL) | |
77 p->type = JPACKET_UNKNOWN; | |
78 val = xmlnode_get_attrib(x,"from"); | |
79 if(val != NULL) | |
80 if((p->from = jid_new(p->p, val)) == NULL) | |
81 p->type = JPACKET_UNKNOWN; | |
82 | |
83 return p; | |
84 } | |
85 | |
86 | |
87 int jpacket_subtype(jpacket p) | |
88 { | |
89 char *type; | |
90 int ret = p->subtype; | |
91 | |
92 if(ret != JPACKET__UNKNOWN) | |
93 return ret; | |
94 | |
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) | |
98 ret = JPACKET__ERROR; | |
99 else | |
100 switch(p->type) | |
101 { | |
102 case JPACKET_MESSAGE: | |
103 if(j_strcmp(type,"chat") == 0) | |
104 ret = JPACKET__CHAT; | |
105 else if(j_strcmp(type,"groupchat") == 0) | |
106 ret = JPACKET__GROUPCHAT; | |
107 else if(j_strcmp(type,"headline") == 0) | |
108 ret = JPACKET__HEADLINE; | |
109 break; | |
110 case JPACKET_S10N: | |
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; | |
119 break; | |
120 case JPACKET_IQ: | |
121 if(j_strcmp(type,"get") == 0) | |
122 ret = JPACKET__GET; | |
123 else if(j_strcmp(type,"set") == 0) | |
124 ret = JPACKET__SET; | |
125 else if(j_strcmp(type,"result") == 0) | |
126 ret = JPACKET__RESULT; | |
127 break; | |
128 } | |
129 | |
130 p->subtype = ret; | |
131 return ret; | |
132 } |