1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/************************************************************************/
/* */
/* Retrieve fields from URL's */
/* */
/* Implements part of rfc 1738. */
/* */
/************************************************************************/
# include "appUtilConfig.h"
# include <string.h>
# include <appUrl.h>
# include <appDebugon.h>
/************************************************************************/
/* */
/* Extract the scheme part from a URL. */
/* */
/* Of failure return -1. Otherwise return the number of characters */
/* consumed including the colon such that url+ rval ponts to the */
/* scheme specific part. */
/* */
/************************************************************************/
int appUrlGetScheme( char * scheme,
int schemeLen,
const char * url )
{
const char * s= url;
int used;
int made;
used= made= 0;
for (;;)
{
if ( made >= schemeLen )
{ return -1; }
if ( *s >= 'A' && *s <= 'Z' )
{ *(scheme++)= *(s++)- 'A'+ 'a'; used++; made++; continue; }
if ( ( *s >= 'a' && *s <= 'z' ) ||
*s == '+' ||
*s == '-' ||
*s == '.' )
{ *(scheme++)= *(s++); used++; made++; continue; }
if ( *s == ':' )
{ *(scheme++)= '\0'; used++; break; }
return -1;
}
return used;
}
/************************************************************************/
/* */
/* Extract the host part from a URL. */
/* */
/************************************************************************/
static int appUrlGetHost( int * pMade,
char * host,
int hostLen,
const char * s,
int xterm )
{
int used;
int made;
used= made= 0;
for (;;)
{
if ( made >= hostLen )
{ LLDEB(made,hostLen); return -1; }
if ( *s >= 'A' && *s <= 'Z' )
{ *(host++)= *(s++)- 'A'+ 'a'; used++; made++; continue; }
if ( ( *s >= 'a' && *s <= 'z' ) ||
( *s >= '0' && *s <= '9' ) ||
*s == '+' ||
*s == '-' ||
*s == '.' )
{ *(host++)= *(s++); used++; made++; continue; }
if ( *s == xterm || *s == '\0' || *s == '/' )
{ *(host++)= '\0'; break; }
SDEB(s); return -1;
}
*pMade += made; return used;
}
/************************************************************************/
/* */
/* Extract the host/port combination from a HTTP URL. */
/* */
/* Return the number of characters consumed, including the terminating */
/* slash, such that schemeSpecific+ used points to the end of the */
/* string or to the hpath?search part. */
/* */
/************************************************************************/
int appUrlGetHttpHostPort( char * host,
int hostLen,
char * port,
int portLen,
const char * schemeSpecific )
{
const char * s= schemeSpecific;
int used;
int made;
int done;
if ( s[0] != '/' || s[1] != '/' )
{ SDEB(s); return -1; }
s += 2; used= 2;
made= 0;
done= appUrlGetHost( &made, host, hostLen, s, ':' );
if ( done < 0 )
{ LDEB(done); return -1; }
s += done; used += done;
if ( *s == ':' )
{
s++; used++;
made= 0;
for (;;)
{
if ( made >= hostLen )
{ LLDEB(made,hostLen); return -1; }
if ( *s >= '0' && *s <= '9' )
{ *(port++)= *(s++); used++; made++; continue; }
if ( *s == '\0' || *s == '/' )
{ *(port++)= '\0'; break; }
SDEB(s); return -1;
}
}
else{ strcpy( port, "80" ); }
/*
if ( *s == '/' )
{ s++; used++; }
*/
return used;
}
/************************************************************************/
/* */
/* Extract the host part from a FILE URL. */
/* */
/* Return the number of characters consumed, excluding the terminating */
/* slash, such that schemeSpecific+ used points to the end of the */
/* string or to the path part. */
/* */
/************************************************************************/
int appUrlGetFileHost( char * host,
int hostLen,
const char * schemeSpecific )
{
const char * s= schemeSpecific;
int used;
int made;
int done;
if ( s[0] != '/' || s[1] != '/' )
{ SDEB(s); return -1; }
s += 2; used= 2;
made= 0;
done= appUrlGetHost( &made, host, hostLen, s, '/' );
if ( done < 0 )
{ LDEB(done); return -1; }
s += done; used += done;
return used;
}
|