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

JStr.c File Reference

#include <sysdep.h>
#include "libjwgc.h"
#include "libxode.h"

Go to the source code of this file.

Defines

#define iconv_t   libiconv_t

Typedefs

typedef void * iconv_t

Functions

iconv_t iconv_open (const char *tocode, const char *fromcode)
size_t iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
int iconv_close (iconv_t cd)
const char * locale_charset (void)
char * j_strdup (const char *str)
char * j_strcat (char *dest, char *txt)
int j_strcmp (const char *a, const char *b)
int j_strcasecmp (const char *a, const char *b)
int j_strncmp (const char *a, const char *b, int i)
int j_strncasecmp (const char *a, const char *b, int i)
int j_strlen (const char *a)
int j_atoi (const char *a, int def)
void trim_message (char *str)
char * spool_print (xode_spool s)
char * spools (xode_pool p,...)
int str_clear_unprintable (char *in, char **out) const
int str_to_unicode (char *in, char **out) const
int unicode_to_str (char *in, char **out) const


Define Documentation

#define iconv_t   libiconv_t
 

Definition at line 52 of file JStr.c.

Referenced by str_to_unicode(), and unicode_to_str().


Typedef Documentation

typedef void* iconv_t
 

Definition at line 53 of file JStr.c.


Function Documentation

size_t iconv iconv_t  cd,
const char **  inbuf,
size_t *  inbytesleft,
char **  outbuf,
size_t *  outbytesleft
 

Referenced by str_to_unicode(), and unicode_to_str().

int iconv_close iconv_t  cd  ) 
 

Referenced by str_to_unicode(), and unicode_to_str().

iconv_t iconv_open const char *  tocode,
const char *  fromcode
 

Referenced by str_to_unicode(), and unicode_to_str().

int j_atoi const char *  a,
int  def
 

Definition at line 141 of file JStr.c.

00142 {
00143         if (a == NULL)
00144                 return def;
00145         else
00146                 return atoi(a);
00147 }

int j_strcasecmp const char *  a,
const char *  b
 

Definition at line 105 of file JStr.c.

References NULL.

00106 {
00107         if (a == NULL || b == NULL)
00108                 return -1;
00109         else
00110                 return strcasecmp(a, b);
00111 }

char* j_strcat char *  dest,
char *  txt
 

Definition at line 75 of file JStr.c.

Referenced by spool_print().

00076 {
00077         if (!txt)
00078                 return (dest);
00079 
00080         while (*txt)
00081                 *dest++ = *txt++;
00082         *dest = '\0';
00083 
00084         return (dest);
00085 }

int j_strcmp const char *  a,
const char *  b
 

Definition at line 88 of file JStr.c.

References NULL.

Referenced by jabpacket_subtype(), and jabutil_regkey().

00089 {
00090         if (a == NULL || b == NULL)
00091                 return -1;
00092 
00093         while (*a == *b && *a != '\0' && *b != '\0') {
00094                 a++;
00095                 b++;
00096         }
00097 
00098         if (*a == *b)
00099                 return 0;
00100 
00101         return -1;
00102 }

char* j_strdup const char *  str  ) 
 

Definition at line 66 of file JStr.c.

00067 {
00068         if (str == NULL)
00069                 return NULL;
00070         else
00071                 return strdup(str);
00072 }

int j_strlen const char *  a  ) 
 

Definition at line 132 of file JStr.c.

00133 {
00134         if (a == NULL)
00135                 return 0;
00136         else
00137                 return strlen(a);
00138 }

int j_strncasecmp const char *  a,
const char *  b,
int  i
 

Definition at line 123 of file JStr.c.

References NULL.

00124 {
00125         if (a == NULL || b == NULL)
00126                 return -1;
00127         else
00128                 return strncasecmp(a, b, i);
00129 }

int j_strncmp const char *  a,
const char *  b,
int  i
 

Definition at line 114 of file JStr.c.

References NULL.

00115 {
00116         if (a == NULL || b == NULL)
00117                 return -1;
00118         else
00119                 return strncmp(a, b, i);
00120 }

const char* locale_charset void   ) 
 

Referenced by str_to_unicode(), and unicode_to_str().

char* spool_print xode_spool  s  ) 
 

Definition at line 164 of file JStr.c.

References xode_spool_node::c, xode_spool_struct::first, j_strcat(), xode_spool_struct::len, xode_spool_node::next, NULL, xode_spool_struct::p, xode_pool_malloc(), and xode_spool.

Referenced by spools().

00165 {
00166         char *ret, *tmp;
00167         struct xode_spool_node *next;
00168 
00169         if (s == NULL || s->len == 0 || s->first == NULL)
00170                 return NULL;
00171 
00172         ret = xode_pool_malloc(s->p, s->len + 1);
00173         *ret = '\0';
00174 
00175         next = s->first;
00176         tmp = ret;
00177         while (next != NULL) {
00178                 tmp = j_strcat(tmp, next->c);
00179                 next = next->next;
00180         }
00181 
00182         return ret;
00183 }

char* spools xode_pool  p,
  ...
 

Definition at line 187 of file JStr.c.

References spool_print(), xode_pool, xode_spool, xode_spool_add(), and xode_spool_newfrompool().

Referenced by xode2file().

