/home/dko/projects/mobilec/trunk/src/include/mtp_http.h

Go to the documentation of this file.
00001 /*[
00002  * Copyright (c) 2007 Integration Engineering Laboratory
00003                       University of California, Davis
00004  *
00005  * Permission to use, copy, and distribute this software and its
00006  * documentation for any purpose with or without fee is hereby granted,
00007  * provided that the above copyright notice appear in all copies and
00008  * that both that copyright notice and this permission notice appear
00009  * in supporting documentation.
00010  *
00011  * Permission to modify the software is granted, but not the right to
00012  * distribute the complete modified source code.  Modifications are to
00013  * be distributed as patches to the released version.  Permission to
00014  * distribute binaries produced by compiling modified sources is granted,
00015  * provided you
00016  *   1. distribute the corresponding source modifications from the
00017  *    released version in the form of a patch file along with the binaries,
00018  *   2. add special version identification to distinguish your version
00019  *    in addition to the base release version number,
00020  *   3. provide your name and address as the primary contact for the
00021  *    support of your modified version, and
00022  *   4. retain our contact information in regard to use of the base
00023  *    software.
00024  * Permission to distribute the released version of the source code along
00025  * with corresponding source modifications in the form of a patch file is
00026  * granted with same provisions 2 through 4 for binary distributions.
00027  *
00028  * This software is provided "as is" without express or implied warranty
00029  * to the extent permitted by applicable law.
00030 ]*/
00031 
00032 /* The MobileC http parser.
00033  *
00034  * We should probably switch to libwww someday, but not today. */
00035 
00036 #ifndef _MTP_HTTP_H_
00037 #define _MTP_HTTP_H_
00038 
00042 enum http_status_code_e
00043 {
00044   /*Informational*/
00045   CONTINUE=100,
00046   SWITCHING_PROTOCOLS,
00047   PROCESSING,
00048   /*Success*/
00049   OK=200,
00050   CREATED,
00051   ACCEPTED,
00052   NON_AUTHORITATIVE_INFORMATION,
00053   NO_CONTENT,
00054   RESET_CONTENT,
00055   PARTIAL_CONTENT,
00056   MULTI_STATUS,
00057   /*Error codes*/
00058   BAD_REQUEST=400,
00059   UNAUTHORIZED,
00060   PAYMENT_REQUIRED,
00061   FORBIDDEN,
00062   NOT_FOUND,
00063   METHOD_NOT_ALLOWED,
00064   NOT_ACCEPTABLE,
00065   PROXY_AUTHENTICATION_REQUIRED,
00066   REQUEST_TIMEOUT,
00067   CONFLICT,
00068   GONE,
00069   LENGTH_REQUIRED,
00070   PRECONDITION_FAILED,
00071   REQUST_ENTITY_TOO_LARGE,
00072   REQUEST_URI_TOO_LONG,
00073   UNSUPPORTED_MEDIA_TYPE,
00074   REQUESTED_RANGE_NOT_SATISFIABLE,
00075   EXPECTATION_FAILED,
00076   UNPROCESSABLE_ENTITY,
00077   LOCKED,
00078   FAILED_DEPENDANCY,
00079   UNORDERED_COLLECTION,
00080   UPGRADE_REQUIRED,
00081   RETRY_WITH
00082 };
00083 
00087 enum http_performative_e
00088 {
00089   HTTP_PERFORMATIVE_UNDEF=-1,
00090   HTTP_PERFORMATIVE_ZERO=0,
00091   HTTP_HEAD,
00092   HTTP_GET,
00093   HTTP_POST,
00094   HTTP_PUT,
00095   HTTP_DELETE,
00096   HTTP_TRACE,
00097   HTTP_OPTIONS,
00098   HTTP_CONNECT,
00099   HTTP_RESPONSE,
00100   HTTP_NUM_PERFORMATIVES
00101 };
00102 
00103 typedef struct mtp_http_content_s
00104 {
00105   char* content_type;
00106   void* data;
00107 } mtp_http_content_t;
00108 
00109 typedef struct mtp_http_s
00110 {
00111   enum http_status_code_e http_status_code;
00112   enum http_performative_e http_performative;
00113   char* http_version;
00114   char* host;
00115   char* return_code;
00116   char* target;       /*Target location for post/put/get etc */
00117 
00118   char* date;
00119   char* server;
00120   char* accept_ranges;
00121   char* content_length;
00122   char* connection;
00123   char* content_type;
00124   char* user_agent;
00125 
00126   char* cache_control;
00127   char* mime_version;
00128 
00129   /* The following are only valid if the message is a response */
00130   int response_code;
00131   char* response_string;
00132 
00133   /* The message may be a multi-part message */
00134   /* FIXME: We don't support nested multi-part messages for now */
00135   int message_parts;
00136   char* boundary;
00137   struct mtp_http_content_s* content;
00138 } mtp_http_t;
00139 typedef mtp_http_t* mtp_http_p;
00140 
00141 #define SOCKET_INPUT_SIZE 4096
00142 
00152 const char* http_GetExpression(const char* string, char** expr);
00153 
00167 int http_ParseExpression(
00168     const char* expression_string,
00169     char** name,
00170     char** value
00171     );
00172 
00173 const char* http_ParseHeader(
00174     mtp_http_p http,
00175     const char* string
00176     );
00177 
00178 const char*
00179 http_GetToken(const char* string, char** token);
00180 
00181 int
00182 mtp_http_Destroy(mtp_http_p http);
00183 
00184 struct connection_s;
00185 int
00186 mtp_http_InitializeFromConnection(struct mtp_http_s *http, struct connection_s *connection);
00187 
00188 mtp_http_p 
00189 mtp_http_New(void);
00190 
00191 struct connection;
00192 int 
00193 mtp_http_Parse(struct mtp_http_s* http, const char* string);
00194 
00195 struct message_s;
00196 int 
00197 mtp_http_ComposeMessage(struct message_s* message);
00198 
00199 struct message_s* 
00200 mtp_http_CreateMessage(
00201     mtp_http_t* mtp_http,
00202     char* hostname,
00203     int port );
00204 #endif

Generated on Mon Jun 23 16:01:10 2008 for Mobile-C by  doxygen 1.5.4