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

str.c

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00015  *
00016  *  Jabber
00017  *  Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
00018  */
00019 
00020 #include "libxode.h"
00021 
00022 xode_pool xode_spool_getpool(const xode_spool s)
00023 {
00024     if(s == NULL)
00025         return NULL;
00026 
00027     return s->p;
00028 }
00029 
00030 int xode_spool_getlen(const xode_spool s)
00031 {
00032     if(s == NULL)
00033         return 0;
00034 
00035     return s->len;    
00036 }
00037 
00038 void xode_spool_free(xode_spool s)
00039 {
00040     xode_pool_free(xode_spool_getpool(s));
00041 }
00042 
00043 xode_spool xode_spool_newfrompool(xode_pool p)
00044 {
00045     xode_spool s;
00046 
00047     s = xode_pool_malloc(p, sizeof(struct xode_spool_struct));
00048     s->p = p;
00049     s->len = 0;
00050     s->last = NULL;
00051     s->first = NULL;
00052     return s;
00053 }
00054 
00055 xode_spool xode_spool_new(void)
00056 {
00057     return xode_spool_newfrompool(xode_pool_heap(512));
00058 }
00059 
00060 void xode_spool_add(xode_spool s, char *str)
00061 {
00062     struct xode_spool_node *sn;
00063     int len;
00064 
00065     if(str == NULL)
00066         return;
00067 
00068     len = strlen(str);
00069     if(len == 0)
00070         return;
00071 
00072     sn = xode_pool_malloc(s->p, sizeof(struct xode_spool_node));
00073     sn->c = xode_pool_strdup(s->p, str);
00074     sn->next = NULL;
00075 
00076     s->len += len;
00077     if(s->last != NULL)
00078         s->last->next = sn;
00079     s->last = sn;
00080     if(s->first == NULL)
00081         s->first = sn;
00082 }
00083 
00084 void xode_spooler(xode_spool s, ...)
00085 {
00086     va_list ap;
00087     char *arg = NULL;
00088 
00089     if(s == NULL)
00090         return;
00091 
00092     va_start(ap, s);
00093 
00094     /* loop till we hit our end flag, the first arg */
00095     while(1)
00096     {
00097         arg = va_arg(ap,char *);
00098         if((int)arg == (int)s || arg == NULL)
00099             break;
00100         else
00101             xode_spool_add(s, arg);
00102     }
00103 
00104     va_end(ap);
00105 }
00106 
00107 char *xode_spool_tostr(xode_spool s)
00108 {
00109     char *ret,*tmp;
00110     struct xode_spool_node *next;
00111 
00112     if(s == NULL || s->len == 0 || s->first == NULL)
00113         return NULL;
00114 
00115     ret = xode_pool_malloc(s->p, s->len + 1);
00116     *ret = '\0';
00117 
00118     next = s->first;
00119     tmp = ret;
00120     while(next != NULL)
00121     {
00122         tmp = strcat(tmp,next->c);
00123         next = next->next;
00124     }
00125 
00126     return ret;
00127 }
00128 
00129 /* convenience :) */
00130 char *xode_spool_str(xode_pool p, ...)
00131 {
00132     va_list ap;
00133     xode_spool s;
00134     char *arg = NULL;
00135 
00136     if(p == NULL)
00137         return NULL;
00138 
00139     s = xode_spool_newfrompool(p);
00140 
00141     va_start(ap, p);
00142 
00143     /* loop till we hit our end flag, the first arg */
00144     while(1)
00145     {
00146         arg = va_arg(ap,char *);
00147         if((int)arg == (int)p)
00148             break;
00149         else
00150             xode_spool_add(s, arg);
00151     }
00152 
00153     va_end(ap);
00154 
00155     return xode_spool_tostr(s);
00156 }
00157 
00158 
00159 char *xode_strunescape(xode_pool p, char *buf)
00160 {
00161     int i,j=0;
00162     char *temp;
00163 
00164     if (p == NULL || buf == NULL) return(NULL);
00165 
00166     if (strchr(buf,'&') == NULL) return(buf);
00167 
00168     temp = xode_pool_malloc(p,strlen(buf)+1);
00169 
00170     if (temp == NULL) return(NULL);
00171 
00172     for(i=0;i<strlen(buf);i++)
00173     {
00174         if (buf[i]=='&')
00175         {
00176             if (strncmp(&buf[i],"&amp;",5)==0)
00177             {
00178                 temp[j] = '&';
00179                 i += 4;
00180             } else if (strncmp(&buf[i],"&quot;",6)==0) {
00181                 temp[j] = '\"';
00182                 i += 5;
00183             } else if (strncmp(&buf[i],"&apos;",6)==0) {
00184                 temp[j] = '\'';
00185                 i += 5;
00186             } else if (strncmp(&buf[i],"&lt;",4)==0) {
00187                 temp[j] = '<';
00188                 i += 3;
00189             } else if (strncmp(&buf[i],"&gt;",4)==0) {
00190                 temp[j] = '>';
00191                 i += 3;
00192             }
00193         } else {
00194             temp[j]=buf[i];
00195         }
00196         j++;
00197     }
00198     temp[j]='\0';
00199     return(temp);
00200 }
00201 
00202 
00203 char *xode_strescape(xode_pool p, char *buf)
00204 {
00205     int i,j,oldlen,newlen;
00206     char *temp;
00207 
00208     if (p == NULL || buf == NULL) return(NULL);
00209 
00210     oldlen = newlen = strlen(buf);
00211     for(i=0;i<oldlen;i++)
00212     {
00213         switch(buf[i])
00214         {
00215         case '&':
00216             newlen+=5;
00217             break;
00218         case '\'':
00219             newlen+=6;
00220             break;
00221         case '\"':
00222             newlen+=6;
00223             break;
00224         case '<':
00225             newlen+=4;
00226             break;
00227         case '>':
00228             newlen+=4;
00229             break;
00230         }
00231     }
00232 
00233     if(oldlen == newlen) return buf;
00234 
00235     temp = xode_pool_malloc(p,newlen+1);
00236 
00237     if (temp==NULL) return(NULL);
00238 
00239     for(i=j=0;i<oldlen;i++)
00240     {
00241         switch(buf[i])
00242         {
00243         case '&':
00244             memcpy(&temp[j],"&amp;",5);
00245             j += 5;
00246             break;
00247         case '\'':
00248             memcpy(&temp[j],"&apos;",6);
00249             j += 6;
00250             break;
00251         case '\"':
00252             memcpy(&temp[j],"&quot;",6);
00253             j += 6;
00254             break;
00255         case '<':
00256             memcpy(&temp[j],"&lt;",4);
00257             j += 4;
00258             break;
00259         case '>':
00260             memcpy(&temp[j],"&gt;",4);
00261             j += 4;
00262             break;
00263         default:
00264             temp[j++] = buf[i];
00265         }
00266     }
00267     temp[j] = '\0';
00268     return temp;
00269 }


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