source: lib/url.c @ b6a2373

Last change on this file since b6a2373 was b6423a09, checked in by Wilmer van der Gaast <wilmer@…>, at 2007-02-18T23:57:12Z

Little fix copied from Jelmer's integration branch, want to import the rest
after doing this devel release because there are quite a lot of changes in
it.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2001-2005 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* URL/mirror stuff - Stolen from Axel                                  */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#include "url.h"
27
28/* Convert an URL to a url_t structure                                  */
29int url_set( url_t *url, char *set_url )
30{
31        char s[MAX_STRING];
32        char *i;
33       
34        /* protocol://                                                  */
35        if( ( i = strstr( set_url, "://" ) ) == NULL )
36        {
37                url->proto = PROTO_DEFAULT;
38                strncpy( s, set_url, MAX_STRING );
39        }
40        else
41        {
42                if( g_strncasecmp( set_url, "http", i - set_url ) == 0 )
43                        url->proto = PROTO_HTTP;
44                else if( g_strncasecmp( set_url, "https", i - set_url ) == 0 )
45                        url->proto = PROTO_HTTPS;
46                else if( g_strncasecmp( set_url, "socks4", i - set_url ) == 0 )
47                        url->proto = PROTO_SOCKS4;
48                else if( g_strncasecmp( set_url, "socks5", i - set_url ) == 0 )
49                        url->proto = PROTO_SOCKS5;
50                else
51                {
52                        return( 0 );
53                }
54                strncpy( s, i + 3, MAX_STRING );
55        }
56       
57        /* Split                                                        */
58        if( ( i = strchr( s, '/' ) ) == NULL )
59        {
60                strcpy( url->file, "/" );
61        }
62        else
63        {
64                strncpy( url->file, i, MAX_STRING );
65                *i = 0;
66        }
67        strncpy( url->host, s, MAX_STRING );
68       
69        /* Check for username in host field                             */
70        if( strrchr( url->host, '@' ) != NULL )
71        {
72                strncpy( url->user, url->host, MAX_STRING );
73                i = strrchr( url->user, '@' );
74                *i = 0;
75                strcpy( url->host, i + 1 );
76                *url->pass = 0;
77        }
78        /* If not: Fill in defaults                                     */
79        else
80        {
81                *url->user = *url->pass = 0;
82        }
83       
84        /* Password?                                                    */
85        if( ( i = strchr( url->user, ':' ) ) != NULL )
86        {
87                *i = 0;
88                strcpy( url->pass, i + 1 );
89        }
90        /* Port number?                                                 */
91        if( ( i = strchr( url->host, ':' ) ) != NULL )
92        {
93                *i = 0;
94                sscanf( i + 1, "%d", &url->port );
95        }
96        else
97        {
98                if( url->proto == PROTO_HTTP )
99                        url->port = 80;
100                else if( url->proto == PROTO_HTTPS )
101                        url->port = 443;
102                else if( url->proto == PROTO_SOCKS4 || url->proto == PROTO_SOCKS5 )
103                        url->port = 1080;
104        }
105       
106        return( url->port > 0 );
107}
Note: See TracBrowser for help on using the repository browser.