Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

http.h File Reference

#include "gwlib/list.h"
#include "gwlib/octstr.h"

Include dependency graph for http.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  HTTPCGIVar
struct  HTTPURLParse

Defines

#define http_receive_result(caller, status, final_url, headers, body)   http_receive_result_real(caller, status, final_url, headers, body, 1)
#define http_header_find_first(headers, name)   gw_claim_area(http_header_find_first_real((headers), (name), __FILE__, __LINE__, __func__))

Typedefs

typedef List HTTPCaller
typedef HTTPClient HTTPClient

Enumerations

enum  {
  HTTP_OK = 200, HTTP_CREATED = 201, HTTP_ACCEPTED = 202, HTTP_NO_CONTENT = 204,
  HTTP_RESET_CONTENT = 205, HTTP_MOVED_PERMANENTLY = 301, HTTP_FOUND = 302, HTTP_SEE_OTHER = 303,
  HTTP_NOT_MODIFIED = 304, HTTP_TEMPORARY_REDIRECT = 307, HTTP_BAD_REQUEST = 400, HTTP_UNAUTHORIZED = 401,
  HTTP_FORBIDDEN = 403, HTTP_NOT_FOUND = 404, HTTP_BAD_METHOD = 405, HTTP_NOT_ACCEPTABLE = 406,
  HTTP_REQUEST_ENTITY_TOO_LARGE = 413, HTTP_UNSUPPORTED_MEDIA_TYPE = 415, HTTP_INTERNAL_SERVER_ERROR = 500, HTTP_NOT_IMPLEMENTED = 501,
  HTTP_BAD_GATEWAY = 502, HTTP_SERVICE_UNAVAILABLE = 503
}
enum  {
  HTTP_STATUS_PROVISIONAL = 100, HTTP_STATUS_SUCCESSFUL = 200, HTTP_STATUS_REDIRECTION = 300, HTTP_STATUS_CLIENT_ERROR = 400,
  HTTP_STATUS_SERVER_ERROR = 500, HTTP_STATUS_UNKNOWN = 0
}
enum  { HTTP_METHOD_GET = 1, HTTP_METHOD_POST = 2, HTTP_METHOD_HEAD = 3 }

Functions

void http_init (void)
void http_shutdown (void)
HTTPURLParsehttp_urlparse_create (void)
void http_urlparse_destroy (HTTPURLParse *p)
HTTPURLParseparse_url (Octstr *url)
void parse_dump (HTTPURLParse *p)
void http_use_proxy (Octstr *hostname, int port, int ssl, List *exceptions, Octstr *username, Octstr *password, Octstr *exceptions_regex)
void http_close_proxy (void)
void http_set_interface (const Octstr *our_host)
void http_set_client_timeout (long timeout)
int http_get_real (int method, Octstr *url, List *request_headers, Octstr **final_url, List **reply_headers, Octstr **reply_body)
HTTPCallerhttp_caller_create (void)
void http_caller_destroy (HTTPCaller *caller)
void http_caller_signal_shutdown (HTTPCaller *caller)
void http_start_request (HTTPCaller *caller, int method, Octstr *url, List *headers, Octstr *body, int follow, void *id, Octstr *certkeyfile)
void * http_receive_result_real (HTTPCaller *caller, int *status, Octstr **final_url, List **headers, Octstr **body, int blocking)
int http_open_port (int port, int ssl)
int http_open_port_if (int port, int ssl, Octstr *interface)
HTTPClienthttp_accept_request (int port, Octstr **client_ip, Octstr **url, List **headers, Octstr **body, List **cgivars)
void http_send_reply (HTTPClient *client, int status, List *headers, Octstr *body)
void http_close_client (HTTPClient *client)
void http_close_port (int port)
void http_close_all_ports (void)
void http_destroy_cgiargs (List *args)
Octstrhttp_cgi_variable (List *list, char *name)
Listhttp_create_empty_headers (void)
void http_destroy_headers (List *headers)
void http_header_add (List *headers, char *name, char *contents)
void http_header_get (List *headers, long i, Octstr **name, Octstr **value)
Listhttp_header_duplicate (List *headers)
void http_header_pack (List *headers)
void http_append_headers (List *to, List *from)
Octstrhttp_header_value (List *headers, Octstr *header)
void http_header_combine (List *old_headers, List *new_headers)
long http_header_quoted_string_len (Octstr *header, long pos)
Listhttp_header_split_value (Octstr *value)
Listhttp_header_split_auth_value (Octstr *value)
long http_header_remove_all (List *headers, char *name)
void http_remove_hop_headers (List *headers)
void http_header_mark_transformation (List *headers, Octstr *new_body, Octstr *new_type)
Octstrhttp_header_find_first_real (List *headers, char *name, const char *file, long line, const char *func)
Listhttp_header_find_all (List *headers, char *name)
void http_header_get_content_type (List *headers, Octstr **type, Octstr **charset)
int http_type_accepted (List *headers, char *type)
void http_header_dump (List *headers)
void http_cgivar_dump (List *cgiargs)
void http_cgivar_dump_into (List *cgiargs, Octstr *os)
int http_charset_accepted (List *headers, char *charset)
void http_add_basic_auth (List *headers, Octstr *username, Octstr *password)
Octstrhttp_get_header_parameter (Octstr *value, Octstr *parameter)
int http_status_class (int code)
int http_name2method (Octstr *method)
char * http_method2name (int method)


Define Documentation

#define http_header_find_first headers,
name   )     gw_claim_area(http_header_find_first_real((headers), (name), __FILE__, __LINE__, __func__))
 

Definition at line 558 of file http.h.

Referenced by check_x_wap_application_id_header(), client_is_persistent(), deduce_body_state(), get_redirection_location(), handle_transaction(), headers_acceptable(), http_header_get_content_type(), transform_message(), and wsp_pack_separate_content_type().

#define http_receive_result caller,
status,
final_url,
headers,
body   )     http_receive_result_real(caller, status, final_url, headers, body, 1)
 

Definition at line 365 of file http.h.

Referenced by http_get_real(), httpsmsc_send_cb(), receive_push_reply(), receive_reply(), return_replies_thread(), soap_read_response(), and url_result_thread().


Typedef Documentation

typedef List HTTPCaller
 

Definition at line 309 of file http.h.

Referenced by client_thread(), http_caller_create(), http_caller_destroy(), http_caller_signal_shutdown(), http_get_real(), http_receive_result_real(), http_start_request(), push_thread(), receive_push_reply(), receive_reply(), server_create(), start_push(), start_request(), and xmlrpc_doc_send().

typedef struct HTTPClient HTTPClient
 

Definition at line 377 of file http.h.


Enumeration Type Documentation

anonymous enum
 

Enumeration values:
HTTP_OK 
HTTP_CREATED 
HTTP_ACCEPTED 
HTTP_NO_CONTENT 
HTTP_RESET_CONTENT 
HTTP_MOVED_PERMANENTLY 
HTTP_FOUND 
HTTP_SEE_OTHER 
HTTP_NOT_MODIFIED 
HTTP_TEMPORARY_REDIRECT 
HTTP_BAD_REQUEST 
HTTP_UNAUTHORIZED 
HTTP_FORBIDDEN 
HTTP_NOT_FOUND 
HTTP_BAD_METHOD 
HTTP_NOT_ACCEPTABLE 
HTTP_REQUEST_ENTITY_TOO_LARGE 
HTTP_UNSUPPORTED_MEDIA_TYPE 
HTTP_INTERNAL_SERVER_ERROR 
HTTP_NOT_IMPLEMENTED 
HTTP_BAD_GATEWAY 
HTTP_SERVICE_UNAVAILABLE 

Definition at line 140 of file http.h.

00140      {
00141     HTTP_OK                        = 200,
00142     HTTP_CREATED                   = 201,
00143     HTTP_ACCEPTED                  = 202,
00144     HTTP_NO_CONTENT                = 204,
00145     HTTP_RESET_CONTENT             = 205,
00146     HTTP_MOVED_PERMANENTLY         = 301,
00147     HTTP_FOUND                     = 302,
00148     HTTP_SEE_OTHER                 = 303,
00149     HTTP_NOT_MODIFIED              = 304,
00150     HTTP_TEMPORARY_REDIRECT        = 307,
00151     HTTP_BAD_REQUEST               = 400,
00152     HTTP_UNAUTHORIZED              = 401,
00153     HTTP_FORBIDDEN                 = 403,
00154     HTTP_NOT_FOUND                 = 404,
00155     HTTP_BAD_METHOD                = 405,
00156     HTTP_NOT_ACCEPTABLE            = 406,
00157     HTTP_REQUEST_ENTITY_TOO_LARGE  = 413,
00158     HTTP_UNSUPPORTED_MEDIA_TYPE    = 415,
00159     HTTP_INTERNAL_SERVER_ERROR     = 500,
00160     HTTP_NOT_IMPLEMENTED           = 501,
00161     HTTP_BAD_GATEWAY               = 502,
00162     HTTP_SERVICE_UNAVAILABLE       = 503
00163 };

anonymous enum
 

Enumeration values:
HTTP_STATUS_PROVISIONAL 
HTTP_STATUS_SUCCESSFUL 
HTTP_STATUS_REDIRECTION 
HTTP_STATUS_CLIENT_ERROR 
HTTP_STATUS_SERVER_ERROR 
HTTP_STATUS_UNKNOWN 

Definition at line 170 of file http.h.

