Diff for /libaitio/src/Attic/url.c between versions 1.5 and 1.6

version 1.5, 2011/03/16 16:44:52 version 1.6, 2011/04/20 22:56:32
Line 1 Line 1
 /*************************************************************************  /*************************************************************************
* (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>* (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
*  by Michael Pounov <misho@openbsd-bg.org>*  by Michael Pounov <misho@elwix.org>
 *  *
 * $Author$  * $Author$
 * $Id$  * $Id$
 *  *
*************************************************************************/**************************************************************************
 The ELWIX and AITNET software is distributed under the following
 terms:
 
 All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
 
 Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
         by Michael Pounov <misho@elwix.org>.  All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:
 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. All advertising materials mentioning features or use of this software
    must display the following acknowledgement:
 This product includes software developed by Michael Pounov <misho@elwix.org>
 ELWIX - Embedded LightWeight unIX and its contributors.
 4. Neither the name of AITNET nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.
 */
 #include "global.h"  #include "global.h"
   
   
Line 116  ioURLGet(const char *csURL, struct tagIOURL *url) Line 153  ioURLGet(const char *csURL, struct tagIOURL *url)
 }  }
   
 /*  /*
  * io_MakeArray() Parse and make array of arguments values ...   
  *      (input string will be modified! and output array must be free)  
  * @psArgs = Input arguments line, after execute string is modified!!!  
  * @csDelim = Delimiter(s) for separate  
  * @args = Output array of arguments ... (must be free() after procced function!)  
  * @nargs = Maximum requested count of arguments from input string psArgs  
  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items  
 */  
 inline int  
 io_MakeArray(char * __restrict psArgs, const char *csDelim, char *** __restrict args, int nargs)  
 {  
         char **app;  
         register int i;  
   
         if (!psArgs || !csDelim || !args || !nargs)  
                 return -1;  
         if (!(*args = malloc(sizeof(char*) * nargs))) {  
                 LOGERR;  
                 return -1;  
         } else  
                 memset(*args, 0, sizeof(char*) * nargs);  
   
         for (i = 0, app = *args; app < *args + nargs && (*app = strsep((char **) &psArgs, csDelim));   
                                 **app ? i++ : i, **app ? app++ : app);  
         return i;  
 }  
 /*  
  * io_SizeArray() Parse and calculate size of array  
  * @csArgs = Input arguments line  
  * @csDelim = Delimiter(s) for separate  
  * return: 0 error format; -1 error:: can`t read; >0 ok, number of items  
 */  
 inline int  
 io_SizeArray(const char *csArgs, const char *csDelim)  
 {  
         register int res;  
         char *pos;  
   
         if (!csArgs || !csDelim)  
                 return -1;  
   
         for (res = 1, pos = (char*) csArgs; (pos = strpbrk(pos, csDelim)); res++, pos++);  
         return res;  
 }  
 /*  
  * io_MakeAV() Parse and make attribute/value pair  
  * @csArgs = Input argument line  
  * @csDelim = Delimiter for separate  
  * @psAttr = Output Attribute  
  * @attrLen = Size of attribute array  
  * @psValue = Output Value, if ==NULL this element not present value or not wanted for return  
  * @valLen = Size of value array  
  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items  
 */  
 inline int  
 io_MakeAV(const char * __restrict csArgs, const char *csDelim,   
                 char * __restrict psAttr, int attrLen, char * __restrict psValue, int valLen)  
 {  
         register int ret = 0;  
         char *pos, *psBuf;  
   
         if (!csArgs || !csDelim || !psAttr || !attrLen)  
                 return -1;  
         if (psValue && !valLen)  
                 return -1;  
         else  
                 memset(psValue, 0, valLen);  
         psBuf = strdup(csArgs);  
         if (!psBuf) {  
                 LOGERR;  
                 return -1;  
         }  
   
         pos = strpbrk(psBuf, csDelim);  
         if (pos)  
                 *pos++ = 0;  
         ret++;  
         strlcpy(psAttr, psBuf, attrLen);  
   
         if (pos && *pos) {  
                 ret++;  
                 if (psValue)  
                         strlcpy(psValue, pos, valLen);  
         }  
   
         free(psBuf);  
         return ret;  
 }  
   
 /*  
  * io_Path2File() Parse and make path/filename pair   * io_Path2File() Parse and make path/filename pair
  * @csArgs = Input argument line   * @csArgs = Input argument line
  * @psPath = Output Path, if ==NULL path not returned   * @psPath = Output Path, if ==NULL path not returned
Line 261  int Line 208  int
 ioURLGetValue(struct tagIOURL *url, const char *csAttr, char * __restrict psValue, int valLen)  ioURLGetValue(struct tagIOURL *url, const char *csAttr, char * __restrict psValue, int valLen)
 {  {
         register int i, ret = 0;          register int i, ret = 0;
        char szBuf[BUFSIZ], **items, szElem[2][BUFSIZ];        char szBuf[BUFSIZ], szElem[2][BUFSIZ];
         int len;          int len;
           array_t *items;
   
         if (!url || !csAttr)          if (!url || !csAttr)
                 return -1;                  return -1;
   
         strlcpy(szBuf, url->url_args.value, BUFSIZ);          strlcpy(szBuf, url->url_args.value, BUFSIZ);
        if (io_MakeArray(szBuf, "&", &items, (len = io_SizeArray(szBuf, "&"))) < 1)        if ((len = io_arrayMake(szBuf, 0, "&", &items)) < 1)
                 return ret;                  return ret;
   
        for (i = 0; i < len && items[i]; i++) {        for (i = 0; i < len && items->arr_data[i]; i++) {
                if (io_MakeAV(items[i], "=", szElem[0], BUFSIZ, szElem[1], BUFSIZ) < 1)                if (io_MakeAV(items->arr_data[i], "=", szElem[0], BUFSIZ, szElem[1], BUFSIZ) < 1)
                         continue;                          continue;
   
                 if (!strcmp(szElem[0], csAttr)) {                  if (!strcmp(szElem[0], csAttr)) {
Line 283  ioURLGetValue(struct tagIOURL *url, const char *csAttr Line 231  ioURLGetValue(struct tagIOURL *url, const char *csAttr
                 }                  }
         }          }
   
        free(items);        io_arrayDestroy(&items);
         return ret;          return ret;
 }  }
   

Removed from v.1.5  
changed lines
  Added in v.1.6


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