Diff for /libaitio/src/Attic/url.c between versions 1.1 and 1.1.2.1

version 1.1, 2010/03/02 15:10:19 version 1.1.2.1, 2010/03/02 15:10:19
Line 0 Line 1
   /*************************************************************************
   * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
   *  by Michael Pounov <misho@openbsd-bg.org>
   *
   * $Author$
   * $Id$
   *
   *************************************************************************/
   #include "global.h"
   
   
   /*
    * ioURLGet() Parse and get data from input URL
    * @csURL = Input URL line
    * @url = Output parsed URL
    * return: 0 error format not find tech:// and return URL like path; 
                   -1 error:: can`t read; >0 ok, up bits for known elements
   */
   int ioURLGet(const char *csURL, struct tagIOURL *url)
   {
           char *pos, *at, *cl, *sl;
           int ret = 0;
   
           if (!url)
                   return -1;
           else
                   memset(url, 0, sizeof(*url));
   
           strlcpy((char*) url->url_line, csURL, BUFSIZ);
           // Tech
           if (!(pos = strstr((char*) url->url_line, "://"))) {
                   url->url_path.vallen = strlen((char*) url->url_line);
                   url->url_path.value = (char*) url->url_line;
                   return ret;
           } else {
                   url->url_tech.value = (char*) url->url_line;
                   url->url_tech.vallen = pos - (char*) url->url_line;
                   if (url->url_tech.vallen)
                           ret |= 1;
   
                   *pos = 0;
                   pos += 3;
           }
   
           // User
           if ((at = strchr(pos, '@'))) {
                   *at++ = 0;
                   // Pass
                   if ((cl = strchr(pos, ':'))) {
                           *cl++ = 0;
   
                           url->url_pass.value = cl;
                           url->url_pass.vallen = at - cl - 1;
                           if (url->url_pass.vallen)
                                   ret |= 4;
                   } else
                           cl = at;
   
                   url->url_user.value = pos;
                   url->url_user.vallen = cl - pos - 1;
                   if (url->url_user.vallen)
                           ret |= 2;
   
                   pos = at;
           }
   
           // Host
           if ((sl = strchr(pos, '/')))
                   *sl++ = 0;
           else
                   sl = pos + strlen(pos) + 1;
           // Port
           if ((cl = strchr(pos, ':'))) {
                   *cl++ = 0;
   
                   url->url_port.value = cl;
                   url->url_port.vallen = sl - cl - 1;
                   if (url->url_port.vallen)
                           ret |= 16;
           } else
                   cl = sl;
   
           url->url_host.value = pos;
           url->url_host.vallen = cl - pos - 1;
           if (url->url_host.vallen)
                   ret |= 8;
   
           pos = sl;
   
           // Args
           if ((at = strchr(pos, '?'))) {
                   *at++ = 0;
   
                   url->url_args.value = at;
                   url->url_args.vallen = strlen(at);
                   if (url->url_args.vallen)
                           ret |= 64;
           } else
                   at = pos + strlen(pos) + 1;
   
           // Path
           url->url_path.value = pos;
           url->url_path.vallen = at - pos - 1;
           if (url->url_path.vallen)
                   ret |= 32;
   
           pos = at + strlen(at);
   
           // Reserved
           url->url_reserved = pos;
           if (*pos)
                   ret |= 128;
   
           return ret;
   }

Removed from v.1.1  
changed lines
  Added in v.1.1.2.1


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