📄 url.h
字号:
/*
* Copyright (C) Ericsson Mobile Communications AB, 2000.
* Licensed to AU-System AB.
* All rights reserved.
*
* This software is covered by the license agreement between
* the end user and AU-System AB, and may be used and copied
* only in accordance with the terms of the said agreement.
*
* Neither Ericsson Mobile Communications AB nor AU-System AB
* assumes any responsibility or liability for any errors or inaccuracies in
* this software, or any consequential, incidental or indirect damage arising
* out of the use of the Generic WAP Client software.
*/
/*
* URL.h
*
* Library of routines for handling URLs.
*
* Created by Anders Edenbrandt, Mon Mar 29 16:50:15 1999.
*
* Revision history:
* 991123, AED: added new function, b_IsPrefix.
* 991123, AED: parsing all URIs as generic
* 001017, IPN: the function b_EscapeBlanks is now also accessable externt from this file.
* 010516, IPN: added new function, w_wmlVariableEscape.
*
*/
#ifndef _URL_h
#define _URL_h
#include "cmmnrsrc.h"
#define NO_COMP 0
#define SCHEME_COMP 0x1
#define USERINFO_COMP 0x2
#define HOST_COMP 0x4
#define PORT_COMP 0x8
#define AUTHORITY_COMP USERINFO_COMP | HOST_COMP | PORT_COMP
#define PATH_COMP 0x10
#define QUERY_COMP 0x40
#define FRAG_COMP 0x80
#define ALL_COMP 0xFF
/* The Scheme type */
typedef enum SchemeEnum {
Scheme_empty = 0,
Scheme_http = 1,
Scheme_https = 2,
Scheme_file = 3,
Scheme_wtai = 4,
Scheme_about = 5,
Scheme_function = 6,
Scheme_wapdevice = 7,
Scheme_unsupported = 90,
Scheme_unknown = 99
} Scheme;
#define NUM_URL_PARTS 8
#define SCHEME_PART 0
#define AUTHORITY_PART 1
#define PATH_PART 2
#define QUERY_PART 3
#define FRAGMENT_PART 4
#define USERINFO_PART 5
#define HOST_PART 6
#define PORT_PART 7
/* The URL type */
typedef struct URL_s {
Scheme scheme_type;
BYTE *s[NUM_URL_PARTS];
UINT16 len[NUM_URL_PARTS];
} URL;
/*
* Return the scheme type named by the given string. Returns Scheme_unknown
* if its not one of the predefined types.
*/
Scheme
Scheme_FromString (BYTE *sch);
/*
* Return a string representation of the Scheme value.
* NOTE: the caller must NOT modify or deallocate the returned string!
*/
const BYTE *
Scheme_ToString (Scheme scheme);
/*
* Sets all fields in the URL struct to NULL and 0, respectively.
*/
void
URL_Clear (URL *url);
/*
* Compute a hash value from a URL and store it in the location pointed
* to by "hv". All equivalent URLs will hash to the same value,
* but two non-equal URLs may also have the same hash value. However,
* the probability of a collision is small.
* Returns FALSE on error, TRUE otherwise.
*/
BOOL
b_HashURL (const BYTE *bs, UINT32 *hv);
/*
* Take a string representation of a URL and parse it into its
* components, and store these as fields in the given URL struct.
* All components are stored in their original (possibly escaped) form.
* Returns TRUE if the URL was valid, FALSE otherwise. In the latter
* case, nothing is stored in the URL struct.
*/
BOOL
URL_FromWideString (const WCHAR *ws, URL *url);
BOOL
URL_FromByteString (const BYTE *bs, URL *url);
/*
* Given a URL struct, construct and return a string representation
* of the URL.
* Returns NULL in case of error.
* NOTE: It is the callers responsibility to deallocate the returned string.
*/
WCHAR *
URL_ToWideString (URL *url);
BYTE *
URL_ToByteString (URL *url);
/*
* Given a base URL and a relative URL, resolve the relative reference
* and store as an absolute URL in the string "*abs".
* Returns TRUE on success, FALSE otherwise, in which case nothing
* is stored in "abs".
* NOTE: It is the callers responsibility to deallocate the returned string.
*/
BOOL
URL_Resolve (URL *base, URL *rel, BYTE **abs);
BOOL
w_Resolve (const WCHAR *base, const WCHAR *rel, WCHAR **abs);
BOOL
b_Resolve (const BYTE *base, const BYTE *rel, BYTE **abs);
/*
* Return TRUE if the two URLs are equal, FALSE otherwise.
* "whichComponents" is a bitmap indicating which parts of the URLs
* should be included in the comparison.
* Returns FALSE in case of error.
*/
BOOL
URL_Equal (URL *url1, URL *url2, BYTE whichComponents);
BOOL
w_EqualURL (const WCHAR *url1, const WCHAR *url2, BYTE whichComponents);
BOOL
b_EqualURL (const BYTE *url1, const BYTE *url2, BYTE whichComponents);
/*
* Return TRUE if the given string URL has a valid format, FALSE otherwise.
*/
BOOL
w_IsValid (const WCHAR* pchUrl);
BOOL
b_IsValid (const BYTE* pbUrl);
/************************************************************
* Retrieval of the different parts of a URL.
************************************************************/
/*
* Return the Scheme of the URL.
* Returns NULL in case of error, or if the URL does not have a scheme part.
* NOTE: it is the responsibility of the caller to deallocate the string.
*/
BYTE *
URL_GetScheme (URL *url);
Scheme
URL_GetSchemeType (URL *url);
/*
* Extract the scheme of a URL.
* Returns FALSE in case of error, including that the URL is not valid.
* Sets the out-parameter to NULL if the URL does not have a scheme component.
* NOTE: it is the responsibility of the caller to deallocate
* the returned string (applies to w_GetScheme and b_GetScheme).
*/
BOOL
w_GetScheme (const WCHAR* pchUrl, WCHAR **scheme);
BOOL
b_GetScheme (const BYTE* pbUrl, BYTE **scheme);
BOOL
w_GetSchemeType (const WCHAR* pchUrl, Scheme *scheme);
BOOL
b_GetSchemeType (const BYTE* pbUrl, Scheme *scheme);
/*
* Return the host part of a URL.
* Returns NULL in case of error, or if the URL does not have a host part.
* NOTE: it is the responsibility of the caller to deallocate the string.
*/
BYTE *
URL_GetHost (URL *url);
/*
* Extract the host part of a URL.
* Returns FALSE in case of error, including that the URL is not valid.
* Sets the out-parameter to NULL if the URL does not have a host component.
* NOTE: it is the responsibility of the caller to deallocate
* the returned string.
*/
BOOL
w_GetHost (const WCHAR* pchUrl, WCHAR **host);
BOOL
b_GetHost (const BYTE* pchUrl, BYTE **host);
/*
* Return the port number of a URL.
* Returns NULL in case of error, or if the URL does not have a port number.
* NOTE: it is the responsibility of the caller to deallocate the string.
*/
BYTE *
URL_GetPort (URL *url);
/*
* Extract the port number of a URL.
* Returns FALSE in case of error, including that the URL is not valid.
* Sets the out-parameter to NULL if the URL does not have a port number.
* NOTE: it is the responsibility of the caller to deallocate
* the returned string.
*/
BOOL
w_GetPort (const WCHAR* pchUrl, WCHAR **port);
BOOL
b_GetPort (const BYTE* pbUrl, BYTE **port);
/*
* Return the path component of a URL.
* Returns NULL in case of error, or if the URL does not
* have a path component.
* NOTE: it is the responsibility of the caller to deallocate the string.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -