Diff for /libaitio/src/Attic/url.c between versions 1.3 and 1.4

version 1.3, 2010/03/22 15:21:20 version 1.4, 2011/02/10 22:01:34
Line 16 Line 16
  * return: 0 error format not find tech:// and return URL like path;    * return: 0 error format not find tech:// and return URL like path; 
                 -1 error:: can`t read; >0 ok, up bits for known elements                  -1 error:: can`t read; >0 ok, up bits for known elements
 */  */
int ioURLGet(const char *csURL, struct tagIOURL *url)int
 ioURLGet(const char *csURL, struct tagIOURL *url)
 {  {
         char *pos, *at, *cl, *sl;          char *pos, *at, *cl, *sl;
         int ret = 0;          int ret = 0;
Line 123  int ioURLGet(const char *csURL, struct tagIOURL *url) Line 124  int ioURLGet(const char *csURL, struct tagIOURL *url)
  * @nargs = Maximum requested count of arguments from input string psArgs   * @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   * 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)inline int
 io_MakeArray(char * __restrict psArgs, const char *csDelim, char *** __restrict args, int nargs)
 {  {
         char **app;          char **app;
         register int i;          register int i;
Line 146  inline int io_MakeArray(char * __restrict psArgs, cons Line 148  inline int io_MakeArray(char * __restrict psArgs, cons
  * @csDelim = Delimiter(s) for separate   * @csDelim = Delimiter(s) for separate
  * return: 0 error format; -1 error:: can`t read; >0 ok, number of items   * return: 0 error format; -1 error:: can`t read; >0 ok, number of items
 */  */
inline int io_SizeArray(const char *csArgs, const char *csDelim)inline int
 io_SizeArray(const char *csArgs, const char *csDelim)
 {  {
         register int res;          register int res;
         char *pos;          char *pos;
Line 167  inline int io_SizeArray(const char *csArgs, const char Line 170  inline int io_SizeArray(const char *csArgs, const char
  * @valLen = Size of value array   * @valLen = Size of value array
  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items   * 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, inline int
 io_MakeAV(const char * __restrict csArgs, const char *csDelim, 
                 char * __restrict psAttr, int attrLen, char * __restrict psValue, int valLen)                  char * __restrict psAttr, int attrLen, char * __restrict psValue, int valLen)
 {  {
         register int ret = 0;          register int ret = 0;
Line 210  inline int io_MakeAV(const char * __restrict csArgs, c Line 214  inline int io_MakeAV(const char * __restrict csArgs, c
  * @fileLen = Size of file array   * @fileLen = Size of file array
  * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items   * return: 0 error format; -1 error:: can`t read; >0 ok, number of readed items
 */  */
inline int io_Path2File(const char * __restrict csArgs, char * __restrict psPath, int pathLen, inline int
 io_Path2File(const char * __restrict csArgs, char * __restrict psPath, int pathLen, 
                 char * __restrict psFile, int fileLen)                  char * __restrict psFile, int fileLen)
 {  {
         char *pos, *psBuf;          char *pos, *psBuf;
Line 252  inline int io_Path2File(const char * __restrict csArgs Line 257  inline int io_Path2File(const char * __restrict csArgs
  * @valLen = Size of psValue array   * @valLen = Size of psValue array
  * return: 0 error attribute not find; -1 error:: can`t read; >0 ok, find at position   * return: 0 error attribute not find; -1 error:: can`t read; >0 ok, find at position
 */  */
int ioURLGetValue(struct tagIOURL *url, const char *csAttr, char * __restrict psValue, int valLen)int
 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], **items, szElem[2][BUFSIZ];
Line 288  int ioURLGetValue(struct tagIOURL *url, const char *cs Line 294  int ioURLGetValue(struct tagIOURL *url, const char *cs
  * @valLen = Size of psValue array   * @valLen = Size of psValue array
  * return: -1 error:: can`t read; 0 ok   * return: -1 error:: can`t read; 0 ok
 */  */
int ioURLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen)int
 ioURLGetFile(struct tagIOURL *url, char * __restrict psValue, int valLen)
 {  {
         if (!url || !psValue || !valLen)          if (!url || !psValue || !valLen)
                 return -1;                  return -1;
Line 300  int ioURLGetFile(struct tagIOURL *url, char * __restri Line 307  int ioURLGetFile(struct tagIOURL *url, char * __restri
         if (!*psValue)          if (!*psValue)
                 strlcpy(psValue, "/", valLen);                  strlcpy(psValue, "/", valLen);
         return 0;          return 0;
   }
   
   // ------------------------------------------
   
   /*
    * ioXMLGet() Parse and get data from input XML request string [ns:]container[|attribute[=value]][?data]
    * @csXML = Input XML request line
    * @xml = Output parsed XML request
    * return: 0 error format incorrect, -1 error:: can`t read; >0 ok readed elements bits
   */
   int
   ioXMLGet(const char *csXML, struct tagReqXML *xml)
   {
           char *pos, *p, *end;
           int ret = 0;
   
           if (!csXML || !xml)
                   return -1;
           else
                   memset(xml, 0, sizeof *xml);
   
           strlcpy((char*) xml->xml_line, csXML, BUFSIZ);
           // if namespace present
           if ((pos = strchr((char*) xml->xml_line, ':'))) {
                   xml->xml_namespace.value = (char*) xml->xml_line;
                   xml->xml_namespace.vallen = pos - (char*) xml->xml_line;
                   if (xml->xml_namespace.vallen)
                           ret |= 1;
                   *pos++ = 0;
           } else
                   pos = (char*) xml->xml_line;
           // if container is path
           if (*pos == '/') {
                   xml->xml_node.path.value = pos;
                   xml->xml_node.path.vallen = strlen(pos);
                   if (!xml->xml_node.path.vallen)
                           ret = 0;
                   else
                           ret |= 32;
                   return ret;
           } else {
           // container
                   xml->xml_node.container.value = pos;
                   xml->xml_node.container.vallen = strlen(pos);
                   if (!xml->xml_node.container.vallen)
                           return 0;
                   else
                           ret |= 2;
           }
           end = strchr(pos, '?');
           // if attribute present
           if (pos && (p = strchr(pos, '|')) && (!end || end > p)) {
                   pos = p;
                   *pos++ = 0;
                   xml->xml_node.container.vallen = strlen(xml->xml_node.container.value);
                   if (!xml->xml_node.container.vallen)
                           return 0;
   
                   xml->xml_attribute.value = pos;
                   xml->xml_attribute.vallen = strlen(pos);
                   if (xml->xml_attribute.vallen)
                           ret |= 4;
           }
           // if value present
           if (pos && (p = strchr(pos, '=')) && (!end || end > p)) {
                   if (!(ret & 4))
                           return 0;
                   else
                           pos = p;
                   *pos++ = 0;
                   xml->xml_attribute.vallen = strlen(xml->xml_attribute.value);
                   if (!xml->xml_attribute.vallen)
                           return 0;
   
                   xml->xml_value.value = pos;
                   xml->xml_value.vallen = strlen(pos);
                   if (xml->xml_value.vallen)
                           ret |= 8;
           }
           // if data present
           if (pos && end) {
                   if (ret < 2)
                           return 0;
                   else
                           pos = end;
                   *pos++ = 0;
                   if (ret & 8) {
                           xml->xml_value.vallen = strlen(xml->xml_value.value);
                           if (!xml->xml_value.vallen)
                                   return 0;
                   } else if (ret & 4) {
                           xml->xml_attribute.vallen = strlen(xml->xml_attribute.value);
                           if (!xml->xml_attribute.vallen)
                                   return 0;
                   } else if (ret & 2) {
                           xml->xml_node.container.vallen = strlen(xml->xml_node.container.value);
                           if (!xml->xml_node.container.vallen)
                                   return 0;
                   } else
                           return 0;
   
                   xml->xml_data.value = pos;
                   xml->xml_data.vallen = strlen(pos);
                   if (xml->xml_data.vallen)
                           ret |= 16;
           }
   
           return ret;
 }  }

Removed from v.1.3  
changed lines
  Added in v.1.4


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