Fri, 11 Apr 2003 08:09:21 +0000
[gaim-migrate @ 5473]
it dawned on me that since this function is so good at validating html, it
might be pretty good at stripping html. so now we use it instead of
strip_html and jabber messages don't get stripped of valid < and > characters
| 3127 | 1 | /* -------------------------------------------------------------------------- |
| 2 | * | |
| 3 | * License | |
| 4 | * | |
| 5 | * The contents of this file are subject to the Jabber Open Source License | |
| 6 | * Version 1.0 (the "JOSL"). You may not copy or use this file, in either | |
| 7 | * source code or executable form, except in compliance with the JOSL. You | |
| 8 | * may obtain a copy of the JOSL at http://www.jabber.org/ or at | |
| 9 | * http://www.opensource.org/. | |
| 10 | * | |
| 11 | * Software distributed under the JOSL is distributed on an "AS IS" basis, | |
| 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the JOSL | |
| 13 | * for the specific language governing rights and limitations under the | |
| 14 | * JOSL. | |
| 15 | * | |
| 16 | * Copyrights | |
| 17 | * | |
| 18 | * Portions created by or assigned to Jabber.com, Inc. are | |
| 19 | * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact | |
| 20 | * information for Jabber.com, Inc. is available at http://www.jabber.com/. | |
| 2086 | 21 | * |
| 3127 | 22 | * Portions Copyright (c) 1998-1999 Jeremie Miller. |
| 23 | * | |
| 24 | * Acknowledgements | |
| 25 | * | |
| 26 | * Special thanks to the Jabber Open Source Contributors for their | |
| 27 | * suggestions and support of Jabber. | |
| 28 | * | |
| 29 | * Alternatively, the contents of this file may be used under the terms of the | |
| 30 | * GNU General Public License Version 2 or later (the "GPL"), in which case | |
| 31 | * the provisions of the GPL are applicable instead of those above. If you | |
| 32 | * wish to allow use of your version of this file only under the terms of the | |
| 33 | * GPL and not to allow others to use your version of this file under the JOSL, | |
| 34 | * indicate your decision by deleting the provisions above and replace them | |
| 35 | * with the notice and other provisions required by the GPL. If you do not | |
| 36 | * delete the provisions above, a recipient may use your version of this file | |
| 37 | * under either the JOSL or the GPL. | |
| 38 | * | |
| 39 | * | |
| 40 | * --------------------------------------------------------------------------*/ | |
| 2086 | 41 | |
| 3127 | 42 | #include "lib.h" |
| 2086 | 43 | |
| 44 | jpacket jpacket_new(xmlnode x) | |
| 45 | { | |
| 46 | jpacket p; | |
| 47 | ||
| 48 | if(x == NULL) | |
| 49 | return NULL; | |
| 50 | ||
| 51 | p = pmalloc(xmlnode_pool(x),sizeof(_jpacket)); | |
| 52 | p->x = x; | |
| 53 | ||
| 54 | return jpacket_reset(p); | |
| 55 | } | |
| 56 | ||
| 57 | jpacket jpacket_reset(jpacket p) | |
| 58 | { | |
| 59 | char *val; | |
| 60 | xmlnode x; | |
| 61 | ||
| 62 | x = p->x; | |
| 63 | memset(p,0,sizeof(_jpacket)); | |
| 64 | p->x = x; | |
| 65 | p->p = xmlnode_pool(x); | |
| 66 | ||
| 67 | if(strncmp(xmlnode_get_name(x),"message",7) == 0) | |
| 68 | { | |
| 69 | p->type = JPACKET_MESSAGE; | |
| 70 | }else if(strncmp(xmlnode_get_name(x),"presence",8) == 0) | |
| 71 | { | |
| 72 | p->type = JPACKET_PRESENCE; | |
| 73 | val = xmlnode_get_attrib(x, "type"); | |
| 74 | if(val == NULL) | |
| 75 | p->subtype = JPACKET__AVAILABLE; | |
| 76 | else if(strcmp(val,"unavailable") == 0) | |
| 77 | p->subtype = JPACKET__UNAVAILABLE; | |
| 78 | else if(strcmp(val,"probe") == 0) | |
| 79 | p->subtype = JPACKET__PROBE; | |
| 3127 | 80 | else if(strcmp(val,"error") == 0) |
| 81 | p->subtype = JPACKET__ERROR; | |
| 82 | else if(strcmp(val,"invisible") == 0) | |
| 83 | p->subtype = JPACKET__INVISIBLE; | |
| 2086 | 84 | else if(*val == 's' || *val == 'u') |
| 85 | p->type = JPACKET_S10N; | |
| 86 | else if(strcmp(val,"available") == 0) | |
| 87 | { /* someone is using type='available' which is frowned upon */ | |
| 88 | xmlnode_hide_attrib(x,"type"); | |
| 89 | p->subtype = JPACKET__AVAILABLE; | |
| 90 | }else | |
| 91 | p->type = JPACKET_UNKNOWN; | |
| 92 | }else if(strncmp(xmlnode_get_name(x),"iq",2) == 0) | |
| 93 | { | |
| 94 | p->type = JPACKET_IQ; | |
| 95 | p->iq = xmlnode_get_tag(x,"?xmlns"); | |
| 96 | p->iqns = xmlnode_get_attrib(p->iq,"xmlns"); | |
| 97 | } | |
| 98 | ||
| 99 | /* set up the jids if any, flag packet as unknown if they are unparseable */ | |
| 100 | val = xmlnode_get_attrib(x,"to"); | |
| 101 | if(val != NULL) | |
| 102 | if((p->to = jid_new(p->p, val)) == NULL) | |
| 103 | p->type = JPACKET_UNKNOWN; | |
| 104 | val = xmlnode_get_attrib(x,"from"); | |
| 105 | if(val != NULL) | |
| 106 | if((p->from = jid_new(p->p, val)) == NULL) | |
| 107 | p->type = JPACKET_UNKNOWN; | |
| 108 | ||
| 109 | return p; | |
| 110 | } | |
| 111 | ||
| 112 | ||
| 113 | int jpacket_subtype(jpacket p) | |
| 114 | { | |
| 115 | char *type; | |
| 116 | int ret = p->subtype; | |
| 117 | ||
| 118 | if(ret != JPACKET__UNKNOWN) | |
| 119 | return ret; | |
| 120 | ||
| 121 | ret = JPACKET__NONE; /* default, when no type attrib is specified */ | |
| 122 | type = xmlnode_get_attrib(p->x, "type"); | |
| 123 | if(j_strcmp(type,"error") == 0) | |
| 124 | ret = JPACKET__ERROR; | |
| 125 | else | |
| 126 | switch(p->type) | |
| 127 | { | |
| 128 | case JPACKET_MESSAGE: | |
| 129 | if(j_strcmp(type,"chat") == 0) | |
| 130 | ret = JPACKET__CHAT; | |
| 131 | else if(j_strcmp(type,"groupchat") == 0) | |
| 132 | ret = JPACKET__GROUPCHAT; | |
| 133 | else if(j_strcmp(type,"headline") == 0) | |
| 134 | ret = JPACKET__HEADLINE; | |
| 135 | break; | |
| 136 | case JPACKET_S10N: | |
| 137 | if(j_strcmp(type,"subscribe") == 0) | |
| 138 | ret = JPACKET__SUBSCRIBE; | |
| 139 | else if(j_strcmp(type,"subscribed") == 0) | |
| 140 | ret = JPACKET__SUBSCRIBED; | |
| 141 | else if(j_strcmp(type,"unsubscribe") == 0) | |
| 142 | ret = JPACKET__UNSUBSCRIBE; | |
| 143 | else if(j_strcmp(type,"unsubscribed") == 0) | |
| 144 | ret = JPACKET__UNSUBSCRIBED; | |
| 145 | break; | |
| 146 | case JPACKET_IQ: | |
| 147 | if(j_strcmp(type,"get") == 0) | |
| 148 | ret = JPACKET__GET; | |
| 149 | else if(j_strcmp(type,"set") == 0) | |
| 150 | ret = JPACKET__SET; | |
| 151 | else if(j_strcmp(type,"result") == 0) | |
| 152 | ret = JPACKET__RESULT; | |
| 153 | break; | |
| 154 | } | |
| 155 | ||
| 156 | p->subtype = ret; | |
| 157 | return ret; | |
| 158 | } |