Diff for /libaitwww/src/tools.c between versions 1.2 and 1.2.6.4

version 1.2, 2012/03/10 00:26:49 version 1.2.6.4, 2012/07/31 23:11:47
Line 44  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF TH Line 44  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF TH
 SUCH DAMAGE.  SUCH DAMAGE.
 */  */
 #include "global.h"  #include "global.h"
 #include "tools.h"  
   
   
   /*
    * www_cmp() - Compare two string
    *
    * @ct = content text from www
    * @s = string
    * return: 0 are equal or !0 are different
    */
 int  int
 www_cmp(const char *ct, const char *s)  www_cmp(const char *ct, const char *s)
 {  {
Line 54  www_cmp(const char *ct, const char *s) Line 60  www_cmp(const char *ct, const char *s)
   
         assert(ct && s);          assert(ct && s);
   
        while (isspace(*ct))        while (isspace((int) *ct))
                 ct++;                  ct++;
   
         if (!(sc = strchr(ct, ';')))          if (!(sc = strchr(ct, ';')))
                 sc = strchr(ct, '\x0');                  sc = strchr(ct, '\x0');
        while (isspace(*(sc - 1)))        while (isspace((int) *(sc - 1)))
                 sc--;                  sc--;
   
         if (strlen(s) != sc - ct)          if (strlen(s) != sc - ct)
Line 67  www_cmp(const char *ct, const char *s) Line 73  www_cmp(const char *ct, const char *s)
         return strncasecmp(ct, s, sc - ct);          return strncasecmp(ct, s, sc - ct);
 }  }
   
   /*
    * www_cmptype() - Compare context type
    *
    * @ct = content text from www
    * @type = content type
    * return: 0 are equal or !0 are different
    */
 int  int
 www_cmptype(const char *ct, const char *type)  www_cmptype(const char *ct, const char *type)
 {  {
Line 74  www_cmptype(const char *ct, const char *type) Line 87  www_cmptype(const char *ct, const char *type)
   
         assert(ct && type);          assert(ct && type);
   
        while (isspace(*ct))        while (isspace((int) *ct))
                 ct++;                  ct++;
   
         if (!(sl = strchr(ct, '/')))          if (!(sl = strchr(ct, '/')))
Line 85  www_cmptype(const char *ct, const char *type) Line 98  www_cmptype(const char *ct, const char *type)
         return strncasecmp(ct, type, sl - ct);          return strncasecmp(ct, type, sl - ct);
 }  }
   
char */*
  * www_getpair() - Get AV pair from WWW query string
  *
  * @str = query string
  * @delim = delimiter
  * return: NULL error or AV pair, must be io_free() after use!
  */
 ait_val_t *
 www_getpair(char ** __restrict str, const char *delim)  www_getpair(char ** __restrict str, const char *delim)
 {  {
        char *tr, *s = NULL;        char *tr;
         int cx;          int cx;
           ait_val_t *s;
   
         assert(str && *str && delim);          assert(str && *str && delim);
   
        cx = strcspn(*str, delim);        s = io_allocVar();
        tr = *str + cx; 
 
        s = malloc(cx + 1); 
         if (!s) {          if (!s) {
                LOGERR;                www_SetErr(io_GetErrno(), "%s", io_GetError());
                 return NULL;                  return NULL;
         } else {  
                 strncpy(s, *str, cx);  
                 s[cx] = 0;  
         }          }
   
        *str = tr;        cx = strcspn(*str, delim);
        if (**str)        tr = *str + cx;
                (*str)++;        if (*tr)
                 *tr++ = 0;
   
           AIT_SET_STR(s, *str);
   
           *str = tr;
         return s;          return s;
 }  }
   
   /*
    * www_x2c() - Hex from string to digit
    *
    * @str = string
    * return: digit
    */
 inline char  inline char
 www_x2c(const char *str)  www_x2c(const char *str)
 {  {
Line 126  www_x2c(const char *str) Line 151  www_x2c(const char *str)
         return digit;          return digit;
 }  }
   
   /*
    * www_unescape() - Unescape/decode WWW query string to host string
    *
    * @str = string
    * return: none
    */
 inline void  inline void
 www_unescape(char * __restrict str)  www_unescape(char * __restrict str)
 {  {
         register int i, j;          register int i, j;
   
        assert(str);        if (!str)
                 return;
   
         for (i = j = 0; str[j]; i++, j++) {          for (i = j = 0; str[j]; i++, j++) {
                 str[i] = str[j];                  str[i] = str[j];

Removed from v.1.2  
changed lines
  Added in v.1.2.6.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>