HTTP Protocol Functions
CosmHTTPOpenSyntaxs32 CosmHTTPOpen( cosm_HTTP * http, const ascii * uri, const cosm_NET_ADDR proxy_host, const u16 proxy_port, const ascii * proxy_name, const ascii * proxy_pass, const ascii * user_name, const ascii * user_pass ); s32 _COSM_HTTPOPEN( cosm_HTTP * http, const ascii * uri ); DescriptionOpen an HTTP/1.1 (RFC 2616) connection to the given uri. The uri must be of the standard "http://host[:port][/][ignored]" form, anything past and including the single slash is ignored. proxy_host and proxy_port are the address of the web proxy, and are used if both are non-zero. The name and pass parameters are for the proxy and web page passwords. Since CosmHTTPOpen is rather complex, a macro for simpler cases is also defined. _COSM_HTTPOPEN(...) allows just the first 2 parameters to be specified for when you do not need to worry about proxies or passwords. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPGetSyntaxs32 CosmHTTPGet( cosm_HTTP * http, u32 * status, const ascii * uri_path, u32 wait_ms ); DescriptionUsing the open http connection, open the uri_path given for reading and place the resulting HTTP status code into status. CGI parameters may be passed as part of the uri_path. This function is only used to read static web data. wait_ms is the network timeout while looking for a response to see if anything is coming back or not. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPPostSyntaxs32 CosmHTTPPost( cosm_HTTP * http, u32 * status, const ascii * uri_path, const void * data, u32 length, u32 wait_ms ); DescriptionUsing the open http connection, send length bytes of data to the uri_path which is then opened for reading and the resulting HTTP status code is put into status. CGI parameter data may be sent as data, but none is allowed in the uri_path with this method. This function is primarily for communication when network traffic of blocked, but is fully compatable with web servers. wait_ms is the network timeout while looking for a response to see if anything is coming back or not. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPRecvSyntaxs32 CosmHTTPRecv( void * buffer, u32 * bytes_received, cosm_HTTP * http, u32 length, u32 wait_ms ); DescriptionRead up to length bytes of the resulting get/post data from the server into the buffer, waiting up to wait_ms milliseconds for data to arrive. bytes_read is set to the number of bytes actually read. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPCloseSyntaxs32 CosmHTTPClose( cosm_HTTP * http ); DescriptionClose the http connection and free any remaining data. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDInitSyntaxs32 CosmHTTPDInit( cosm_HTTPD * httpd, ascii * log_path, u32 log_level, u32 threads, u32 stack_size, cosm_NET_ADDR ip, u16 port, u32 wait_ms ); DescriptionInitialize a server with threads threads, each with a stack size of stack_size, running on the ip and port given. Depending on how you write your handlers, not much stack should be needed. log_path and log_level are for the server log using a standard CosmLog. wait_ms is the network timeout while parsing the request. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDSetHandlerSyntaxs32 CosmHTTPDSetHandler( cosm_HTTPD * httpd, const ascii * path, cosm_NET_ACL * acl, s32 (*handler)( cosm_HTTPD_REQUEST * request ) ); DescriptionA handler will be called when a client mathching the ACL requests a URL starting with path. The handler with the longest matching path will be called, and the order handlers are added does not matter. if handler is NULL, the handler is removed. At minimum you must have a handler set for the path "/" which will be called if no other handler matches. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDStartSyntaxs32 CosmHTTPDStart( cosm_HTTPD * httpd, u32 timeout_ms ); DescriptionStarts the httpd server once it is initialized and handlers are set. Since your server will probably be stopped by a message or signal, the correct way to see that it is still running is to check that httpd.status != COSM_HTTPD_STATUS_STOPPED. It is possible on some systems for severe network driver errors to stop the server. Calling CosmHTTPStart again may be able to restart it. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDStopSyntaxs32 CosmHTTPDStop( cosm_HTTPD * httpd, u32 timeout_ms ); DescriptionStops the httpd server, possibly to change the handlers. If the threads cannot be shutdown within timeout_ms milliseconds, then COSM_HTTPD_ERROR_TIMEOUT is returned and you can attempt to stop it again. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDSendInitSyntaxs32 CosmHTTPDSendInit( cosm_HTTPD_REQUEST * request, u32 status_code, ascii * status_string, ascii * mime_type ); DescriptionThis is the first function that should be called in any handler. status_code is the 3 digit HTTP status code. status_string is the text associated with the that code, for 200 it is "OK". mime_type is the media type of data to be sent based on the content. Further information on these parameters can be found in the HTTP/1.1 documentation (RFC 2616). Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDSendHeadSyntaxs32 CosmHTTPDSendHead( cosm_HTTPD_REQUEST * request, const void * string ); DescriptionSend the string to the client as part of the HTTP header sent in handler functions. This function must be used after CosmHTTPDSendInit but before any CosmHTTPDSend are called. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDSendSyntaxs32 CosmHTTPDSend( cosm_HTTPD_REQUEST * request, const void * data, u32 length ); DescriptionSend length bytes of data to the client in a handler function. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDRecvSyntaxs32 CosmHTTPDRecv( void * buffer, u32 * bytes_received, cosm_HTTPD_REQUEST * request, u32 length, u32 wait_ms ); DescriptionRead up to length bytes of the posted data from the client into the buffer, waiting up to wait_ms milliseconds for data to arrive. bytes_received is set to the number of bytes actually read. For use in handler functions. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
ExampleCosmHTTPDFreeSyntaxs32 CosmHTTPDFree( cosm_HTTPD * httpd ); DescriptionFree the httpd and any remaining data. A server must not be running in order to free it. Return ValuesCOSM_PASS on success, or an error code on failure. Errors
Example
© Copyright Mithral Communications & Design Inc.
1995-2024.
All rights reserved.
Mithral® and Cosm® are trademarks of
Mithral Communications & Design Inc.
|