00170      {
00171     HTTP_STATUS_PROVISIONAL = 100,
00172     HTTP_STATUS_SUCCESSFUL = 200,
00173     HTTP_STATUS_REDIRECTION = 300,
00174     HTTP_STATUS_CLIENT_ERROR = 400,
00175     HTTP_STATUS_SERVER_ERROR = 500,
00176     HTTP_STATUS_UNKNOWN = 0
00177 };

anonymous enum
 

Enumeration values:
HTTP_METHOD_GET 
HTTP_METHOD_POST 
HTTP_METHOD_HEAD 

Definition at line 184 of file http.h.

00184      {
00185     HTTP_METHOD_GET = 1,
00186     HTTP_METHOD_POST = 2,
00187     HTTP_METHOD_HEAD = 3
00188 };


Function Documentation

HTTPClient* http_accept_request int  port,
Octstr **  client_ip,
Octstr **  url,
List **  headers,
Octstr **  body,
List **  cgivars
 

Definition at line 2435 of file http.c.

References HTTPEntity::body, client_destroy(), client_is_persistent(), HTTPClient::conn, conn_eof(), conn_error(), conn_wait(), debug(), entity_destroy(), HTTPEntity::headers, HTTPClient::ip, HTTPClient::method, octstr_destroy(), octstr_duplicate, parse_cgivars(), HTTPClient::persistent_conn, port, port_get_request(), HTTPClient::request, HTTPClient::url, and HTTPClient::use_version_1_0.

Referenced by client_thread(), http_read_thread(), http_thread(), httpadmin_run(), httpd_emu(), https_read_thread(), httpsmsc_receiver(), sendsms_thread(), and soap_server().

02438 {
02439     HTTPClient *client;
02440 
02441     do {
02442         client = port_get_request(port);
02443         if (client == NULL) {
02444             debug("gwlib.http", 0, "HTTP: No clients with requests, quitting.");
02445             return NULL;
02446         }
02447         /* check whether client connection still ok */
02448         conn_wait(client->conn, 0);
02449         if (conn_error(client->conn) || conn_eof(client->conn)) {
02450             client_destroy(client);
02451             client = NULL;
02452         }
02453     } while(client == NULL);
02454 
02455     *client_ip = octstr_duplicate(client->ip);
02456     *url = client->url;
02457     *headers = client->request->headers;
02458     *body = client->request->body;
02459     *cgivars = parse_cgivars(client->url);
02460 
02461     if (client->method != HTTP_METHOD_POST) {
02462     octstr_destroy(*body);
02463     *body = NULL;
02464     }
02465 
02466     client->persistent_conn = client_is_persistent(client->request->headers,
02467                            client->use_version_1_0);
02468     
02469     client->url = NULL;
02470     client->request->headers = NULL;
02471     client->request->body = NULL;
02472     entity_destroy(client->request);
02473     client->request = NULL;
02474 
02475     return client;
02476 }

Here is the call graph for this function:

void http_add_basic_auth List headers,
Octstr username,
Octstr password
 

Definition at line 3344 of file http.c.

References http_header_add(), octstr_binary_to_base64(), octstr_destroy(), octstr_format(), octstr_get_cstr, octstr_imm(), octstr_insert(), octstr_strip_blanks(), password, and username.

Referenced by client_thread(), push_headers_create(), receive_push_reply(), and send_request().

03345 {
03346     Octstr *os;
03347     
03348     if (password != NULL)
03349       os = octstr_format("%S:%S", username, password);
03350     else
03351       os = octstr_format("%S", username);
03352     octstr_binary_to_base64(os);
03353     octstr_strip_blanks(os);
03354     octstr_insert(os, octstr_imm("Basic "), 0);
03355     http_header_add(headers, "Authorization", octstr_get_cstr(os));
03356     octstr_destroy(os);
03357 }

Here is the call graph for this function:

void http_append_headers List to,
List from
 

Definition at line 2884 of file http.c.

References gw_assert, gwlib_assert_init(), gwlist_append(), gwlist_get(), gwlist_len(), and octstr_duplicate.

Referenced by http_header_combine(), and pap_request_thread().

02885 {
02886     Octstr *header;
02887     long i;
02888 
02889     gwlib_assert_init();
02890     gw_assert(to != NULL);
02891     gw_assert(from != NULL);
02892 
02893     for (i = 0; i < gwlist_len(from); ++i) {
02894         header = gwlist_get(from, i);
02895         gwlist_append(to, octstr_duplicate(header));
02896     }
02897 }

Here is the call graph for this function:

HTTPCaller* http_caller_create void   ) 
 

Definition at line 894 of file http.c.

References gwlist_add_producer(), gwlist_create, and HTTPCaller.

Referenced by http_get_real(), main(), smsc_http_create(), soap_create_client_data(), and wap_appl_init().

00895 {
00896     HTTPCaller *caller;
00897     
00898     caller = gwlist_create();
00899     gwlist_add_producer(caller);
00900     return caller;
00901 }

Here is the call graph for this function:

void http_caller_destroy HTTPCaller caller  ) 
 

Definition at line 904 of file http.c.

References gwlist_destroy(), HTTPCaller, and server_destroy().

Referenced by client_thread(), conndata_destroy(), http_get_real(), main(), push_thread(), soap_destroy_client_data(), and wap_appl_shutdown().

00905 {
00906     gwlist_destroy(caller, server_destroy);
00907 }

Here is the call graph for this function:

void http_caller_signal_shutdown HTTPCaller caller  ) 
 

Definition at line 910 of file http.c.

References gwlist_remove_producer(), and HTTPCaller.

Referenced by httpsmsc_receiver(), main(), soap_destroy_client_data(), and wap_appl_shutdown().

00911 {
00912     gwlist_remove_producer(caller);
00913 }

Here is the call graph for this function:

Octstr* http_cgi_variable List list,
char *  name
 

Definition at line 2668 of file http.c.

References gw_assert, gwlib_assert_init(), gwlist_get(), gwlist_len(), HTTPCGIVar::name, name, octstr_str_compare(), and HTTPCGIVar::value.

Referenced by brunet_receive_sms(), clickatell_receive_sms(), client_thread(), default_authorise_user(), httpd_check_authorization(), httpd_emu(), httpd_loglevel(), httpd_restart_smsc(), httpd_stop_smsc(), kannel_receive_sms(), parse_cgivars_for_password(), parse_cgivars_for_username(), smsbox_req_sendota(), smsbox_req_sendsms(), and xidris_receive_sms().

02669 {
02670     int i;
02671     HTTPCGIVar *v;
02672 
02673     gwlib_assert_init();
02674     gw_assert(list != NULL);
02675     gw_assert(name != NULL);
02676 
02677     for (i = 0; i < gwlist_len(list); ++i) {
02678         v = gwlist_get(list, i);
02679         if (octstr_str_compare(v->name, name) == 0)
02680             return v->value;
02681     }
02682     return NULL;
02683 }

Here is the call graph for this function:

void http_cgivar_dump List cgiargs  ) 
 

Definition at line 3272 of file http.c.

References debug(), gwlib_assert_init(), gwlist_get(), gwlist_len(), HTTPCGIVar::name, octstr_dump, and HTTPCGIVar::value.

03273 {
03274     HTTPCGIVar *v;
03275     long i, len;
03276 
03277     gwlib_assert_init();
03278 
03279     len = gwlist_len(cgiargs);
03280 
03281     debug("gwlib.http", 0, "Dumping %ld cgi variables:", len);
03282     for (i = 0; i < len; i++) {
03283         v = gwlist_get(cgiargs, i);
03284         octstr_dump(v->name, 0);
03285         octstr_dump(v->value, 0);
03286     }
03287     debug("gwlib.http", 0, "End of dump.");
03288 }

Here is the call graph for this function:

void http_cgivar_dump_into List cgiargs,
Octstr os
 

Definition at line 3291 of file http.c.

References gwlib_assert_init(), gwlist_extract_first(), HTTPCGIVar::name, octstr_format_append(), and HTTPCGIVar::value.

03292 {
03293     HTTPCGIVar *v;
03294 
03295     if (os == NULL)
03296         return;
03297 
03298     gwlib_assert_init();
03299 
03300     while ((v = gwlist_extract_first(cgiargs)) != NULL)
03301         octstr_format_append(os, "&%S=%S", v->name, v->value);
03302 }

Here is the call graph for this function:

int http_charset_accepted List headers,
char *  charset
 

Definition at line 3338 of file http.c.

References charset, and http_something_accepted().

Referenced by add_charset_headers(), and normalize_charset().

03339 {
03340     return http_something_accepted(headers, "Accept-Charset", charset);
03341 }

Here is the call graph for this function:

void http_close_all_ports void   ) 
 

Definition at line 2374 of file http.c.

References fdset_destroy(), gwthread_join_every(), gwthread_wakeup(), keep_servers_open, server_fdset, server_thread(), server_thread_id, and server_thread_is_running.

Referenced by client_thread(), httpadmin_stop(), httpd_emu_destroy(), main(), sigterm(), and wap_push_ppg_shutdown().

02375 {
02376     if (server_thread_id != -1) {
02377         keep_servers_open = 0;
02378         gwthread_wakeup(server_thread_id);
02379         gwthread_join_every(server_thread);
02380         server_thread_is_running = 0;
02381         fdset_destroy(server_fdset);
02382         server_fdset = NULL;
02383     }
02384 }

Here is the call graph for this function:

void http_close_client HTTPClient client  ) 
 

Definition at line 2597 of file http.c.

