Jabber WindowGram Client (JWGC)

Introduction Screenshots Installation Downloads
Documentation Browse Source Resources Project Site

Stable Version
-none-

Latest Version
beta5



Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

jpacket.c

Go to the documentation of this file.
00001 /*
00002  * --------------------------------------------------------------------------
00003  * 
00004  * License
00005  * 
00006  * The contents of this file are subject to the Jabber Open Source License
00007  * Version 1.0 (the "JOSL").  You may not copy or use this file, in either
00008  * source code or executable form, except in compliance with the JOSL. You
00009  * may obtain a copy of the JOSL at http://www.jabber.org/ or at
00010  * http://www.opensource.org/.
00011  * 
00012  * Software distributed under the JOSL is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the JOSL for
00014  * the specific language governing rights and limitations under the JOSL.
00015  * 
00016  * Copyrights
00017  * 
00018  * Portions created by or assigned to Jabber.com, Inc. are Copyright (c)
00019  * 1999-2002 Jabber.com, Inc.  All Rights Reserved.  Contact information for
00020  * Jabber.com, Inc. is available at http://www.jabber.com/.
00021  * 
00022  * Portions Copyright (c) 1998-1999 Jeremie Miller.
00023  * 
00024  * Acknowledgements
00025  * 
00026  * Special thanks to the Jabber Open Source Contributors for their suggestions
00027  * and support of Jabber.
00028  * 
00029  * Alternatively, the contents of this file may be used under the terms of the
00030  * GNU General Public License Version 2 or later (the "GPL"), in which case
00031  * the provisions of the GPL are applicable instead of those above.  If you
00032  * wish to allow use of your version of this file only under the terms of the
00033  * GPL and not to allow others to use your version of this file under the
00034  * JOSL, indicate your decision by deleting the provisions above and replace
00035  * them with the notice and other provisions required by the GPL.  If you do
00036  * not delete the provisions above, a recipient may use your version of this
00037  * file under either the JOSL or the GPL.
00038  * 
00039  * --------------------------------------------------------------------------
00040  */
00041 
00042 /* $Id: jpacket.c,v 1.9 2004/01/25 17:25:52 jadestorm Exp $ */
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 }


Last updated at Tue Dec 18 21:07:42 PST 2007. This site and project hosted by...SourceForge.net Logo
Source Perspective by Fisheye