24 #define checkUrlValue( data, dataLength, minLength, maxLength ) \
25 ( ( data == NULL && dataLength == 0 ) || \
27 dataLength >= minLength && dataLength <= maxLength ) )
41 if( !checkUrlValue( urlInfo->schema, urlInfo->
schemaLen,
44 if( !checkUrlValue( urlInfo->userInfo, urlInfo->
userInfoLen,
47 if( !checkUrlValue( urlInfo->location, urlInfo->
locationLen,
52 if( urlInfo->host == NULL || \
68 static
int checkSchema(
IN_BUFFER( schemaLen )
const void *schema,
69 IN_RANGE( 2, 16 )
const int schemaLen,
76 const int schemaLength;
79 static const URL_SCHEMA_INFO
FAR_BSS urlSchemaInfo[] = {
96 REQUIRES( schemaLen >= 2 && schemaLen <= 16 );
108 if( urlSchemaInfo[ i ].schemaLength == schemaLen && \
109 !
strCompare( urlSchemaInfo[ i ].schema, schema, schemaLen ) )
113 type = urlSchemaInfo[ i ].type;
124 switch( urlTypeHint )
188 const char *strPtr, *hostName, *location;
201 memset( urlInfo, 0,
sizeof(
URL_INFO ) );
206 for( offset = 0; offset <
urlLen; offset++ )
210 if( ch <= 0 || ch > 0x7F || !
isPrint( ch ) )
221 if( ( offset =
strFindStr( strPtr, strLen,
"://", 3 ) ) >= 0 )
224 if( offset < 2 || offset > 8 )
227 urlInfo->schema = strPtr;
228 urlInfo->schemaLen =
offset;
229 strLen = strExtract( &strPtr, strPtr, offset, strLen );
234 status = checkSchema( urlInfo->schema, urlInfo->schemaLen,
235 &urlInfo->type, urlTypeHint );
241 if( ( offset = strFindCh( strPtr, strLen,
'@' ) ) >= 0 )
243 const char *userInfo;
247 if( offset < 1 || offset > MAX_URL_SIZE )
249 userInfoLen = strExtract( &userInfo, strPtr, 0, offset );
252 urlInfo->userInfo = userInfo;
253 urlInfo->userInfoLen = userInfoLen;
256 strLen = strExtract( &strPtr, strPtr, offset + 1, strLen );
257 if( strLen < MIN_DNS_SIZE || strLen > MAX_URL_SIZE )
266 if( *strPtr ==
'[' && \
267 ( strLen != 12 ||
strCompare( strPtr,
"[Autodetect]", 12 ) ) )
272 if( ( offset = strFindCh( strPtr, strLen,
']' ) ) <= 0 )
274 if( offset < 2 || offset > strLen - 1 || offset > CRYPT_MAX_TEXTSIZE )
285 hostNameLen = offset + 1;
293 hostNameLen = strExtract( &hostName, strPtr, 1, offset );
304 offset = strFindCh( strPtr, strLen,
':' );
305 offset2 = strFindCh( strPtr, strLen,
'/' );
312 offset =
min( offset, offset2 );
318 urlInfo->host = strPtr;
319 urlInfo->hostLen =
strLen;
321 ENSURES( sanityCheckURL( urlInfo ) );
328 hostNameLen = strExtract( &hostName, strPtr, 0, offset );
331 if( hostNameLen < minLen || hostNameLen > CRYPT_MAX_TEXTSIZE )
333 urlInfo->host = hostName;
334 urlInfo->hostLen = hostNameLen;
337 if( offset >= strLen )
339 ENSURES( sanityCheckURL( urlInfo ) );
343 strLen = strExtract( &strPtr, strPtr, offset, strLen );
344 if( strLen == 1 && *strPtr ==
'/' )
347 ENSURES( sanityCheckURL( urlInfo ) );
351 if( strLen < 3 || strLen > MAX_URL_SIZE )
357 int portStrLen, port;
360 strLen = strExtract( &strPtr, strPtr, 1, strLen );
361 if( strLen < 2 || strLen > MAX_URL_SIZE )
367 portStrLen < strLen &&
isDigit( strPtr[ portStrLen ] );
369 if( portStrLen < 2 || portStrLen > 8 )
371 status = strGetNumeric( strPtr, portStrLen, &port,
375 urlInfo->port = port;
378 if( strLen == portStrLen )
380 ENSURES( sanityCheckURL( urlInfo ) );
384 strLen = strExtract( &strPtr, strPtr, portStrLen, strLen );
385 if( strLen == 1 && *strPtr ==
'/' )
388 ENSURES( sanityCheckURL( urlInfo ) );
392 if( strLen < 3 || strLen > MAX_URL_SIZE )
402 locationLen = strExtract( &location, strPtr, 0, strLen );
403 if( locationLen < 3 || locationLen > MAX_URL_SIZE )
405 urlInfo->location = location;
406 urlInfo->locationLen = locationLen;
408 ENSURES( sanityCheckURL( urlInfo ) );