References client_destroy().

Referenced by httpadmin_run(), httpsmsc_receiver(), and pap_request_thread().

02598 {
02599     client_destroy(client);
02600 }

Here is the call graph for this function:

void http_close_port int  port  ) 
 

Definition at line 2363 of file http.c.

References closed_server_sockets, gwlist_produce(), gwthread_wakeup(), and server_thread_id.

Referenced by httpsmsc_receiver(), httpsmsc_shutdown(), soap_server_start(), and soap_server_stop().

02364 {
02365     int *p;
02366     
02367     p = gw_malloc(sizeof(*p));
02368     *p = port;
02369     gwlist_produce(closed_server_sockets, p);
02370     gwthread_wakeup(server_thread_id);
02371 }

Here is the call graph for this function:

void http_close_proxy void   ) 
 

Definition at line 302 of file http.c.

References gw_assert, gw_regex_destroy(), gwlist_destroy(), mutex_lock, mutex_unlock, octstr_destroy(), octstr_destroy_item(), proxy_exceptions, proxy_exceptions_regex, proxy_hostname, proxy_mutex, proxy_password, proxy_port, proxy_username, run_status, running, and terminating.

Referenced by http_use_proxy(), and proxy_shutdown().

00303 {
00304     gw_assert(run_status == running || run_status == terminating);
00305 
00306     mutex_lock(proxy_mutex);
00307     proxy_port = 0;
00308     octstr_destroy(proxy_hostname);
00309     octstr_destroy(proxy_username);
00310     octstr_destroy(proxy_password);
00311     proxy_hostname = NULL;
00312     proxy_username = NULL;
00313     proxy_password = NULL;
00314     gwlist_destroy(proxy_exceptions, octstr_destroy_item);
00315     gw_regex_destroy(proxy_exceptions_regex);
00316     proxy_exceptions = NULL;
00317     proxy_exceptions_regex = NULL;
00318     mutex_unlock(proxy_mutex);
00319 }

Here is the call graph for this function:

List* http_create_empty_headers void   ) 
 

Definition at line 2704 of file http.c.

References gwlib_assert_init(), and gwlist_create.

Referenced by brunet_send_sms(), challenge(), clickatell_send_sms(), entity_create(), http_header_duplicate(), httpd_emu_init(), indicate_push_connection(), indicate_push_resume(), kill_kannel(), main(), make_confirmedpush_pdu(), make_push_pdu(), make_reply_headers(), make_resume_reply_pdu(), mime_entity_create(), obey_request(), pass_data_headers(), push_headers_create(), reply(), return_reply(), send_to_pi(), soap_send(), soap_server(), start_fetch(), test_header_combine(), unpack_new_headers(), and wsp_headers_unpack().

02705 {
02706     gwlib_assert_init();
02707     return gwlist_create();
02708 }

Here is the call graph for this function:

void http_destroy_cgiargs List args  ) 
 

Definition at line 2650 of file http.c.

References gwlib_assert_init(), gwlist_destroy(), gwlist_extract_first(), HTTPCGIVar::name, octstr_destroy(), and HTTPCGIVar::value.

Referenced by client_thread(), http_thread(), httpd_emu(), httpd_serve(), httpsmsc_receiver(), pap_request_thread(), and sendsms_thread().

02651 {
02652     HTTPCGIVar *v;
02653 
02654     gwlib_assert_init();
02655 
02656     if (args == NULL)
02657         return ;
02658 
02659     while ((v = gwlist_extract_first(args)) != NULL) {
02660         octstr_destroy(v->name);
02661         octstr_destroy(v->value);
02662         gw_free(v);
02663     }
02664     gwlist_destroy(args, NULL);
02665 }

Here is the call graph for this function:

void http_destroy_headers List headers  ) 
 

Definition at line 2711 of file http.c.

References gwlib_assert_init(), gwlist_destroy(), and octstr_destroy_item().

Referenced by brunet_receive_sms(), brunet_send_sms(), challenge(), check_application_headers(), clickatell_receive_sms(), clickatell_send_sms(), client_thread(), content_transformable(), decode_bearer_indication(), entity_destroy(), generic_send_sms(), handle_transaction(), http_queue_thread(), http_something_accepted(), http_thread(), httpd_emu(), httpd_emu_shutdown(), httpd_serve(), httpsmsc_receiver(), httpsmsc_send_cb(), indicate_push_connection(), indicate_push_resume(), kannel_receive_sms(), kannel_send_sms(), kill_kannel(), main(), make_confirmedpush_pdu(), make_connectreply_pdu(), make_push_pdu(), make_resume_reply_pdu(), mime_entity_to_octstr(), mime_replace_headers(), mime_something_to_entity(), numhash_create(), obey_request(), pack_sia(), pap_request_thread(), receive_push_reply(), receive_reply(), reply(), return_replies_thread(), return_reply(), send_to_pi(), sendsms_thread(), server_destroy(), soap_read_response(), soap_send(), soap_server(), start_fetch(), start_push(), test_header_combine(), url_result_thread(), wapme_smsproxy_send_sms(), xidris_receive_sms(), and xidris_send_sms().

02712 {
02713     gwlib_assert_init();
02714     gwlist_destroy(headers, octstr_destroy_item);
02715 }

Here is the call graph for this function:

Octstr* http_get_header_parameter Octstr value,
Octstr parameter
 

Definition at line 3360 of file http.c.

References http_header_quoted_string_len(), octstr_case_compare(), octstr_copy, octstr_destroy(), octstr_duplicate, octstr_get_char(), octstr_len(), octstr_search_char(), octstr_strip_blanks(), and result.

Referenced by fix_boundary_element(), get_start_param(), and mime_something_to_entity().

03361 {
03362     long pos, len, end;
03363     int c, found = 0;
03364     Octstr *result = NULL;
03365 
03366     len = octstr_len(value);
03367     /* Find the start of the first parameter. */
03368     for (pos = 0; pos < len; pos++) {
03369         c = octstr_get_char(value, pos);
03370         if (c == ';')
03371             break;
03372         else if (c == '"')
03373             pos += http_header_quoted_string_len(value, pos) - 1;
03374     }
03375 
03376     if (pos >= len)
03377         return NULL;   /* no parameters */
03378 
03379     for (pos++; pos > 0 && pos < len && found == 0; pos++) {
03380         Octstr *key = NULL;
03381         Octstr *val = NULL;
03382 
03383         end = octstr_search_char(value, '=', pos);
03384         if (end < 0)
03385             end = octstr_search_char(value, ';', pos);
03386         if (end < 0)
03387             end = octstr_len(value);
03388         key = octstr_copy(value, pos, end - pos);
03389         octstr_strip_blanks(key);
03390         pos = end;
03391 
03392         if (octstr_get_char(value, pos) == '=') {
03393             pos++;
03394             while (isspace(octstr_get_char(value, pos)))
03395                 pos++;
03396             if (octstr_get_char(value, pos) == '"')
03397                 end = pos + http_header_quoted_string_len(value, pos);
03398             else
03399                 end = octstr_search_char(value, ';', pos);
03400             if (end < 0)
03401                 end = octstr_len(value);
03402             val = octstr_copy(value, pos, end - pos);
03403             octstr_strip_blanks(val);
03404             pos = end;
03405             pos = octstr_search_char(value, ';', pos);
03406         }
03407 
03408         /* is this the pair we look for? bail out then*/
03409         if (octstr_case_compare(key, parameter) == 0) {
03410             found++;        
03411             result = octstr_duplicate(val);
03412         }
03413 
03414         octstr_destroy(key);
03415         octstr_destroy(val);
03416     }
03417 
03418     return result;
03419 }

Here is the call graph for this function:

int http_get_real int  method,
Octstr url,
List request_headers,
Octstr **  final_url,
List **  reply_headers,
Octstr **  reply_body
 

Definition at line 1727 of file http.c.

References http_caller_create(), http_caller_destroy(), http_get_real(), http_receive_result, http_start_request(), and HTTPCaller.

Referenced by http_get_real(), kill_kannel(), and numhash_create().

01729 {
01730     HTTPCaller *caller;
01731     int status;
01732     void *ret;
01733     
01734     caller = http_caller_create();
01735     http_start_request(caller, method, url, request_headers, 
01736                        NULL, 1, http_get_real, NULL);
01737     ret = http_receive_result(caller, &status, final_url, 
01738                               reply_headers, reply_body);
01739     http_caller_destroy(caller);
01740     if (ret == NULL)
01741         return -1;
01742     return status;
01743 }

Here is the call graph for this function:

void http_header_add List headers,
char *  name,
char *  contents
 

Definition at line 2718 of file http.c.

References gw_assert, gwlib_assert_init(), gwlist_append(), name, and octstr_format().

Referenced by add_accept_headers(), add_charset_headers(), add_client_sdu_size(), add_connection_header(), add_dlr_mask(), add_dlr_url(), add_kannel_version(), add_msisdn(), add_network_info(), add_push_application_id(), add_push_flag(), add_session_id(), add_via(), add_x_wap_tod(), brunet_receive_sms(), challenge(), change_header_value(), check_application_headers(), check_session_request_headers(), check_x_wap_application_id_header(), clickatell_receive_sms(), client_thread(), decode_bearer_indication(), fix_boundary_element(), http_add_basic_auth(), http_header_mark_transformation(), httpd_emu_init(), httpd_serve(), kannel_receive_sms(), kill_kannel(), main(), make_reply_headers(), obey_request(), pack_into_push_datagram(), pack_into_result_datagram(), pass_extension_headers(), pass_optional_header(), proxy_add_authentication(), push_headers_create(), send_request(), send_to_pi(), soap_send(), soap_server(), start_fetch(), test_header_combine(), wsp_unpack_app_header(), wsp_unpack_well_known_field(), and xmlrpc_doc_send().

02719 {
02720     gwlib_assert_init();
02721     gw_assert(headers != NULL);
02722     gw_assert(name != NULL);
02723     gw_assert(contents != NULL);
02724 
02725     gwlist_append(headers, octstr_format("%s: %s", name, contents));
02726 }

Here is the call graph for this function:

void http_header_combine List old_headers,
List new_headers
 

Definition at line 2900 of file http.c.

References gwlist_len(), http_append_headers(), http_header_get(), http_header_remove_all(), name, octstr_destroy(), and octstr_get_cstr.

Referenced by return_reply(), start_fetch(), start_request(), test_header_combine(), and unpack_new_headers().

02901 {
02902     long i;
02903     Octstr *name;
02904     Octstr *value;
02905 
02906     /*
02907      * Avoid doing this scan if old_headers is empty anyway.
02908      */
02909     if (gwlist_len(old_headers) > 0) {
02910         for (i = 0; i < gwlist_len(new_headers); i++) {
02911         http_header_get(new_headers, i, &name, &value);
02912         http_header_remove_all(old_headers, octstr_get_cstr(name));
02913             octstr_destroy(name);
02914             octstr_destroy(value);
02915         }
02916     }
02917 
02918     http_append_headers(old_headers, new_headers);
02919 }

Here is the call graph for this function:

void http_header_dump List headers  ) 
 

Definition at line 3259 of file http.c.

References debug(), gwlib_assert_init(), gwlist_get(), gwlist_len(), and octstr_dump.

Referenced by check_application_headers(), client_thread(), decode_bearer_indication(), main(), and start_push().

03260 {
03261     long i;
03262 
03263     gwlib_assert_init();
03264 
03265     debug("gwlib.http", 0, "Dumping HTTP headers:");
03266     for (i = 0; headers != NULL && i < gwlist_len(headers); ++i)
03267         octstr_dump(gwlist_get(headers, i), 1);
03268     debug("gwlib.http", 0, "End of dump.");
03269 }

Here is the call graph for this function:

List* http_header_duplicate List headers  ) 
 

Definition at line 2801 of file http.c.

References gwlib_assert_init(), gwlist_append(), gwlist_get(), gwlist_len(), http_create_empty_headers(), and octstr_duplicate.

Referenced by add_push_flag(), create_session(), indicate_confirmedpush(), indicate_push_connection(), indicate_push_resume(), indicate_resume(), make_session_request(), mime_entity_headers(), mime_entity_to_octstr(), mime_replace_headers(), mime_something_to_entity(), pap_request_thread(), push_machine_create(), remember_receiver(), request_confirmed_push(), request_push(), request_unit_push(), and server_create().

02802 {
02803     List *new;
02804     long i, len;
02805 
02806     gwlib_assert_init();
02807 
02808     if (headers == NULL)
02809         return NULL;
02810 
02811     new = http_create_empty_headers();
02812     len = gwlist_len(headers);
02813     for (i = 0; i < len; ++i)
02814         gwlist_append(new, octstr_duplicate(gwlist_get(headers, i)));
02815     return new;
02816 }

Here is the call graph for this function:

List* http_header_find_all List headers,
char *  name
 

Definition at line 2947 of file http.c.

References gw_assert, gwlib_assert_init(), gwlist_append(), gwlist_create, gwlist_get(), gwlist_len(), header_is_called(), name, and octstr_duplicate.

Referenced by content_transformable(), http_remove_hop_headers(), http_something_accepted(), make_session_request(), and split_header_list().

02948 {
02949     List *list;
02950     long i;
02951     Octstr *h;
02952 
02953     gwlib_assert_init();
02954     gw_assert(headers != NULL);
02955     gw_assert(name != NULL);
02956 
02957     list = gwlist_create();
02958     for (i = 0; i < gwlist_len(headers); ++i) {
02959         h = gwlist_get(headers, i);
02960         if (header_is_called(h, name))
02961             gwlist_append(list, octstr_duplicate(h));
02962     }
02963     return list;
02964 }

Here is the call graph for this function:

Octstr* http_header_find_first_real List headers,
char *  name,
const char *  file,
long  line,
const char *  func
 

Definition at line 2922 of file http.c.

References file, gw_assert, gwlib_assert_init(), gwlist_get(), gwlist_len(), header_is_called(), name, name_len, octstr_copy_real(), octstr_len(), and octstr_strip_blanks().

02924 {
02925     long i, name_len;
02926     Octstr *h, *value;
02927 
02928     gwlib_assert_init();
02929     gw_assert(headers != NULL);
02930     gw_assert(name != NULL);
02931 
02932     name_len = strlen(name);
02933 
02934     for (i = 0; i < gwlist_len(headers); ++i) {
02935         h = gwlist_get(headers, i);
02936         if (header_is_called(h, name)) {
02937             value = octstr_copy_real(h, name_len + 1, octstr_len(h),
02938                                      file, line, func);
02939         octstr_strip_blanks(value);
02940         return value;
02941     }
02942     }
02943     return NULL;
02944 }

Here is the call graph for this function:

void http_header_get List headers,
long  i,
Octstr **  name,
Octstr **  value
 

Definition at line 2734 of file http.c.

References error(), gw_assert, gwlib_assert_init(), gwlist_get(), name, octstr_copy, octstr_create, octstr_duplicate, octstr_len(), octstr_search_char(), and octstr_strip_blanks().

Referenced by check_application_headers(), content_transformable(), decode_bearer_indication(), get_x_kannel_from_headers(), http_header_combine(), http_header_pack(), pack_appid_list(), smsbox_sendota_post(), and wsp_headers_pack().

02735 {
02736     Octstr *os;
02737     long colon;
02738 
02739     gwlib_assert_init();
02740     gw_assert(i >= 0);
02741     gw_assert(name != NULL);
02742     gw_assert(value != NULL);
02743 
02744     os = gwlist_get(headers, i);
02745     if (os == NULL)
02746         colon = -1;
02747     else
02748         colon = octstr_search_char(os, ':', 0);
02749     if (colon == -1) {
02750         error(0, "HTTP: Header does not contain a colon. BAD.");
02751         *name = octstr_create("X-Unknown");
02752         *value = octstr_duplicate(os);
02753     } else {
02754         *name = octstr_copy(os, 0, colon);
02755         *value = octstr_copy(os, colon + 1, octstr_len(os));
02756         octstr_strip_blanks(*value);
02757     }
02758 }

Here is the call graph for this function:

void http_header_get_content_type List headers,
Octstr **  type,
Octstr **  charset
 

Definition at line 3057 of file http.c.

References charset, gw_assert, gwlib_assert_init(), http_header_find_first, octstr_append_cstr(), octstr_create, octstr_delete(), octstr_duplicate, octstr_get_char(), octstr_imm(), octstr_len(), octstr_ncompare(), octstr_search_char(), octstr_strip_blanks(), octstr_truncate(), and type.

Referenced by mime_entity_dump_real(), numhash_create(), receive_reply(), return_reply(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_xmlrpc_post(), start_fetch(), transform_message(), and url_result_thread().

03059 {
03060     Octstr *h;
03061     long semicolon, equals, len;
03062 
03063     gwlib_assert_init();
03064     gw_assert(headers != NULL);
03065     gw_assert(type != NULL);
03066     gw_assert(charset != NULL);
03067 
03068     h = http_header_find_first(headers, "Content-Type");
03069     if (h == NULL) {
03070         *type = octstr_create("application/octet-stream");
03071         *charset = octstr_create("");
03072     } else {
03073         octstr_strip_blanks(h);
03074         semicolon = octstr_search_char(h, ';', 0);
03075         if (semicolon == -1) {
03076             *type = h;
03077             *charset = octstr_create("");
03078         } else {
03079             *charset = octstr_duplicate(h);
03080             octstr_delete(*charset, 0, semicolon + 1);
03081             octstr_strip_blanks(*charset);
03082             equals = octstr_search_char(*charset, '=', 0);
03083             if (equals == -1)
03084                 octstr_truncate(*charset, 0);
03085             else {
03086                 octstr_delete(*charset, 0, equals + 1);
03087                 if (octstr_get_char(*charset, 0) == '"')
03088                     octstr_delete(*charset, 0, 1);
03089                 len = octstr_len(*charset);
03090                 if (octstr_get_char(*charset, len - 1) == '"')
03091                     octstr_truncate(*charset, len - 1);
03092             }
03093 
03094             octstr_truncate(h, semicolon);
03095             octstr_strip_blanks(h);
03096             *type = h;
03097         }
03098 
03099         /* 
03100          * According to HTTP/1.1 (RFC 2616, section 3.7.1) we have to ensure
03101          * to return charset 'iso-8859-1' in case of no given encoding and
03102          * content-type is a 'text' subtype. 
03103          */
03104         if (octstr_len(*charset) == 0 && 
03105             octstr_ncompare(*type, octstr_imm("text"), 4) == 0)
03106             octstr_append_cstr(*charset, "ISO-8859-1");
03107     }
03108 }

Here is the call graph for this function:

void http_header_mark_transformation List headers,
Octstr new_body,
Octstr new_type
 

Definition at line 3035 of file http.c.

References http_header_add(), http_header_remove_all(), octstr_destroy(), octstr_format(), octstr_get_cstr, and octstr_len().

Referenced by handle_push_message(), return_reply(), and start_fetch().

03037 {
03038     Octstr *new_length = NULL;
03039 
03040     /* Remove all headers that no longer apply to the new body. */
03041     http_header_remove_all(headers, "Content-Length");
03042     http_header_remove_all(headers, "Content-MD5");
03043     http_header_remove_all(headers, "Content-Type");
03044 
03045     /* Add headers that we need to describe the new body. */
03046     new_length = octstr_format("%ld", octstr_len(new_body));
03047     http_header_add(headers, "Content-Length", octstr_get_cstr(new_length));
03048     if(octstr_len(new_type))
03049     http_header_add(headers, "Content-Type", octstr_get_cstr(new_type));
03050 
03051     /* Perhaps we should add Warning: 214 "Transformation applied" too? */
03052 
03053     octstr_destroy(new_length);
03054 }

Here is the call graph for this function:

void http_header_pack List headers  ) 
 

Definition at line 2824 of file http.c.

References gw_assert, gwlib_assert_init(), gwlist_delete(), gwlist_get(), gwlist_insert(), gwlist_len(), http_header_get(), name, octstr_append(), octstr_case_compare(), octstr_create, octstr_destroy(), octstr_imm(), and octstr_len().

Referenced by start_fetch().

02825 {
02826     Octstr *name, *value;
02827     Octstr *name2, *value2;
02828     long i, j;
02829 
02830     gwlib_assert_init();
02831     gw_assert(headers != NULL);
02832 
02833     /*
02834      * For each header, search forward headers for similar ones and if possible, 
02835      * add it to current header and delete it
02836      */
02837     for(i = 0; i < gwlist_len(headers); i++) {
02838         http_header_get(headers, i, &name, &value);
02839     /* debug("http_header_pack", 0, "HTTP_HEADER_PACK: Processing header %d. [%s: %s]", 
02840            i, octstr_get_cstr(name), octstr_get_cstr(value)); */
02841 
02842         for(j=i+1; j < gwlist_len(headers); j++) {
02843             http_header_get(headers, j, &name2, &value2);
02844 
02845             if(octstr_case_compare(name, name2) == 0) {
02846                 if(octstr_len(value) + 2 + octstr_len(value2) > MAX_HEADER_LENGTH) {
02847             octstr_destroy(name2);
02848             octstr_destroy(value2);
02849                     break;
02850                 } else {
02851             Octstr *header;
02852 
02853             /* Delete old header */
02854             header = gwlist_get(headers, i);
02855             octstr_destroy(header);
02856                     gwlist_delete(headers, i, 1);
02857 
02858             /* Adds comma and new value to old header value */
02859                     octstr_append(value, octstr_imm(", "));
02860                     octstr_append(value, value2);
02861             /* Creates a new header */
02862             header = octstr_create("");
02863                     octstr_append(header, name);
02864                     octstr_append(header, octstr_imm(": "));
02865                     octstr_append(header, value);
02866                     gwlist_insert(headers, i, header);
02867 
02868             /* Delete this header */
02869             header = gwlist_get(headers, j);
02870             octstr_destroy(header);
02871                     gwlist_delete(headers, j, 1);
02872                     j--;
02873                 }
02874             }
02875         octstr_destroy(name2);
02876         octstr_destroy(value2);
02877         }
02878     octstr_destroy(name);
02879     octstr_destroy(value);
02880     }
02881 }

Here is the call graph for this function:

long http_header_quoted_string_len Octstr header,
long  pos
 

Definition at line 3125 of file http.c.

References octstr_get_char(), octstr_get_cstr, octstr_len(), and warning().

Referenced by http_get_header_parameter(), http_header_split_value(), pack_warning(), and wsp_strip_parameters().

03126 {
03127     long len;
03128     long pos;
03129     int c;
03130 
03131     if (octstr_get_char(header, start) != '"')
03132     return -1;
03133 
03134     len = octstr_len(header);
03135     for (pos = start + 1; pos < len; pos++) {
03136     c = octstr_get_char(header, pos);
03137     if (c == '\\')    /* quoted-pair */
03138         pos++;
03139     else if (c == '"')
03140         return pos - start + 1;
03141     }
03142 
03143     warning(0, "Header contains unterminated quoted-string:");
03144     warning(0, "%s", octstr_get_cstr(header));
03145     return len - start;
03146 }

Here is the call graph for this function:

long http_header_remove_all List headers,
char *  name
 

Definition at line 2967 of file http.c.

References gw_assert, gwlib_assert_init(), gwlist_delete(), gwlist_get(), gwlist_len(), header_is_called(), name, and octstr_destroy().

Referenced by add_msisdn(), change_header_value(), check_x_wap_application_id_header(), fix_boundary_element(), handle_push_message(), http_header_combine(), http_header_mark_transformation(), http_remove_hop_headers(), pap_request_thread(), remove_link_headers(), remove_mime_headers(), remove_x_kannel_headers(), return_reply(), send_request(), set_addr_tuple(), split_header_list(), start_fetch(), and xmlrpc_doc_send().

02968 {
02969     long i;
02970     Octstr *h;
02971     long count;
02972 
02973     gwlib_assert_init();
02974     gw_assert(headers != NULL);
02975     gw_assert(name != NULL);
02976 
02977     i = 0;
02978     count = 0;
02979     while (i < gwlist_len(headers)) {
02980     h = gwlist_get(headers, i);
02981     if (header_is_called(h, name)) {
02982         gwlist_delete(headers, i, 1);
02983         octstr_destroy(h);
02984         count++;
02985     } else
02986         i++;
02987     }
02988 
02989     return count;
02990 }

Here is the call graph for this function:

List* http_header_split_auth_value Octstr value  ) 
 

Definition at line 3183 of file http.c.

References gwlist_delete(), gwlist_get(), gwlist_len(), http_header_split_value(), octstr_append(), octstr_append_char(), octstr_destroy(), octstr_get_char(), octstr_insert_data(), octstr_len(), and result.

Referenced by pack_known_header().

03184 {
03185     List *result;
03186     Octstr *auth_scheme;
03187     Octstr *element;
03188     long i;
03189 
03190     /*
03191      * According to RFC2617, both "challenge" and "credentials"
03192      * consist of an auth-scheme followed by a list of auth-param.
03193      * Since we have to parse a list of challenges or credentials,
03194      * we have to look for auth-scheme to signal the start of
03195      * a new element.  (We can't just split on commas because
03196      * they are also used to separate the auth-params.)
03197      *
03198      * An auth-scheme is a single token, while an auth-param is
03199      * always a key=value pair.  So we can recognize an auth-scheme
03200      * as a token that is not followed by a '=' sign.
03201      *
03202      * Simple approach: First split at all commas, then recombine
03203      * the elements that belong to the same challenge or credential.
03204      * This is somewhat expensive but saves programmer thinking time.
03205      *
03206      * Richard Braakman
03207      */
03208  
03209     result = http_header_split_value(value);
03210     if (gwlist_len(result) == 0)
03211         return result;
03212 
03213     auth_scheme = gwlist_get(result, 0);
03214     i = 1;
03215     while (i < gwlist_len(result)) {
03216         int c;
03217         long pos;
03218 
03219         element = gwlist_get(result, i);
03220 
03221         /*
03222          * If the element starts with: token '='
03223          * then it's just an auth_param; append it to the current
03224          * auth_scheme.  If it starts with: token token '='
03225          * then it's the start of a new auth scheme.
03226          *
03227          * To make the scan easier, we consider anything other
03228          * than whitespace or '=' to be part of a token.
03229          */
03230 
03231         /* Skip first token */
03232         for (pos = 0; pos < octstr_len(element); pos++) {
03233             c = octstr_get_char(element, pos);
03234             if (isspace(c) || c == '=')
03235                 break;
03236         }
03237 
03238         /* Skip whitespace, if any */
03239         while (isspace(octstr_get_char(element, pos)))
03240             pos++;
03241 
03242         if (octstr_get_char(element, pos) == '=') {
03243             octstr_append_char(auth_scheme, ';');
03244             octstr_append(auth_scheme, element);
03245             gwlist_delete(result, i, 1);
03246             octstr_destroy(element);
03247         } else {
03248             char semicolon = ';';
03249             octstr_insert_data(element, pos, &semicolon, 1);
03250             auth_scheme = element;
03251             i++;
03252         }
03253     }
03254 
03255     return result;
03256 }

Here is the call graph for this function:

List* http_header_split_value Octstr value  ) 
 

Definition at line 3149 of file http.c.

References gwlist_create, http_header_add_element(), http_header_quoted_string_len(), octstr_get_char(), octstr_len(), and result.

Referenced by http_header_split_auth_value(), http_remove_hop_headers(), pack_cache_control(), and pack_known_header().

03150 {
03151     long start;  /* start of current element */
03152     long pos;
03153     long len;
03154     List *result;
03155     int c;
03156 
03157     /*
03158      * According to RFC2616 section 4.2, a field-value is either *TEXT
03159      * (the caller is responsible for not feeding us one of those) or
03160      * combinations of token, separators, and quoted-string.  We're
03161      * looking for commas which are separators, and have to skip
03162      * commas in quoted-strings.
03163      */
03164  
03165     result = gwlist_create();
03166     len = octstr_len(value);
03167     start = 0;
03168     for (pos = 0; pos < len; pos++) {
03169     c = octstr_get_char(value, pos);
03170     if (c == ',') {
03171         http_header_add_element(result, value, start, pos);
03172         start = pos + 1;
03173     } else if (c == '"') {
03174             pos += http_header_quoted_string_len(value, pos);
03175         pos--; /* compensate for the loop's pos++ */
03176         }
03177     }
03178     http_header_add_element(result, value, start, len);
03179     return result;
03180 }

Here is the call graph for this function:

Octstr* http_header_value List headers,
Octstr header
 

Definition at line 2764 of file http.c.

References gw_assert, gwlib_assert_init(), gwlist_get(), gwlist_len(), name, octstr_case_compare(), octstr_copy, octstr_destroy(), octstr_len(), octstr_search_char(), and octstr_strip_blanks().

Referenced by add_msisdn(), add_via(), cid_matches(), client_thread(), fix_boundary_element(), mime_entity_dump_real(), mime_multipart_start_elem(), mime_something_to_entity(), return_reply(), set_addr_tuple(), set_dlr_mask(), set_dlr_url(), set_smsbox_id(), and set_smsc_id().

02765 {
02766     Octstr *value;
02767     long i;
02768     Octstr *os;
02769     long colon;
02770     Octstr *current_name;
02771     
02772     gwlib_assert_init();
02773     gw_assert(name);
02774     
02775     value = NULL;
02776     i = 0;
02777     while (i < gwlist_len(headers)) {
02778         os = gwlist_get(headers, i);
02779         if (os == NULL)
02780             colon = -1;
02781         else
02782             colon = octstr_search_char(os, ':', 0);
02783         if (colon == -1) {
02784             return NULL;      
02785         } else {
02786             current_name = octstr_copy(os, 0, colon);
02787         }
02788         if (octstr_case_compare(current_name, name) == 0) {
02789             value = octstr_copy(os, colon + 1, octstr_len(os));
02790             octstr_strip_blanks(value);
02791             octstr_destroy(current_name);
02792             return value;
02793         }
02794         octstr_destroy(current_name);
02795         ++i;
02796     }
02797     
02798     return NULL;
02799 }

Here is the call graph for this function:

void http_init void   ) 
 

Definition at line 3427 of file http.c.

References client_init(), conn_init_ssl(), conn_pool_init(), gw_assert, limbo, openssl_init_locks(), port_init(), proxy_init(), run_status, server_init(), and server_ssl_init().

Referenced by gwlib_init().

03428 {
03429     gw_assert(run_status == limbo);
03430 
03431 #ifdef HAVE_LIBSSL
03432     openssl_init_locks();
03433     conn_init_ssl();
03434 #endif /* HAVE_LIBSSL */
03435     proxy_init();
03436     client_init();
03437     conn_pool_init();
03438     port_init();
03439     server_init();
03440 #ifdef HAVE_LIBSSL
03441     server_ssl_init();
03442 #endif /* HAVE_LIBSSL */
03443     
03444     run_status = running;
03445 }

Here is the call graph for this function:

char* http_method2name int  method  ) 
 

Definition at line 3503 of file http.c.

References gw_assert, and http_methods.

Referenced by send_request().

03504 {
03505     gw_assert(method > 0 && method <= 3);
03506 
03507     return http_methods[method-1];
03508 }

int http_name2method Octstr method  ) 
 

Definition at line 3485 of file http.c.

References gw_assert, and octstr_str_compare().

Referenced by main(), and start_fetch().

03486 {
03487     gw_assert(method != NULL);
03488 
03489     if (octstr_str_compare(method, "GET") == 0) {
03490         return HTTP_METHOD_GET;
03491     } 
03492     else if (octstr_str_compare(method, "POST") == 0) {
03493         return HTTP_METHOD_POST;
03494     } 
03495     else if (octstr_str_compare(method, "HEAD") == 0) {
03496         return HTTP_METHOD_HEAD;
03497     } 
03498 
03499     return -1;
03500 }

Here is the call graph for this function:

int http_open_port int  port,
int  ssl
 

Definition at line 2357 of file http.c.

References http_open_port_if(), port, and ssl.

Referenced by httpd_emu_create(), main(), soap_server_start(), start_http_thread(), and wap_push_ppg_init().

02358 {
02359     return http_open_port_if(port, ssl, NULL);
02360 }

Here is the call graph for this function:

int http_open_port_if int  port,
int  ssl,
Octstr interface
 

Definition at line 2330 of file http.c.

References server::fd, gwlist_produce(), gwthread_wakeup(), info(), keep_servers_open, make_server_socket(), new_server_sockets, octstr_get_cstr, server::port, port, port_add(), server_thread_id, server::ssl, and start_server_thread().

Referenced by http_open_port(), httpadmin_start(), init_smsbox(), and smsc_http_create().

02331 {
02332     struct server *p;
02333 
02334     if (ssl) 
02335         info(0, "HTTP: Opening SSL server at port %d.", port);
02336     else 
02337         info(0, "HTTP: Opening server at port %d.", port);
02338     p = gw_malloc(sizeof(*p));
02339     p->port = port;
02340     p->ssl = ssl;
02341     p->fd = make_server_socket(port, (interface ? octstr_get_cstr(interface) : NULL));
02342     if (p->fd == -1) {
02343     gw_free(p);
02344         return -1;
02345     }
02346 
02347     port_add(port);
02348     gwlist_produce(new_server_sockets, p);
02349     keep_servers_open = 1;
02350     start_server_thread();
02351     gwthread_wakeup(server_thread_id);
02352 
02353     return 0;
02354 }

Here is the call graph for this function:

void* http_receive_result_real HTTPCaller caller,
int *  status,
Octstr **  final_url,
List **  headers,
Octstr **  body,
int  blocking
 

Definition at line 1692 of file http.c.

References HTTPEntity::body, gwlist_consume(), gwlist_extract_first(), HTTPEntity::headers, HTTPCaller, HTTPServer::request_id, HTTPServer::response, server_destroy(), HTTPServer::status, and HTTPServer::url.

01694 {
01695     HTTPServer *trans;
01696     void *request_id;
01697 
01698     if (blocking == 0)
01699         trans = gwlist_extract_first(caller);
01700     else
01701         trans = gwlist_consume(caller);
01702     if (trans == NULL)
01703         return NULL;
01704 
01705     request_id = trans->request_id;
01706     *status = trans->status;
01707     
01708     if (trans->status >= 0) {
01709         *final_url = trans->url;
01710         *headers = trans->response->headers;
01711         *body = trans->response->body;
01712 
01713         trans->url = NULL;
01714         trans->response->headers = NULL;
01715         trans->response->body = NULL;
01716     } else {
01717        *final_url = NULL;
01718        *headers = NULL;
01719        *body = NULL;
01720     }
01721 
01722     server_destroy(trans);
01723     return request_id;
01724 }

Here is the call graph for this function:

void http_remove_hop_headers List headers  ) 
 

Definition at line 2993 of file http.c.

References gw_assert, gwlib_assert_init(), gwlist_consume(), gwlist_destroy(), http_header_find_all(), http_header_remove_all(), http_header_split_value(), octstr_delete(), octstr_destroy(), and octstr_get_cstr.

Referenced by pap_request_thread(), return_reply(), and start_fetch().

02994 {
02995     Octstr *h;
02996     List *connection_headers;
02997 
02998     gwlib_assert_init();
02999     gw_assert(headers != NULL);
03000 
03001     /*
03002      * The hop-by-hop headers are a standard list, plus those named
03003      * in the Connection header(s).
03004      */
03005 
03006     connection_headers = http_header_find_all(headers, "Connection");
03007     while ((h = gwlist_consume(connection_headers))) {
03008     List *hop_headers;
03009     Octstr *e;
03010 
03011     octstr_delete(h, 0, strlen("Connection:"));
03012     hop_headers = http_header_split_value(h);
03013     octstr_destroy(h);
03014 
03015     while ((e = gwlist_consume(hop_headers))) {
03016         http_header_remove_all(headers, octstr_get_cstr(e));
03017         octstr_destroy(e);
03018     }
03019 
03020     gwlist_destroy(hop_headers, NULL);
03021     }
03022     gwlist_destroy(connection_headers, NULL);
03023    
03024     http_header_remove_all(headers, "Connection");
03025     http_header_remove_all(headers, "Keep-Alive");
03026     http_header_remove_all(headers, "Proxy-Authenticate");
03027     http_header_remove_all(headers, "Proxy-Authorization");
03028     http_header_remove_all(headers, "TE");
03029     http_header_remove_all(headers, "Trailers");
03030     http_header_remove_all(headers, "Transfer-Encoding");
03031     http_header_remove_all(headers, "Upgrade");
03032 }

Here is the call graph for this function:

void http_send_reply HTTPClient client,
int  status,
List headers,
Octstr body
 

Definition at line 2532 of file http.c.

References client_destroy(), client_reset(), HTTPClient::conn, conn_register, conn_write(), date_format_http(), GW_NAME, GW_VERSION, gwlist_get(), gwlist_len(), http_reason_phrase(), HTTPClient::method, octstr_append(), octstr_destroy(), octstr_format(), octstr_format_append(), octstr_get_cstr, octstr_len(), HTTPClient::persistent_conn, receive_request(), response, server_fdset, HTTPClient::state, and HTTPClient::use_version_1_0.

Referenced by brunet_receive_sms(), challenge(), clickatell_receive_sms(), client_thread(), delayed_http_reply(), http_thread(), httpd_emu_reply(), httpd_serve(), kannel_receive_sms(), pap_request_thread(), receive_request(), reply(), send_to_pi(), sendsms_thread(), soap_server(), and xidris_receive_sms().

02534 {
02535     Octstr *response;
02536     Octstr *date;
02537     long i;
02538     int ret;
02539 
02540     if (client->use_version_1_0)
02541         response = octstr_format("HTTP/1.0 %d %s\r\n", status, http_reason_phrase(status));
02542     else
02543         response = octstr_format("HTTP/1.1 %d %s\r\n", status, http_reason_phrase(status));
02544 
02545     /* identify ourselfs */
02546     octstr_format_append(response, "Server: " GW_NAME "/%s\r\n", GW_VERSION);
02547     
02548     /* let's inform the client of our time */
02549     date = date_format_http(time(NULL));
02550     octstr_format_append(response, "Date: %s\r\n", octstr_get_cstr(date));
02551     octstr_destroy(date);
02552     
02553     octstr_format_append(response, "Content-Length: %ld\r\n",
02554              octstr_len(body));
02555 
02556     /* 
02557      * RFC2616, sec. 8.1.2.1 says that if the server chooses to close the 
02558      * connection, it *should* send a coresponding header
02559      */
02560     if (!client->use_version_1_0 && !client->persistent_conn)
02561         octstr_format_append(response, "Connection: close\r\n");
02562 
02563     for (i = 0; i < gwlist_len(headers); ++i)
02564         octstr_format_append(response, "%S\r\n", gwlist_get(headers, i));
02565     octstr_format_append(response, "\r\n");
02566     
02567     if (body != NULL && client->method != HTTP_METHOD_HEAD)
02568         octstr_append(response, body);
02569     
02570     ret = conn_write(client->conn, response);
02571     octstr_destroy(response);
02572 
02573     /* obey return code of conn_write() */
02574     /* sending response was successful */
02575     if (ret == 0) { 
02576         /* HTTP/1.0 or 1.1, hence keep-alive or keep-alive */
02577         if (!client->persistent_conn) {
02578             client_destroy(client);     
02579         } else {
02580             /* XXX mark this HTTPClient in the keep-alive cleaner thread */
02581             client_reset(client);
02582             conn_register(client->conn, server_fdset, receive_request, client);
02583         }
02584     }
02585     /* queued for sending, we don't want to block */
02586     else if (ret == 1) {    
02587         client->state = sending_reply;
02588         conn_register(client->conn, server_fdset, receive_request, client);
02589     }
02590     /* error while sending response */
02591     else {     
02592         client_destroy(client);
02593     }
02594 }

Here is the call graph for this function:

void http_set_client_timeout long  timeout  ) 
 

Define timeout in seconds for which HTTP clint will wait for response. Set -1 to disable timeouts.

Definition at line 1657 of file http.c.

References client_fdset, fdset_set_timeout(), and http_client_timeout.

01658 {
01659     http_client_timeout = timeout;
01660     if (client_fdset != NULL) {
01661         /* we are already initialized set timeout in fdset */
01662         fdset_set_timeout(client_fdset, http_client_timeout);
01663     }
01664 }

Here is the call graph for this function:

void http_set_interface const Octstr our_host  ) 
 

Definition at line 1652 of file http.c.

References http_interface, and octstr_duplicate.

Referenced by config_reload().

01653 {
01654     http_interface = octstr_duplicate(our_host);
01655 }

void http_shutdown void   ) 
 

Definition at line 3448 of file http.c.

References client_shutdown(), conn_pool_shutdown(), conn_shutdown_ssl(), gw_assert, gwlib_assert_init(), openssl_shutdown_locks(), port_shutdown(), proxy_shutdown(), run_status, running, server_shutdown(), and server_shutdown_ssl().

Referenced by gwlib_shutdown().

03449 {
03450     gwlib_assert_init();
03451     gw_assert(run_status == running);
03452 
03453     run_status = terminating;
03454 
03455     conn_pool_shutdown();
03456     client_shutdown();
03457     server_shutdown();
03458     port_shutdown();
03459     proxy_shutdown();
03460 #ifdef HAVE_LIBSSL
03461     openssl_shutdown_locks();
03462     conn_shutdown_ssl();
03463     server_shutdown_ssl();
03464 #endif /* HAVE_LIBSSL */
03465     run_status = limbo;
03466 }

Here is the call graph for this function:

void http_start_request HTTPCaller caller,
int  method,
Octstr url,
List headers,
Octstr body,
int  follow,
void *  id,
Octstr certkeyfile
 

Definition at line 1666 of file http.c.

References gwlist_produce(), HTTPCaller, pending_requests, HTTPServer::request_id, server_create(), and start_client_threads().

Referenced by brunet_send_sms(), clickatell_send_sms(), generic_send_sms(), http_get_real(), http_queue_thread(), kannel_send_sms(), obey_request(), receive_push_reply(), soap_client_init_query(), start_fetch(), start_push(), start_request(), wapme_smsproxy_send_sms(), xidris_send_sms(), and xmlrpc_doc_send().

01668 {
01669     HTTPServer *trans;
01670     int follow_remaining;
01671     
01672     if (follow)
01673         follow_remaining = HTTP_MAX_FOLLOW;
01674     else
01675         follow_remaining = 0;
01676 
01677     trans = server_create(caller, method, url, headers, body, follow_remaining, 
01678               certkeyfile);
01679 
01680     if (id == NULL)
01681         /* We don't leave this NULL so http_receive_result can use NULL
01682          * to signal no more requests */
01683         trans->request_id = http_start_request;
01684     else
01685         trans->request_id = id;
01686         
01687     gwlist_produce(pending_requests, trans);
01688     start_client_threads();
01689 }

Here is the call graph for this function:

int http_status_class int  code  ) 
 

Definition at line 3473 of file http.c.

References code.

Referenced by handle_transaction(), response_expectation(), and return_reply().

03474 {
03475     int sclass;
03476 
03477     if (code < 100 || code >= 600)
03478         sclass = HTTP_STATUS_UNKNOWN;
03479     else
03480         sclass = code - (code % 100);
03481     return sclass;
03482 }

int http_type_accepted List headers,
char *  type
 

Definition at line 3332 of file http.c.

References http_something_accepted(), and type.

Referenced by add_accept_headers(), check_session_request_headers(), convert_content(), httpd_serve(), and return_reply().

03333 {
03334     return http_something_accepted(headers, "Accept", type);
03335 }

Here is the call graph for this function:

HTTPURLParse* http_urlparse_create void   ) 
 

Definition at line 1226 of file http.c.

References HTTPURLParse::fragment, HTTPURLParse::host, HTTPURLParse::pass, HTTPURLParse::path, HTTPURLParse::port, HTTPURLParse::query, HTTPURLParse::scheme, HTTPURLParse::url, and HTTPURLParse::user.

Referenced by parse_url().

01227 {
01228     HTTPURLParse *p;
01229 
01230     p = gw_malloc(sizeof(HTTPURLParse));
01231     p->url = NULL;
01232     p->scheme = NULL;
01233     p->host = NULL;
01234     p->port = 0;
01235     p->user = NULL;
01236     p->pass = NULL;
01237     p->path = NULL;
01238     p->query = NULL;
01239     p->fragment = NULL;
01240     
01241     return p;
01242 }

void http_urlparse_destroy HTTPURLParse p  ) 
 

Definition at line 1245 of file http.c.

References HTTPURLParse::fragment, gw_assert, HTTPURLParse::host, octstr_destroy(), HTTPURLParse::pass, HTTPURLParse::path, HTTPURLParse::query, HTTPURLParse::scheme, HTTPURLParse::url, and HTTPURLParse::user.

Referenced by get_connection(), and parse_url().

01246 {
01247     gw_assert(p != NULL);
01248 
01249     octstr_destroy(p->url);
01250     octstr_destroy(p->scheme);
01251     octstr_destroy(p->host);
01252     octstr_destroy(p->user);
01253     octstr_destroy(p->pass);
01254     octstr_destroy(p->path);
01255     octstr_destroy(p->query);
01256     octstr_destroy(p->fragment);
01257     gw_free(p);
01258 }

Here is the call graph for this function:

void http_use_proxy Octstr hostname,
int  port,
int  ssl,
List exceptions,
Octstr username,
Octstr password,
Octstr exceptions_regex
 

Definition at line 266 of file http.c.

References debug(), gw_assert, gwlist_append(), gwlist_create, gwlist_get(), gwlist_len(), hostname, http_close_proxy(), mutex_lock, mutex_unlock, octstr_duplicate, octstr_get_cstr, octstr_len(), panic, password, port, proxy_exceptions, proxy_exceptions_regex, proxy_hostname, proxy_mutex, proxy_password, proxy_port, proxy_ssl, proxy_username, run_status, running, and username.

Referenced by config_reload(), init_smsbox(), and main().

00268 {
00269     Octstr *e;
00270     int i;
00271 
00272     gw_assert(run_status == running);
00273     gw_assert(hostname != NULL);
00274     gw_assert(octstr_len(hostname) > 0);
00275     gw_assert(port > 0);
00276 
00277     http_close_proxy();
00278     mutex_lock(proxy_mutex);
00279 
00280     proxy_hostname = octstr_duplicate(hostname);
00281     proxy_port = port;
00282     proxy_ssl = ssl;
00283     proxy_exceptions = gwlist_create();
00284     for (i = 0; i < gwlist_len(exceptions); ++i) {
00285         e = gwlist_get(exceptions, i);
00286         debug("gwlib.http", 0, "HTTP: Proxy exception `%s'.", octstr_get_cstr(e));
00287         gwlist_append(proxy_exceptions, octstr_duplicate(e));
00288     }
00289     if (exceptions_regex != NULL &&
00290         (proxy_exceptions_regex = gw_regex_comp(exceptions_regex, REG_EXTENDED)) == NULL)
00291             panic(0, "Could not compile pattern '%s'", octstr_get_cstr(exceptions_regex));
00292     proxy_username = octstr_duplicate(username);
00293     proxy_password = octstr_duplicate(password);
00294     debug("gwlib.http", 0, "Using proxy <%s:%d> with %s scheme", 
00295           octstr_get_cstr(proxy_hostname), proxy_port,
00296           (proxy_ssl ? "HTTPS" : "HTTP"));
00297 
00298     mutex_unlock(proxy_mutex);
00299 }

Here is the call graph for this function:

void parse_dump HTTPURLParse p  ) 
 

Definition at line 1261 of file http.c.

References debug(), HTTPURLParse::fragment, HTTPURLParse::host, octstr_get_cstr, HTTPURLParse::pass, HTTPURLParse::path, HTTPURLParse::port, HTTPURLParse::query, HTTPURLParse::scheme, HTTPURLParse::url, and HTTPURLParse::user.

Referenced by parse_url().

01262 {
01263     if (p == NULL)
01264         return;
01265     debug("http.parse_url",0,"Parsing URL `%s':", octstr_get_cstr(p->url));
01266     debug("http.parse_url",0,"  Scheme: %s", octstr_get_cstr(p->scheme));  
01267     debug("http.parse_url",0,"  Host: %s", octstr_get_cstr(p->host));  
01268     debug("http.parse_url",0,"  Port: %ld", p->port);  
01269     debug("http.parse_url",0,"  Username: %s", octstr_get_cstr(p->user));  
01270     debug("http.parse_url",0,"  Password: %s", octstr_get_cstr(p->pass));  
01271     debug("http.parse_url",0,"  Path: %s", octstr_get_cstr(p->path));  
01272     debug("http.parse_url",0,"  Query: %s", octstr_get_cstr(p->query));  
01273     debug("http.parse_url",0,"  Fragment: %s", octstr_get_cstr(p->fragment));  
01274 }

Here is the call graph for this function:

HTTPURLParse* parse_url Octstr url  ) 
 

Definition at line 1290 of file http.c.

References debug(), error(), HTTPURLParse::host, http_urlparse_create(), http_urlparse_destroy(), HTTPS_PORT, octstr_case_search(), octstr_compare(), octstr_copy, octstr_create, octstr_duplicate, octstr_get_cstr, octstr_imm(), octstr_len(), octstr_parse_long(), octstr_search_char(), octstr_set_char(), parse_dump(), HTTPURLParse::pass, HTTPURLParse::path, HTTPURLParse::port, HTTPURLParse::query, HTTPURLParse::scheme, HTTPURLParse::url, and HTTPURLParse::user.

Referenced by get_connection().

01291 {
01292     HTTPURLParse *p;
01293     Octstr *prefix, *prefix_https;
01294     long prefix_len;
01295     int host_len, colon, slash, at, auth_sep, query;
01296     host_len = colon = slash = at = auth_sep = query = 0;
01297 
01298     prefix = octstr_imm("http://");
01299     prefix_https = octstr_imm("https://");
01300     prefix_len = octstr_len(prefix);
01301 
01302     if (octstr_case_search(url, prefix, 0) != 0) {
01303         if (octstr_case_search(url, prefix_https, 0) == 0) {
01304 #ifdef HAVE_LIBSSL
01305             debug("gwlib.http", 0, "HTTPS URL; Using SSL for the connection");
01306             prefix = prefix_https;
01307             prefix_len = octstr_len(prefix_https);  
01308 #else
01309             error(0, "Attempt to use HTTPS <%s> but SSL not compiled in", 
01310                   octstr_get_cstr(url));
01311             return NULL;
01312 #endif
01313         } else {
01314             error(0, "URL <%s> doesn't start with `%s' nor `%s'",
01315             octstr_get_cstr(url), octstr_get_cstr(prefix),
01316             octstr_get_cstr(prefix_https));
01317             return NULL;
01318         }
01319     }
01320 
01321     /* an URL should be more (at least one charset) then the scheme itself */
01322     if (octstr_len(url) == prefix_len) {
01323         error(0, "URL <%s> is malformed.", octstr_get_cstr(url));
01324         return NULL;
01325     }
01326 
01327     /* check if colon and slashes are within scheme */
01328     colon = octstr_search_char(url, ':', prefix_len);
01329     slash = octstr_search_char(url, '/', prefix_len);
01330     if (colon == prefix_len || slash == prefix_len) {
01331         error(0, "URL <%s> is malformed.", octstr_get_cstr(url));
01332         return NULL;
01333     }
01334 
01335     /* create struct and add values succesively while parsing */
01336     p = http_urlparse_create();
01337     p->url = octstr_duplicate(url);
01338     p->scheme = octstr_duplicate(prefix);
01339 
01340     /* try to parse authentication separator */
01341     at = octstr_search_char(url, '@', prefix_len);
01342     if (at != -1) {
01343         if ((slash == -1 || ( slash != -1 && at < slash))) {
01344             auth_sep = octstr_search_char(url, ':', prefix_len);
01345             if (auth_sep != -1 && (auth_sep < at)) {
01346                 octstr_set_char(url, auth_sep, '@');
01347                 colon = octstr_search_char(url, ':', prefix_len);
01348             }
01349         } else {
01350             at = -1;
01351         }
01352     }
01353 
01354     /*
01355      * We have to watch out here for 4 cases:
01356      *  a) hostname, no port or path
01357      *  b) hostname, port, no path
01358      *  c) hostname, path, no port
01359      *  d) hostname, port and path
01360      */
01361     
01362     /* we only have the hostname, no port or path. */
01363     if (slash == -1 && colon == -1) {
01364         host_len = octstr_len(url) - prefix_len;
01365 #ifdef HAVE_LIBSSL
01366         p->port = (octstr_compare(p->scheme, octstr_imm("https://")) == 0) ? 
01367             HTTPS_PORT : HTTP_PORT;
01368 #else
01369         p->port = HTTP_PORT;
01370 #endif /* HAVE_LIBSSL */
01371     } 
01372     /* we have a port, but no path. */
01373     else if (slash == -1) {
01374         host_len = colon - prefix_len;
01375         if (octstr_parse_long((long*) &(p->port), url, colon + 1, 10) == -1) {
01376             error(0, "URL <%s> has malformed port number.",
01377                   octstr_get_cstr(url));
01378             http_urlparse_destroy(p);
01379             return NULL;
01380         }
01381     } 
01382     /* we have a path, but no port. */
01383     else if (colon == -1 || colon > slash) {
01384         host_len = slash - prefix_len;
01385 #ifdef HAVE_LIBSSL
01386         p->port = (octstr_compare(p->scheme, octstr_imm("https://")) == 0) ? 
01387             HTTPS_PORT : HTTP_PORT;
01388 #else
01389         p->port = HTTP_PORT;
01390 #endif /* HAVE_LIBSSL */
01391     } 
01392     /* we have both, path and port. */
01393     else if (colon < slash) {
01394         host_len = colon - prefix_len;
01395         if (octstr_parse_long((long*) &(p->port), url, colon + 1, 10) == -1) {
01396             error(0, "URL <%s> has malformed port number.",
01397                   octstr_get_cstr(url));
01398             http_urlparse_destroy(p);
01399             return NULL;
01400         }
01401     /* none of the above, so there is something wrong here */
01402     } else {
01403         error(0, "Internal error in URL parsing logic.");
01404         http_urlparse_destroy(p);
01405         return NULL;
01406     }
01407 
01408     /* there was an authenticator separator, so try to parse 
01409      * the username and password credentials */
01410     if (at != -1) {
01411         int at2;
01412 
01413         at2 = octstr_search_char(url, '@', prefix_len);
01414         p->user = octstr_copy(url, prefix_len, at2 - prefix_len);
01415         p->pass = (at2 != at) ? octstr_copy(url, at2 + 1, at - at2 - 1) : NULL;
01416 
01417         if (auth_sep != -1)
01418             octstr_set_char(url, auth_sep, ':');
01419   
01420         host_len = host_len - at + prefix_len - 1;
01421         prefix_len = at + 1;
01422     }
01423 
01424     /* query (CGI vars) */
01425     query = octstr_search_char(url, '?', (slash == -1) ? prefix_len : slash);
01426     if (query != -1) {
01427         p->query = octstr_copy(url, query + 1, octstr_len(url));
01428     }
01429 
01430     /* path */
01431     p->path = (slash == -1) ? 
01432         octstr_create("/") : ((query != -1) && (query > slash) ? 
01433             octstr_copy(url, slash, query - slash) :
01434             octstr_copy(url, slash, octstr_len(url) - slash)); 
01435 
01436     /* hostname */
01437     p->host = octstr_copy(url, prefix_len, 
01438         (query == -1 || slash != -1) ? host_len : query - prefix_len);
01439 
01440     /* XXX add fragment too */
01441    
01442     /* dump components */
01443     parse_dump(p);
01444 
01445     return p;
01446 }

Here is the call graph for this function:

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.