libUPnP  1.6.17
uri.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2000-2003 Intel Corporation 
00004  * All rights reserved. 
00005  *
00006  * Redistribution and use in source and binary forms, with or without 
00007  * modification, are permitted provided that the following conditions are met: 
00008  *
00009  * - Redistributions of source code must retain the above copyright notice, 
00010  * this list of conditions and the following disclaimer. 
00011  * - Redistributions in binary form must reproduce the above copyright notice, 
00012  * this list of conditions and the following disclaimer in the documentation 
00013  * and/or other materials provided with the distribution. 
00014  * - Neither name of Intel Corporation nor the names of its contributors 
00015  * may be used to endorse or promote products derived from this software 
00016  * without specific prior written permission.
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00021  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
00022  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00025  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
00026  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  ******************************************************************************/
00031 
00032 #ifndef GENLIB_NET_URI_H
00033 #define GENLIB_NET_URI_H
00034 
00039 #if !defined(WIN32)
00040         #include <sys/param.h>
00041 #endif
00042 
00043 #include "UpnpGlobal.h" /* for */
00044 #include "UpnpInet.h"
00045 
00046 #include <ctype.h>
00047 #include <errno.h>
00048 #include <fcntl.h>
00049 #include <stdlib.h>
00050 #include <string.h>
00051 #include <sys/types.h>
00052 #include <time.h>
00053 
00054 #ifdef WIN32
00055         #ifndef UPNP_USE_MSVCPP
00056                 /* VC Winsocks2 includes these functions */
00057                 #include "inet_pton.h"
00058         #endif
00059 #else
00060         #include <netdb.h>      /* for struct addrinfo */
00061 #endif
00062 
00063 #ifdef WIN32
00064         #define strncasecmp strnicmp
00065 #else
00066         /* Other systems have strncasecmp */
00067 #endif
00068 
00069 #ifdef __cplusplus
00070 extern "C" {
00071 #endif
00072 
00074 #define HTTP_DATE_LENGTH 37
00075 
00076 #define SEPARATORS "()<>@,;:\\\"/[]?={} \t"
00077 #define MARK "-_.!~*'()"
00078 
00080 #define RESERVED ";/?:@&=+$,{}"
00081 
00082 #define HTTP_SUCCESS 1
00083 #define FALSE 0
00084 #define TAB 9
00085 #define CR 13
00086 #define LF 10
00087 #define SOCKET_BUFFER_SIZE 5000
00088 
00089 enum hostType {
00090         HOSTNAME,
00091         IPv4address
00092 };
00093 
00094 enum pathType {
00095         ABS_PATH,
00096         REL_PATH,
00097         OPAQUE_PART
00098 };
00099 
00100 #ifdef WIN32
00101         /* there is a conflict in windows with other symbols. */
00102         enum uriType  {
00103                 absolute,
00104                 relative
00105         };
00106 #else
00107         enum uriType  {
00108                 ABSOLUTE,
00109                 RELATIVE
00110         };
00111 #endif
00112 
00117 typedef struct TOKEN {
00118         const char *buff;
00119         size_t size;
00120 } token;
00121 
00126 typedef struct HOSTPORT {
00128         token text;
00129         /* Network Byte Order */
00130         struct sockaddr_storage IPaddress;
00131 } hostport_type;
00132 
00136 typedef struct URI{
00137         enum uriType type;
00138         token scheme;
00139         enum pathType path_type;
00140         token pathquery;
00141         token fragment;
00142         hostport_type hostport;
00143 } uri_type;
00144 
00149 typedef struct URL_LIST {
00151         size_t size;
00153         char *URLs;
00155         uri_type *parsedURLs;
00156 } URL_list;
00157 
00170 int replace_escaped(
00172         char *in,
00174         size_t index,
00176         size_t *max);
00177 
00189 int copy_URL_list(
00191         URL_list *in,
00193         URL_list *out);
00194 
00201 void free_URL_list(
00203         URL_list *list);
00204 
00208 #ifdef DEBUG
00209 void print_uri(
00211         uri_type *in);
00212 #else
00213 static UPNP_INLINE void print_uri(uri_type *in)
00214 {
00215         return;
00216         in = in;
00217 }
00218 #endif
00219 
00223 #ifdef DEBUG
00224 void print_token(
00226         token *in);
00227 #else
00228 static UPNP_INLINE void print_token(
00230         token *in)
00231 {
00232         return;
00233         in = in;
00234 }
00235 #endif
00236 
00245 int token_string_casecmp(
00247         token *in1,
00249         const char *in2);
00250 
00259 int token_string_cmp(
00261         token *in1,
00263         char *in2);
00264 
00273 int token_cmp(
00275         token *in1,
00277         token *in2);
00278 
00288 int remove_escaped_chars(
00290         char *in,
00292         size_t *size);
00293 
00316 int remove_dots(
00318         char *in,
00320         size_t size);
00321 
00336 char *resolve_rel_url(
00338         char *base_url,
00340         char *rel_url);
00341 
00354 int parse_uri(
00356         const char *in,
00358         size_t max,
00360         uri_type *out);
00361 
00370 int parse_uri_and_unescape(
00372         char *in,
00374         size_t max,
00376         uri_type *out);
00377 
00383 int parse_token(
00385         char *in,
00387         token *out,
00389         int max_size);
00390 
00391 /* Commented #defines, functions and typdefs */
00392 
00393 #if 0
00394 #define HTTP_E_BAD_URL UPNP_E_INVALID_URL
00395 #define HTTP_E_READ_SOCKET  UPNP_E_SOCKET_READ
00396 #define HTTP_E_BIND_SOCKET  UPNP_E_SOCKET_BIND
00397 #define HTTP_E_WRITE_SOCKET  UPNP_E_SOCKET_WRITE
00398 #define HTTP_E_CONNECT_SOCKET  UPNP_E_SOCKET_CONNECT
00399 #define HTTP_E_SOCKET    UPNP_E_OUTOF_SOCKET
00400 #define HTTP_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE
00401 #define HTTP_E_BAD_REQUEST UPNP_E_BAD_REQUEST
00402 #define HTTP_E_BAD_IP_ADDRESS UPNP_E_INVALID_URL
00403 
00404 #define RESPONSE_TIMEOUT 30
00405 #endif
00406 
00407 #if 0
00408 
00412 typedef struct SOCKET_BUFFER{
00413         char buff[SOCKET_BUFFER_SIZE];
00414         int size;
00415         struct SOCKET_BUFFER *next;
00416 } socket_buffer;
00417 
00418 
00419 typedef struct HTTP_HEADER {
00420         token header;
00421         token value;
00422         struct HTTP_HEADER * next;
00423 } http_header;
00424 
00425 
00426 typedef struct HTTP_STATUS_LINE{
00427         token http_version;
00428         token status_code;
00429         token reason_phrase;
00430 } http_status;
00431 
00432 
00433 typedef struct HTTP_REQUEST_LINE {
00434         token http_version;
00435         uri_type request_uri;
00436         token method;
00437 } http_request;
00438 
00439 
00443 typedef struct HTTP_MESSAGE {
00444         http_status status;
00445         http_request request;
00446         http_header * header_list;
00447         token content;
00448 } http_message;
00449 #endif
00450 
00451 
00452 #if 0
00453 int transferHTTP(
00454         char *request,
00455         char *toSend, 
00456         int toSendSize,
00457         char **out,
00458         char *Url);
00459 
00460 
00461 int transferHTTPRaw(
00462         char *toSend,
00463         int toSendSize, 
00464         char **out,
00465         char *URL);
00466 
00467 
00471 int transferHTTPparsedURL(
00472         char *request, 
00473         char *toSend,
00474         int toSendSize, 
00475         char **out,
00476         uri_type *URL);
00477 
00478 
00484 void currentTmToHttpDate(
00485         char *out);
00486 
00487 
00488 int parse_http_response(
00489         char *in,
00490         http_message *out,
00491         int max_len);
00492 
00493 
00494 int parse_http_request(
00495         char *in,
00496         http_message *out,
00497         int max_len);
00498 
00499 
00500 void print_http_message(
00501         http_message *message);
00502 
00503 
00504 int search_for_header(
00505         http_message *in,
00506         char *header,
00507         token *out_value);
00508 
00509 
00510 void print_status_line(
00511         http_status *in);
00512 
00513 
00514 void print_request_line(
00515         http_request *in);
00516 
00517 
00518 int parse_http_line(
00519         char *in,
00520         int max_size);
00521 
00522 
00523 int parse_not_LWS(
00524         char *in,
00525         token *out,
00526         int max_size);
00527 
00528 
00529 int parse_LWS(
00530         char *in,
00531         int max_size);
00532 
00533 
00534 size_t write_bytes(
00535         int fd,
00536         char *bytes,
00537         size_t n,
00538         int timeout);
00539 
00540 
00541 void free_http_message(
00542         http_message *message);
00543 
00544 
00545 #endif
00546 
00547 
00548 #ifdef __cplusplus
00549 }
00550 #endif
00551 
00552 
00553 #endif /* GENLIB_NET_URI_H */
00554