00188 {
00189         va_list ap;
00190         xode_spool s;
00191         char *arg = NULL;
00192 
00193         if (p == NULL)
00194                 return NULL;
00195 
00196         s = xode_spool_newfrompool(p);
00197 
00198         va_start(ap, p);
00199 
00200         /* loop till we hit our end flag, the first arg */
00201         while (1) {
00202                 arg = va_arg(ap, char *);
00203                 if ((xode_pool) arg == p)
00204                         break;
00205                 else
00206                         xode_spool_add(s, arg);
00207         }
00208 
00209         va_end(ap);
00210 
00211         return spool_print(s);
00212 }

int str_clear_unprintable char *  in,
char **  out
const
 

Definition at line 215 of file JStr.c.

References dExecution, and dprintf().

Referenced by str_to_unicode().

00218 {
00219         int i;
00220 
00221         dprintf(dExecution, "Clearing unprintable characters...\n");
00222         *out = (char *)malloc(sizeof(char) * (strlen(in) + 1));
00223         for (i = 0; i < strlen(in); i++) {
00224                 if (in[i] != '\n' && !isprint(in[i])) {
00225                         (*out)[i] = ' ';
00226                 }
00227                 else {
00228                         (*out)[i] = in[i];
00229                 }
00230         }
00231 
00232         return 1;
00233 }

int str_to_unicode char *  in,
char **  out
const
 

Definition at line 236 of file JStr.c.

References dExecution, dprintf(), errno, iconv(), iconv_close(), iconv_open(), iconv_t, locale_charset(), and str_clear_unprintable().

Referenced by main().

00239 {       
00240 #ifdef HAVE_LIBICONV
00241         iconv_t ic;
00242         size_t ret;
00243         int inlen, outlen;
00244         char *inptr, *outbuf, *outptr;
00245         extern int errno;
00246         
00247         dprintf(dExecution, "Converting localized string to unicode...\n");
00248         ic = iconv_open("UTF-8", (char *)locale_charset());
00249         if (ic == (iconv_t)-1) {
00250                 return str_clear_unprintable(in, out);
00251         }
00252         
00253         inptr = (char *)in;
00254         inlen = strlen(in);
00255         /* horrible handling of out buf sizing, fix me at some point */
00256         outbuf = (char *)malloc(sizeof(char) * ((inlen * 4) + 1));
00257         outbuf[0] = '\0';
00258         outptr = outbuf;
00259         outlen = inlen;
00260         do {
00261                 ret = iconv(ic,
00262                                 (const char **)&inptr, (size_t *)&inlen,
00263                                 (char **)&outptr, (size_t *)&outlen);
00264                 if (ret == (size_t) -1) {
00265                         if (errno == EINVAL) {
00266                                 continue;
00267                         }
00268                 }
00269                 outptr[inlen] = '\0';
00270         } while(inlen > 0);
00271         iconv_close(ic);
00272         
00273         *out = outbuf;
00274         return 1;
00275 #else
00276         return str_clear_unprintable(in, out);
00277 #endif /* HAVE_LIBICONV */
00278 }

void trim_message char *  str  ) 
 

Definition at line 150 of file JStr.c.

References dExecution, and dprintf().

Referenced by jab_on_packet_handler(), and jwg_on_event_handler().

00152 {
00153         int pos = strlen(str);
00154         
00155         dprintf(dExecution, "Trim start position at %d.\n", pos);
00156         while (pos >= 0 && (isspace(str[pos]) || iscntrl(str[pos]))) {
00157                 dprintf(dExecution, "Trimming position %d.\n", pos);
00158                 str[pos] = '\0';
00159                 pos--;
00160         }
00161 }

int unicode_to_str char *  in,
char **  out
const
 

Definition at line 281 of file JStr.c.

References dExecution, dprintf(), errno, iconv(), iconv_close(), iconv_open(), iconv_t, and locale_charset().

Referenced by decode_notice(), and jab_on_packet_handler().

00284 {       
00285 #ifdef HAVE_LIBICONV
00286         iconv_t ic;
00287         size_t ret;
00288         int inlen, outlen;
00289         char *inptr, *outbuf, *outptr;
00290         extern int errno;
00291         
00292         dprintf(dExecution, "Converting unicode to localized string...\n");
00293         ic = iconv_open((char *)locale_charset(), "UTF-8");
00294         if (ic == (iconv_t)-1) {
00295                 *out = (char *)strdup(in);
00296                 return 1;
00297         }
00298         
00299         inptr = (char *)in;
00300         inlen = strlen(in);
00301         /* horrible handling of out buf sizing, fix me at some point */
00302         outbuf = (char *)malloc(sizeof(char) * (inlen + 1));
00303         outbuf[0] = '\0';
00304         outptr = outbuf;
00305         outlen = inlen;
00306         do {
00307                 ret = iconv(ic,
00308                                 (const char **)&inptr, (size_t *)&inlen,
00309                                 (char **)&outptr, (size_t *)&outlen);
00310                 if (ret == (size_t) -1) {
00311                         if (errno == EINVAL) {
00312                                 continue;
00313                         }
00314                 }
00315                 outptr[inlen] = '\0';
00316         } while(inlen > 0);
00317         iconv_close(ic);
00318 
00319         *out = outbuf;
00320         return 1;
00321 #else
00322         return in;
00323 #endif /* HAVE_LIBICONV */
00324 }



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

Source Perspective by Fisheye