jabberd2  2.2.16
sx/callback.c
Go to the documentation of this file.
00001 /*
00002  * jabberd - Jabber Open Source Server
00003  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
00004  *                    Ryan Eatmon, Robert Norris
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
00019  */
00020 
00021 #include "sx.h"
00022 
00024 void _sx_element_start(void *arg, const char *name, const char **atts) {
00025     sx_t s = (sx_t) arg;
00026     char buf[1024];
00027     char *uri, *elem, *prefix;
00028     const char **attr;
00029     int ns;
00030     int el;
00031 
00032     if(s->fail) return;
00033 
00034     /* starting a new nad */
00035     if(s->nad == NULL)
00036         s->nad = nad_new();
00037 
00038     /* make a copy */
00039     strncpy(buf, name, 1024);
00040     buf[1023] = '\0';
00041 
00042     /* expat gives us:
00043          prefixed namespaced elem: uri|elem|prefix
00044           default namespaced elem: uri|elem
00045                un-namespaced elem: elem
00046      */
00047 
00048     /* extract all the bits */
00049     uri = buf;
00050     elem = strchr(uri, '|');
00051     if(elem != NULL) {
00052         *elem = '\0';
00053         elem++;
00054         prefix = strchr(elem, '|');
00055         if(prefix != NULL) {
00056             *prefix = '\0';
00057             prefix++;
00058         }
00059         ns = nad_add_namespace(s->nad, uri, prefix);
00060     } else {
00061         /* un-namespaced, just take it as-is */
00062         uri = NULL;
00063         elem = buf;
00064         prefix = NULL;
00065         ns = -1;
00066     }
00067 
00068     /* add it */
00069     el = nad_append_elem(s->nad, ns, elem, s->depth - 1);
00070 
00071     /* now the attributes, one at a time */
00072     attr = atts;
00073     while(attr[0] != NULL) {
00074 
00075         /* make a copy */
00076         strncpy(buf, attr[0], 1024);
00077         buf[1023] = '\0';
00078 
00079         /* extract all the bits */
00080         uri = buf;
00081         elem = strchr(uri, '|');
00082         if(elem != NULL) {
00083             *elem = '\0';
00084             elem++;
00085             prefix = strchr(elem, '|');
00086             if(prefix != NULL) {
00087                 *prefix = '\0';
00088                 prefix++;
00089             }
00090             ns = nad_append_namespace(s->nad, el, uri, prefix);
00091         } else {
00092             /* un-namespaced, just take it as-is */
00093             uri = NULL;
00094             elem = buf;
00095             prefix = NULL;
00096             ns = -1;
00097         }
00098 
00099         /* add it */
00100         nad_append_attr(s->nad, ns, elem, (char *) attr[1]);
00101 
00102         attr += 2;
00103     }
00104 
00105     s->depth++;
00106 }
00107 
00108 void _sx_element_end(void *arg, const char *name) {
00109     sx_t s = (sx_t) arg;
00110 
00111     if(s->fail) return;
00112 
00113     s->depth--;
00114 
00115     if(s->depth == 1) {
00116         /* completed nad, save it for later processing */
00117         jqueue_push(s->rnadq, s->nad, 0);
00118         s->nad = NULL;
00119 
00120         /* and reset read bytes counter */
00121         s->rbytes = 0;
00122     }
00123 
00124     /* close received */
00125     else if(s->depth == 0)
00126         s->depth = -1;
00127 }
00128 
00129 void _sx_cdata(void *arg, const char *str, int len) {
00130     sx_t s = (sx_t) arg;
00131 
00132     if(s->fail) return;
00133 
00134     /* no nad? no cdata */
00135     if(s->nad == NULL)
00136         return;
00137 
00138     /* go */
00139     nad_append_cdata(s->nad, (char *) str, len, s->depth - 1);
00140 }
00141 
00142 void _sx_namespace_start(void *arg, const char *prefix, const char *uri) {
00143     sx_t s = (sx_t) arg;
00144     int ns;
00145 
00146     if(s->fail) return;
00147 
00148     /* some versions of MSXML send xmlns='' occassionaally. it seems safe to ignore it */
00149     if(uri == NULL) return;
00150 
00151     /* starting a new nad */
00152     if(s->nad == NULL)
00153         s->nad = nad_new();
00154 
00155     ns = nad_add_namespace(s->nad, (char *) uri, (char *) prefix);
00156 
00157     /* Always set the namespace (to catch cases where nad_add_namespace doesn't add it) */
00158     s->nad->scope = ns;
00159 }
00160 
00161 #ifdef HAVE_XML_STOPPARSER
00162 /* Stop the parser if an entity declaration is hit. */
00163 void _sx_entity_declaration(void *arg, const char *entityName,
00164                             int is_parameter_entity, const char *value,
00165                             int value_length, const char *base,
00166                             const char *systemId, const char *publicId,
00167                             const char *notationName)
00168 {
00169     sx_t s = (sx_t) arg;
00170 
00171     XML_StopParser(s->expat, XML_FALSE);
00172 }
00173 #endif
00174