00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "libjabber.h"
00045 #include "libxode.h"
00046
00047 jabpacket
00048 jabpacket_new(xode x)
00049 {
00050 jabpacket p;
00051
00052 if (x == NULL)
00053 return NULL;
00054
00055 p = xode_pool_malloc(xode_get_pool(x), sizeof(_jabpacket));
00056 p->x = x;
00057
00058 return jabpacket_reset(p);
00059 }
00060
00061 jabpacket
00062 jabpacket_reset(jabpacket p)
00063 {
00064 char *val;
00065 xode x;
00066
00067 x = p->x;
00068 memset(p, 0, sizeof(_jabpacket));
00069 p->x = x;
00070 p->p = xode_get_pool(x);
00071
00072 if (strncmp(xode_get_name(x), "message", 7) == 0) {
00073 p->type = JABPACKET_MESSAGE;
00074 }
00075 else if (strncmp(xode_get_name(x), "presence", 8) == 0) {
00076 p->type = JABPACKET_PRESENCE;
00077 }
00078 else if (strncmp(xode_get_name(x), "iq", 2) == 0) {
00079 p->type = JABPACKET_IQ;
00080 p->iq = xode_get_tag(x, "?xmlns");
00081 p->iqns = xode_get_attrib(p->iq, "xmlns");
00082 }
00083
00084 val = xode_get_attrib(x, "to");
00085 if (val != NULL)
00086 if ((p->to = jid_new(p->p, val)) == NULL)
00087 p->type = JABPACKET_UNKNOWN;
00088 val = xode_get_attrib(x, "from");
00089 if (val != NULL)
00090 if ((p->from = jid_new(p->p, val)) == NULL)
00091 p->type = JABPACKET_UNKNOWN;
00092
00093 p->subtype = JABPACKET__UNKNOWN;
00094 p->subtype = jabpacket_subtype(p);
00095
00096 return p;
00097 }
00098
00099
00100 int
00101 jabpacket_subtype(jabpacket p)
00102 {
00103 char *type;
00104 int ret = p->subtype;
00105
00106 if (ret != JABPACKET__UNKNOWN)
00107 return ret;
00108
00109 ret = JABPACKET__NONE;
00110 type = xode_get_attrib(p->x, "type");
00111 if (j_strcmp(type, "error") == 0)
00112 ret = JABPACKET__ERROR;
00113 else
00114 switch (p->type) {
00115 case JABPACKET_MESSAGE:
00116 if (j_strcmp(type, "chat") == 0)
00117 ret = JABPACKET__CHAT;
00118 else if (j_strcmp(type, "groupchat") == 0)
00119 ret = JABPACKET__GROUPCHAT;
00120 else if (j_strcmp(type, "headline") == 0)
00121 ret = JABPACKET__HEADLINE;
00122 else if (j_strcmp(type, "internal") == 0)
00123 ret = JABPACKET__INTERNAL;
00124 else
00125 ret = JABPACKET__UNKNOWN;
00126 break;
00127
00128 case JABPACKET_PRESENCE:
00129 if (type == NULL)
00130 ret = JABPACKET__AVAILABLE;
00131 else if (j_strcmp(type, "unavailable") == 0)
00132 ret = JABPACKET__UNAVAILABLE;
00133 else if (j_strcmp(type, "probe") == 0)
00134 ret = JABPACKET__PROBE;
00135 else if (j_strcmp(type, "error") == 0)
00136 ret = JABPACKET__ERROR;
00137 else if (j_strcmp(type, "invisible") == 0)
00138 ret = JABPACKET__INVISIBLE;
00139 else if (j_strcmp(type, "available") == 0)
00140 ret = JABPACKET__AVAILABLE;
00141 else if (j_strcmp(type, "online") == 0)
00142 ret = JABPACKET__AVAILABLE;
00143 else if (j_strcmp(type, "subscribe") == 0)
00144 ret = JABPACKET__SUBSCRIBE;
00145 else if (j_strcmp(type, "subscribed") == 0)
00146 ret = JABPACKET__SUBSCRIBED;
00147 else if (j_strcmp(type, "unsubscribe") == 0)
00148 ret = JABPACKET__UNSUBSCRIBE;
00149 else if (j_strcmp(type, "unsubscribed") == 0)
00150 ret = JABPACKET__UNSUBSCRIBED;
00151 else
00152 ret = JABPACKET__UNKNOWN;
00153 break;
00154
00155 case JABPACKET_IQ:
00156 if (j_strcmp(type, "get") == 0)
00157 ret = JABPACKET__GET;
00158 else if (j_strcmp(type, "set") == 0)
00159 ret = JABPACKET__SET;
00160 else if (j_strcmp(type, "result") == 0)
00161 ret = JABPACKET__RESULT;
00162 else
00163 ret = JABPACKET__UNKNOWN;
00164 break;
00165 }
00166
00167 return ret;
00168 }