📄 uri.h
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2000-2003 Intel Corporation // All rights reserved. //// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: //// * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither name of Intel Corporation nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission.// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE./////////////////////////////////////////////////////////////////////////////#ifndef GENLIB_NET_URI_H#define GENLIB_NET_URI_H#ifdef __cplusplusextern "C" {#endif#include <fcntl.h>#include <string.h>#include <sys/types.h>//#include <malloc.h>#include <time.h>#include <errno.h>#include <ctype.h>#include <stdlib.h>#ifndef WIN32 #include <arpa/inet.h> #include <sys/socket.h> #include <netinet/in.h> #include <unistd.h> #include <netdb.h> #include <sys/time.h>#else #include <time.h> #define strncasecmp strnicmp#endif#include "upnp.h"//#include <upnp_debug.h>#define HTTP_DATE_LENGTH 37 // length for HTTP DATE: //"DATE: Sun, 01 Jul 2000 08:15:23 GMT<cr><lf>"#define SEPARATORS "()<>@,;:\\\"/[]?={} \t"#define MARK "-_.!~*'()"#define RESERVED ";/?:@&=+$,{}" //added {} for compatibility#define HTTP_SUCCESS 1#define FALSE 0#define TAB 9#define CR 13#define LF 10#define SOCKET_BUFFER_SIZE 5000enum hostType { HOSTNAME, IPv4address };enum pathType { ABS_PATH, REL_PATH, OPAQUE_PART };#ifndef WIN32// there is a conflict in windows with other symbolsenum uriType { ABSOLUTE, RELATIVE };#elseenum uriType { absolute, relative };#endif/* Buffer used in parsinghttp messages, urls, etc. generally this simply* holds a pointer into a larger array */typedef struct TOKEN { const char *buff; size_t size;} token;/* Represents a host port:e.g. :"127.127.0.1:80"* text is a token pointing to the full string representation */typedef struct HOSTPORT { token text; //full host port struct sockaddr_in IPv4address; //Network Byte Order } hostport_type;/* Represents a URI used in parse_uri and elsewhere */typedef struct URI{ enum uriType type; token scheme; enum pathType path_type; token pathquery; token fragment; hostport_type hostport;} uri_type;/* Represents a list of URLs as in the "callback" header of SUBSCRIBE* message in GENA * char * URLs holds dynamic memory */typedef struct URL_LIST { int size; char * URLs; //all the urls, delimited by <> uri_type *parsedURLs;} URL_list;/************************************************************************* Function : replace_escaped** Parameters :* char * in ; string of characters* int index ; index at which to start checking the characters* size_t *max ; ** Description : Replaces an escaped sequence with its unescaped version * as in http://www.ietf.org/rfc/rfc2396.txt (RFC explaining URIs)* Size of array is NOT checked (MUST be checked by caller)** Return : int ;** Note : This function modifies the string. If the sequence is an * escaped sequence it is replaced, the other characters in the * string are shifted over, and NULL characters are placed at the * end of the string.************************************************************************/int replace_escaped(char * in, int index, size_t *max);/************************************************************************* Function : copy_URL_list** Parameters :* URL_list *in ; Source URL list* URL_list *out ; Destination URL list** Description : Copies one URL_list into another. This includes * dynamically allocating the out->URLs field (the full string),* and the structures used to hold the parsedURLs. This memory MUST * be freed by the caller through: free_URL_list(&out)** Return : int ;* HTTP_SUCCESS - On Success* UPNP_E_OUTOF_MEMORY - On Failure to allocate memory** Note :************************************************************************/int copy_URL_list( URL_list *in, URL_list *out);/************************************************************************* Function : free_URL_list** Parameters :* URL_list * list ; URL List object** Description : Frees the memory associated with a URL_list. Frees the * dynamically allocated members of of list. Does NOT free the * pointer to the list itself ( i.e. does NOT free(list))** Return : void ;** Note :************************************************************************/void free_URL_list(URL_list * list);/************************************************************************* Function : print_uri** Parameters :* uri_type *in ; URI object** Description : Function useful in debugging for printing a parsed uri.** Return : void ;** Note :************************************************************************/#ifdef DEBUGvoid print_uri(uri_type *in);#elsestatic UPNP_INLINE void print_uri(uri_type *in) {}#endif/************************************************************************* Function : print_token** Parameters :* token * in ; ** Description : Function useful in debugging for printing a token.** Return : void ;** Note :************************************************************************/#ifdef DEBUGvoid print_token(token *in);#elsestatic UPNP_INLINE void print_token(token * in) {}#endif/************************************************************************* Function : token_string_casecmp** Parameters :* token * in1 ; Token object whose buffer is to be compared* char * in2 ; string of characters to compare with** Description : Compares buffer in the token object with the buffer * in in2** Return : int ;* < 0 string1 less than string2 * 0 string1 identical to string2 * > 0 string1 greater than string2 ** Note :************************************************************************/int token_string_casecmp( token * in1, char * in2);/************************************************************************* Function : token_string_cmp** Parameters :* token * in1 ; Token object whose buffer is to be compared* char * in2 ; string of characters to compare with** Description : Compares a null terminated string to a token (exact) ** Return : int ;* < 0 string1 less than string2 * 0 string1 identical to string2 * > 0 string1 greater than string2 ** Note :************************************************************************/int token_string_cmp( token * in1, char * in2);/************************************************************************* Function : token_cmp** Parameters :* token *in1 ; First token object whose buffer is to be compared* token *in2 ; Second token object used for the comparison** Description : Compares two tokens ** Return : int ;* < 0 string1 less than string2 * 0 string1 identical to string2 * > 0 string1 greater than string2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -