Kannel: Open Source WAP and SMS gateway  svn-r5335
http.h File Reference
#include "gwlib/list.h"
#include "gwlib/octstr.h"

Go to the source code of this file.

Data Structures

struct  HTTPCGIVar
 
struct  HTTPURLParse
 

Macros

#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 struct HTTPClient HTTPClient
 

Enumerations

enum  {
  HTTP_CONTINUE = 100, HTTP_SWITCHING_PROTOCOLS = 101, HTTP_OK = 200, HTTP_CREATED = 201,
  HTTP_ACCEPTED = 202, HTTP_NON_AUTHORATIVE_INFORMATION = 203, HTTP_NO_CONTENT = 204, HTTP_RESET_CONTENT = 205,
  HTTP_PARTIAL_CONTENT = 206, HTTP_MULTIPLE_CHOICES = 300, HTTP_MOVED_PERMANENTLY = 301, HTTP_FOUND = 302,
  HTTP_SEE_OTHER = 303, HTTP_NOT_MODIFIED = 304, HTTP_USE_PROXY = 305, HTTP_TEMPORARY_REDIRECT = 307,
  HTTP_BAD_REQUEST = 400, HTTP_UNAUTHORIZED = 401, HTTP_PAYMENT_REQUIRED = 402, HTTP_FORBIDDEN = 403,
  HTTP_NOT_FOUND = 404, HTTP_BAD_METHOD = 405, HTTP_NOT_ACCEPTABLE = 406, HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
  HTTP_REQUEST_TIMEOUT = 408, HTTP_CONFLICT = 409, HTTP_GONE = 410, HTTP_LENGTH_REQUIRED = 411,
  HTTP_PRECONDITION_FAILED = 412, HTTP_REQUEST_ENTITY_TOO_LARGE = 413, HTTP_REQUEST_URI_TOO_LARGE = 414, HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
  HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416, HTTP_EXPECTATION_FAILED = 417, HTTP_INTERNAL_SERVER_ERROR = 500, HTTP_NOT_IMPLEMENTED = 501,
  HTTP_BAD_GATEWAY = 502, HTTP_SERVICE_UNAVAILABLE = 503, HTTP_GATEWAY_TIMEOUT = 504, HTTP_HTTP_VERSION_NOT_SUPPORTED = 505
}
 
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, HTTP_METHOD_PUT = 4,
  HTTP_METHOD_DELETE = 5, HTTP_METHOD_PATCH = 6
}
 

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 parse_cgivars (List *cgivars, Octstr *pairs)
 
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)
 
void http_set_server_timeout (int port, long timeout)
 
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)
 
int http_method (HTTPClient *client)
 
Octstrhttp_request_url (HTTPClient *client)
 
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)
 

Macro Definition Documentation

◆ http_header_find_first

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

◆ http_receive_result

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

Typedef Documentation

◆ HTTPCaller

typedef List HTTPCaller

Definition at line 338 of file http.h.

◆ HTTPClient

typedef struct HTTPClient HTTPClient

Definition at line 406 of file http.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
HTTP_CONTINUE 
HTTP_SWITCHING_PROTOCOLS 
HTTP_OK 
HTTP_CREATED 
HTTP_ACCEPTED 
HTTP_NON_AUTHORATIVE_INFORMATION 
HTTP_NO_CONTENT 
HTTP_RESET_CONTENT 
HTTP_PARTIAL_CONTENT 
HTTP_MULTIPLE_CHOICES 
HTTP_MOVED_PERMANENTLY 
HTTP_FOUND 
HTTP_SEE_OTHER 
HTTP_NOT_MODIFIED 
HTTP_USE_PROXY 
HTTP_TEMPORARY_REDIRECT 
HTTP_BAD_REQUEST 
HTTP_UNAUTHORIZED 
HTTP_PAYMENT_REQUIRED 
HTTP_FORBIDDEN 
HTTP_NOT_FOUND 
HTTP_BAD_METHOD 
HTTP_NOT_ACCEPTABLE 
HTTP_PROXY_AUTHENTICATION_REQUIRED 
HTTP_REQUEST_TIMEOUT 
HTTP_CONFLICT 
HTTP_GONE 
HTTP_LENGTH_REQUIRED 
HTTP_PRECONDITION_FAILED 
HTTP_REQUEST_ENTITY_TOO_LARGE 
HTTP_REQUEST_URI_TOO_LARGE 
HTTP_UNSUPPORTED_MEDIA_TYPE 
HTTP_REQUESTED_RANGE_NOT_SATISFIABLE 
HTTP_EXPECTATION_FAILED 
HTTP_INTERNAL_SERVER_ERROR 
HTTP_NOT_IMPLEMENTED 
HTTP_BAD_GATEWAY 
HTTP_SERVICE_UNAVAILABLE 
HTTP_GATEWAY_TIMEOUT 
HTTP_HTTP_VERSION_NOT_SUPPORTED 

Definition at line 139 of file http.h.

139  {
140  HTTP_CONTINUE = 100,
142  HTTP_OK = 200,
143  HTTP_CREATED = 201,
144  HTTP_ACCEPTED = 202,
146  HTTP_NO_CONTENT = 204,
147  HTTP_RESET_CONTENT = 205,
148  HTTP_PARTIAL_CONTENT = 206,
149  HTTP_MULTIPLE_CHOICES = 300,
151  HTTP_FOUND = 302,
152  HTTP_SEE_OTHER = 303,
153  HTTP_NOT_MODIFIED = 304,
154  HTTP_USE_PROXY = 305,
155  /* HTTP 306 is not used and reserved */
157  HTTP_BAD_REQUEST = 400,
158  HTTP_UNAUTHORIZED = 401,
159  HTTP_PAYMENT_REQUIRED = 402,
160  HTTP_FORBIDDEN = 403,
161  HTTP_NOT_FOUND = 404,
162  HTTP_BAD_METHOD = 405,
163  HTTP_NOT_ACCEPTABLE = 406,
165  HTTP_REQUEST_TIMEOUT = 408,
166  HTTP_CONFLICT = 409,
167  HTTP_GONE = 410,
168  HTTP_LENGTH_REQUIRED = 411,
176  HTTP_NOT_IMPLEMENTED = 501,
177  HTTP_BAD_GATEWAY = 502,
179  HTTP_GATEWAY_TIMEOUT = 504,
181 };
Definition: http.h:142

◆ anonymous enum

anonymous enum
Enumerator
HTTP_STATUS_PROVISIONAL 
HTTP_STATUS_SUCCESSFUL 
HTTP_STATUS_REDIRECTION 
HTTP_STATUS_CLIENT_ERROR 
HTTP_STATUS_SERVER_ERROR 
HTTP_STATUS_UNKNOWN 

Definition at line 188 of file http.h.

◆ anonymous enum

anonymous enum
Enumerator
HTTP_METHOD_GET 
HTTP_METHOD_POST 
HTTP_METHOD_HEAD 
HTTP_METHOD_PUT 
HTTP_METHOD_DELETE 
HTTP_METHOD_PATCH 

Definition at line 202 of file http.h.

Function Documentation

◆ http_accept_request()

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

Definition at line 2571 of file http.c.

References charset, client(), client_destroy(), client_is_persistent(), conn_eof(), conn_error(), conn_wait(), content_type, debug(), entity_destroy(), gwlist_create, http_header_get_content_type(), http_method2name(), HTTP_METHOD_POST, HTTP_METHOD_PUT, octstr_copy, octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_len(), octstr_search_char(), octstr_str_compare(), octstr_truncate(), parse_cgivars(), port_get_request(), and url.

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

2574 {
2575  HTTPClient *client;
2576  Octstr *query, *content_type, *charset;
2577  int question_mark;
2578 
2579  do {
2581  if (client == NULL) {
2582  debug("gwlib.http", 0, "HTTP: No clients with requests, quitting.");
2583  return NULL;
2584  }
2585  /* check whether client connection still ok */
2586  conn_wait(client->conn, 0);
2587  if (conn_error(client->conn) || conn_eof(client->conn)) {
2589  client = NULL;
2590  }
2591  } while(client == NULL);
2592 
2593  debug("gwlib.http", 0, "HTTP: Got %s request with url='%s' and body='%s'",
2594  http_method2name(client->method), octstr_get_cstr(client->url), octstr_get_cstr(client->request->body));
2595 
2596  *client_ip = octstr_duplicate(client->ip);
2597  *url = client->url;
2598  *headers = client->request->headers;
2599  *body = client->request->body;
2600  *cgivars = gwlist_create();
2601 
2602  /* is there a query string in the url? */
2603  question_mark = octstr_search_char(*url, '?', 0);
2604  if (question_mark >= 0) {
2605  /* parse the query string */
2606  query = octstr_copy(*url, question_mark + 1, octstr_len(*url));
2607  parse_cgivars(*cgivars, query);
2608  octstr_destroy(query);
2609 
2610  /* remove query string from url */
2611  octstr_truncate(*url, question_mark);
2612  }
2613 
2614  if (client->method == HTTP_METHOD_POST || client->method == HTTP_METHOD_PUT) {
2615  if (octstr_len(*body) > 0) {
2617  if (octstr_str_compare(content_type, "application/x-www-form-urlencoded") == 0) {
2618  /* parse the body */
2619  parse_cgivars(*cgivars, *body);
2620  }
2623  }
2624  } else {
2625  octstr_destroy(*body);
2626  *body = NULL;
2627  }
2628 
2629  client->persistent_conn = client_is_persistent(client->request->headers,
2630  client->use_version_1_0);
2631 
2632  client->url = NULL;
2633  client->request->headers = NULL;
2634  client->request->body = NULL;
2635  entity_destroy(client->request);
2636  client->request = NULL;
2637 
2638  return client;
2639 }
void parse_cgivars(List *cgivars, Octstr *pairs)
Definition: http.c:2542
char * http_method2name(int method)
Definition: http.c:3681
Definition: http.c:2014
static HTTPClient * port_get_request(int port)
Definition: http.c:2149
static void client(int port)
Definition: test_udp.c:77
void http_header_get_content_type(List *headers, Octstr **type, Octstr **charset)
Definition: http.c:3225
static int client_is_persistent(List *headers, int use_version_1_0)
Definition: http.c:1982
int conn_eof(Connection *conn)
Definition: conn.c:705
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
Octstr * charset
Definition: test_ota.c:68
static void client_destroy(void *client)
Definition: http.c:1932
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
const char * content_type
Definition: fakewap.c:249
static void entity_destroy(HTTPEntity *ent)
Definition: http.c:445
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
int conn_wait(Connection *conn, double seconds)
Definition: conn.c:904
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
int octstr_str_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:973
#define gwlist_create()
Definition: list.h:136
void octstr_truncate(Octstr *ostr, int new_len)
Definition: octstr.c:1327
int conn_error(Connection *conn)
Definition: conn.c:716
static Octstr * url
Definition: test_xmlrpc.c:84

◆ http_add_basic_auth()

void http_add_basic_auth ( List headers,
Octstr username,
Octstr password 
)

Definition at line 3515 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().

3516 {
3517  Octstr *os;
3518 
3519  if (password != NULL)
3520  os = octstr_format("%S:%S", username, password);
3521  else
3522  os = octstr_format("%S", username);
3524  octstr_strip_blanks(os);
3525  octstr_insert(os, octstr_imm("Basic "), 0);
3526  http_header_add(headers, "Authorization", octstr_get_cstr(os));
3527  octstr_destroy(os);
3528 }
void http_header_add(List *headers, char *name, char *contents)
Definition: http.c:2886
void octstr_binary_to_base64(Octstr *ostr)
Definition: octstr.c:542
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
unsigned char * username
Definition: test_cimd2.c:99
unsigned char * password
Definition: test_cimd2.c:100
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1303
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118

◆ http_append_headers()

void http_append_headers ( List to,
List from 
)

Definition at line 3052 of file http.c.

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

Referenced by http_header_combine(), and pap_request_thread().

3053 {
3054  Octstr *header;
3055  long i;
3056 
3058  gw_assert(to != NULL);
3059  gw_assert(from != NULL);
3060 
3061  for (i = 0; i < gwlist_len(from); ++i) {
3062  header = gwlist_get(from, i);
3063  gwlist_append(to, octstr_duplicate(header));
3064  }
3065 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_append(List *list, void *item)
Definition: list.c:179
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static Octstr * from
Definition: mtbatch.c:95
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Definition: octstr.c:118
void() gwlib_assert_init(void)
Definition: gwlib.c:72

◆ http_caller_create()

HTTPCaller* http_caller_create ( void  )

Definition at line 897 of file http.c.

References caller, gwlist_add_producer(), and gwlist_create.

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

898 {
900 
901  caller = gwlist_create();
903  return caller;
904 }
static HTTPCaller * caller
Definition: smsbox.c:442
#define gwlist_create()
Definition: list.h:136
void gwlist_add_producer(List *list)
Definition: list.c:383
Definition: list.c:102

◆ http_caller_destroy()

void http_caller_destroy ( HTTPCaller caller)

Definition at line 907 of file http.c.

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

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

908 {
910 }
static void server_destroy(void *p)
Definition: http.c:730
static HTTPCaller * caller
Definition: smsbox.c:442
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ http_caller_signal_shutdown()

void http_caller_signal_shutdown ( HTTPCaller caller)

Definition at line 913 of file http.c.

References caller, and gwlist_remove_producer().

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

914 {
916 }
static HTTPCaller * caller
Definition: smsbox.c:442
void gwlist_remove_producer(List *list)
Definition: list.c:401

◆ http_cgi_variable()

Octstr* http_cgi_variable ( List list,
char *  name 
)

Definition at line 2836 of file http.c.

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

Referenced by brunet_receive_sms(), clickatell_receive_sms(), client_thread(), default_authorise_user(), generic_receive_sms(), httpd_add_smsc(), httpd_check_authorization(), httpd_emu(), httpd_loglevel(), httpd_remove_message(), httpd_remove_smsc(), 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().

2837 {
2838  int i;
2839  HTTPCGIVar *v;
2840 
2842  gw_assert(list != NULL);
2843  gw_assert(name != NULL);
2844 
2845  for (i = 0; i < gwlist_len(list); ++i) {
2846  v = gwlist_get(list, i);
2847  if (octstr_str_compare(v->name, name) == 0)
2848  return v->value;
2849  }
2850  return NULL;
2851 }
Octstr * value
Definition: http.h:216
gw_assert(wtls_machine->packet_to_send !=NULL)
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Octstr * name
Definition: http.h:215
char * name
Definition: smsc_cimd2.c:212
void() gwlib_assert_init(void)
Definition: gwlib.c:72
int octstr_str_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:973

◆ http_cgivar_dump()

void http_cgivar_dump ( List cgiargs)

Definition at line 3440 of file http.c.

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

3441 {
3442  HTTPCGIVar *v;
3443  long i, len;
3444 
3446 
3447  len = gwlist_len(cgiargs);
3448 
3449  debug("gwlib.http", 0, "Dumping %ld cgi variables:", len);
3450  for (i = 0; i < len; i++) {
3451  v = gwlist_get(cgiargs, i);
3452  octstr_dump(v->name, 0);
3453  octstr_dump(v->value, 0);
3454  }
3455  debug("gwlib.http", 0, "End of dump.");
3456 }
Octstr * value
Definition: http.h:216
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Octstr * name
Definition: http.h:215
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
void() gwlib_assert_init(void)
Definition: gwlib.c:72

◆ http_cgivar_dump_into()

void http_cgivar_dump_into ( List cgiargs,
Octstr os 
)

Definition at line 3459 of file http.c.

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

Referenced by httpsmsc_receiver().

3460 {
3461  HTTPCGIVar *v;
3462  long i;
3463 
3464  if (os == NULL)
3465  return;
3466 
3468 
3469  for (i = 0; i < gwlist_len(cgiargs); i++) {
3470  v = gwlist_get(cgiargs, i);
3471  octstr_format_append(os, "&%E=%E", v->name, v->value);
3472  }
3473 }
Octstr * value
Definition: http.h:216
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Octstr * name
Definition: http.h:215
void() gwlib_assert_init(void)
Definition: gwlib.c:72
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2507

◆ http_charset_accepted()

int http_charset_accepted ( List headers,
char *  charset 
)

Definition at line 3509 of file http.c.

References charset, and http_something_accepted().

Referenced by add_charset_headers(), and normalize_charset().

3510 {
3511  return http_something_accepted(headers, "Accept-Charset", charset);
3512 }
Octstr * charset
Definition: test_ota.c:68
static int http_something_accepted(List *headers, char *header_name, char *what)
Definition: http.c:3476

◆ http_close_all_ports()

void http_close_all_ports ( void  )

Definition at line 2526 of file http.c.

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

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

2527 {
2528  if (server_thread_id != -1) {
2529  keep_servers_open = 0;
2533  }
2534 }
static long server_thread_id
Definition: http.c:1894
void gwthread_join_every(gwthread_func_t *func)
static int keep_servers_open
Definition: http.c:1897
void gwthread_wakeup(long thread)
static void server_thread(void *dummy)
Definition: http.c:2344
static volatile sig_atomic_t server_thread_is_running
Definition: http.c:1893

◆ http_close_client()

void http_close_client ( HTTPClient client)

Definition at line 2758 of file http.c.

References client(), and client_destroy().

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

2759 {
2761 }
static void client(int port)
Definition: test_udp.c:77
static void client_destroy(void *client)
Definition: http.c:1932

◆ http_close_port()

void http_close_port ( int  port)

Definition at line 2515 of file http.c.

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

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

2516 {
2517  int *p;
2518 
2519  p = gw_malloc(sizeof(*p));
2520  *p = port;
2523 }
static long server_thread_id
Definition: http.c:1894
void gwlist_produce(List *list, void *item)
Definition: list.c:411
static int port
Definition: fakesmsc.c:121
static List * closed_server_sockets
Definition: http.c:1896
void gwthread_wakeup(long thread)

◆ http_close_proxy()

void http_close_proxy ( void  )

Definition at line 304 of file http.c.

References gw_assert(), 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().

305 {
307 
309  proxy_port = 0;
313  proxy_hostname = NULL;
314  proxy_username = NULL;
315  proxy_password = NULL;
317  gw_regex_destroy(proxy_exceptions_regex);
318  proxy_exceptions = NULL;
319  proxy_exceptions_regex = NULL;
321 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define mutex_unlock(m)
Definition: thread.h:136
Definition: http.c:115
static regex_t * proxy_exceptions_regex
Definition: http.c:206
static enum @59 run_status
static int proxy_port
Definition: http.c:201
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Octstr * proxy_username
Definition: http.c:203
void octstr_destroy_item(void *os)
Definition: octstr.c:336
static Mutex * proxy_mutex
Definition: http.c:199
static Octstr * proxy_hostname
Definition: http.c:200
static List * proxy_exceptions
Definition: http.c:205
#define mutex_lock(m)
Definition: thread.h:130
static Octstr * proxy_password
Definition: http.c:204
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ http_create_empty_headers()

◆ http_destroy_cgiargs()

void http_destroy_cgiargs ( List args)

Definition at line 2818 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().

2819 {
2820  HTTPCGIVar *v;
2821 
2823 
2824  if (args == NULL)
2825  return ;
2826 
2827  while ((v = gwlist_extract_first(args)) != NULL) {
2828  octstr_destroy(v->name);
2829  octstr_destroy(v->value);
2830  gw_free(v);
2831  }
2832  gwlist_destroy(args, NULL);
2833 }
Octstr * value
Definition: http.h:216
Octstr * name
Definition: http.h:215
void * gwlist_extract_first(List *list)
Definition: list.c:305
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void() gwlib_assert_init(void)
Definition: gwlib.c:72
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ http_destroy_headers()

void http_destroy_headers ( List headers)

Definition at line 2879 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_receive_sms(), generic_send_sms(), 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(), xidris_receive_sms(), and xidris_send_sms().

2880 {
2883 }
void octstr_destroy_item(void *os)
Definition: octstr.c:336
void() gwlib_assert_init(void)
Definition: gwlib.c:72
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ http_get_header_parameter()

Octstr* http_get_header_parameter ( Octstr value,
Octstr parameter 
)

Definition at line 3531 of file http.c.

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

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

3532 {
3533  long pos, len, end;
3534  int c, found = 0;
3535  Octstr *result = NULL;
3536 
3537  len = octstr_len(value);
3538  /* Find the start of the first parameter. */
3539  for (pos = 0; pos < len; pos++) {
3540  c = octstr_get_char(value, pos);
3541  if (c == ';')
3542  break;
3543  else if (c == '"')
3544  pos += http_header_quoted_string_len(value, pos) - 1;
3545  }
3546 
3547  if (pos >= len)
3548  return NULL; /* no parameters */
3549 
3550  for (pos++; pos > 0 && pos < len && found == 0; pos++) {
3551  Octstr *key = NULL;
3552  Octstr *val = NULL;
3553 
3554  end = octstr_search_char(value, '=', pos);
3555  if (end < 0)
3556  end = octstr_search_char(value, ';', pos);
3557  if (end < 0)
3558  end = octstr_len(value);
3559  key = octstr_copy(value, pos, end - pos);
3560  octstr_strip_blanks(key);
3561  pos = end;
3562 
3563  if (octstr_get_char(value, pos) == '=') {
3564  pos++;
3565  while (isspace(octstr_get_char(value, pos)))
3566  pos++;
3567  if (octstr_get_char(value, pos) == '"')
3568  end = pos + http_header_quoted_string_len(value, pos);
3569  else
3570  end = octstr_search_char(value, ';', pos);
3571  if (end < 0)
3572  end = octstr_len(value);
3573  val = octstr_copy(value, pos, end - pos);
3574  octstr_strip_blanks(val);
3575  pos = end;
3576  pos = octstr_search_char(value, ';', pos);
3577  }
3578 
3579  /* is this the pair we look for? bail out then*/
3580  if (octstr_case_compare(key, parameter) == 0) {
3581  found++;
3582  result = octstr_duplicate(val);
3583  }
3584 
3585  octstr_destroy(key);
3586  octstr_destroy(val);
3587  }
3588 
3589  return result;
3590 }
long http_header_quoted_string_len(Octstr *header, long start)
Definition: http.c:3293
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
static struct pid_list * found
#define octstr_duplicate(ostr)
Definition: octstr.h:187
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:903
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ http_get_real()

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

Definition at line 1821 of file http.c.

References caller, http_caller_create(), http_caller_destroy(), http_get_real(), http_receive_result, http_start_request(), method, and url.

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

1823 {
1824  HTTPCaller *caller;
1825  int status;
1826  void *ret;
1827 
1829  http_start_request(caller, method, url, request_headers,
1830  NULL, 1, http_get_real, NULL);
1831  ret = http_receive_result(caller, &status, final_url,
1832  reply_headers, reply_body);
1834  if (ret == NULL)
1835  return -1;
1836  return status;
1837 }
static HTTPCaller * caller
Definition: smsbox.c:442
void http_start_request(HTTPCaller *caller, int method, Octstr *url, List *headers, Octstr *body, int follow, void *id, Octstr *certkeyfile)
Definition: http.c:1760
static int method
Definition: test_http.c:76
#define http_receive_result(caller, status, final_url, headers, body)
Definition: http.h:394
int http_get_real(int method, Octstr *url, List *request_headers, Octstr **final_url, List **reply_headers, Octstr **reply_body)
Definition: http.c:1821
HTTPCaller * http_caller_create(void)
Definition: http.c:897
void http_caller_destroy(HTTPCaller *caller)
Definition: http.c:907
static Octstr * url
Definition: test_xmlrpc.c:84
Definition: list.c:102

◆ http_header_add()

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

Definition at line 2886 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_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(), generic_receive_sms(), generic_send_sms(), 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().

2887 {
2889  gw_assert(headers != NULL);
2890  gw_assert(name != NULL);
2891  gw_assert(contents != NULL);
2892 
2893  gwlist_append(headers, octstr_format("%s: %s", name, contents));
2894 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_append(List *list, void *item)
Definition: list.c:179
char * name
Definition: smsc_cimd2.c:212
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void() gwlib_assert_init(void)
Definition: gwlib.c:72

◆ http_header_combine()

void http_header_combine ( List old_headers,
List new_headers 
)

Definition at line 3068 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 client_thread(), return_reply(), start_fetch(), start_request(), test_header_combine(), and unpack_new_headers().

3069 {
3070  long i;
3071  Octstr *name;
3072  Octstr *value;
3073 
3074  /*
3075  * Avoid doing this scan if old_headers is empty anyway.
3076  */
3077  if (gwlist_len(old_headers) > 0) {
3078  for (i = 0; i < gwlist_len(new_headers); i++) {
3079  http_header_get(new_headers, i, &name, &value);
3082  octstr_destroy(value);
3083  }
3084  }
3085 
3086  http_append_headers(old_headers, new_headers);
3087 }
void http_header_get(List *headers, long i, Octstr **name, Octstr **value)
Definition: http.c:2902
long gwlist_len(List *list)
Definition: list.c:166
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void http_append_headers(List *to, List *from)
Definition: http.c:3052
char * name
Definition: smsc_cimd2.c:212
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
long http_header_remove_all(List *headers, char *name)
Definition: http.c:3135

◆ http_header_dump()

void http_header_dump ( List headers)

Definition at line 3427 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().

3428 {
3429  long i;
3430 
3432 
3433  debug("gwlib.http", 0, "Dumping HTTP headers:");
3434  for (i = 0; headers != NULL && i < gwlist_len(headers); ++i)
3435  octstr_dump(gwlist_get(headers, i), 1);
3436  debug("gwlib.http", 0, "End of dump.");
3437 }
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
void() gwlib_assert_init(void)
Definition: gwlib.c:72

◆ http_header_duplicate()

List* http_header_duplicate ( List headers)

Definition at line 2969 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().

2970 {
2971  List *new;
2972  long i, len;
2973 
2975 
2976  if (headers == NULL)
2977  return NULL;
2978 
2979  new = http_create_empty_headers();
2980  len = gwlist_len(headers);
2981  for (i = 0; i < len; ++i)
2982  gwlist_append(new, octstr_duplicate(gwlist_get(headers, i)));
2983  return new;
2984 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
List * http_create_empty_headers(void)
Definition: http.c:2872
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void() gwlib_assert_init(void)
Definition: gwlib.c:72
Definition: list.c:102

◆ http_header_find_all()

List* http_header_find_all ( List headers,
char *  name 
)

Definition at line 3115 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().

3116 {
3117  List *list;
3118  long i;
3119  Octstr *h;
3120 
3122  gw_assert(headers != NULL);
3123  gw_assert(name != NULL);
3124 
3125  list = gwlist_create();
3126  for (i = 0; i < gwlist_len(headers); ++i) {
3127  h = gwlist_get(headers, i);
3128  if (header_is_called(h, name))
3129  gwlist_append(list, octstr_duplicate(h));
3130  }
3131  return list;
3132 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_append(List *list, void *item)
Definition: list.c:179
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define octstr_duplicate(ostr)
Definition: octstr.h:187
char * name
Definition: smsc_cimd2.c:212
Definition: octstr.c:118
void() gwlib_assert_init(void)
Definition: gwlib.c:72
#define gwlist_create()
Definition: list.h:136
static int header_is_called(Octstr *header, char *name)
Definition: http.c:2859
Definition: list.c:102

◆ http_header_find_first_real()

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

Definition at line 3090 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().

3092 {
3093  long i, name_len;
3094  Octstr *h, *value;
3095 
3097  gw_assert(headers != NULL);
3098  gw_assert(name != NULL);
3099 
3100  name_len = strlen(name);
3101 
3102  for (i = 0; i < gwlist_len(headers); ++i) {
3103  h = gwlist_get(headers, i);
3104  if (header_is_called(h, name)) {
3105  value = octstr_copy_real(h, name_len + 1, octstr_len(h),
3106  file, line, func);
3107  octstr_strip_blanks(value);
3108  return value;
3109  }
3110  }
3111  return NULL;
3112 }
size_t name_len
Definition: wslexer.c:158
gw_assert(wtls_machine->packet_to_send !=NULL)
long gwlist_len(List *list)
Definition: list.c:166
Octstr * octstr_copy_real(const Octstr *ostr, long from, long len, const char *file, long line, const char *func)
Definition: octstr.c:351
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
FILE * file
Definition: log.c:169
char * name
Definition: smsc_cimd2.c:212
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void() gwlib_assert_init(void)
Definition: gwlib.c:72
static int header_is_called(Octstr *header, char *name)
Definition: http.c:2859

◆ http_header_get()

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

Definition at line 2902 of file http.c.

References colon, 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().

2903 {
2904  Octstr *os;
2905  long colon;
2906 
2908  gw_assert(i >= 0);
2909  gw_assert(name != NULL);
2910  gw_assert(value != NULL);
2911 
2912  os = gwlist_get(headers, i);
2913  if (os == NULL)
2914  colon = -1;
2915  else
2916  colon = octstr_search_char(os, ':', 0);
2917  if (colon == -1) {
2918  error(0, "HTTP: Header does not contain a colon. BAD.");
2919  *name = octstr_create("X-Unknown");
2920  *value = octstr_duplicate(os);
2921  } else {
2922  *name = octstr_copy(os, 0, colon);
2923  *value = octstr_copy(os, colon + 1, octstr_len(os) - colon - 1);
2924  octstr_strip_blanks(*value);
2925  }
2926 }
void error(int err, const char *fmt,...)
Definition: log.c:648
gw_assert(wtls_machine->packet_to_send !=NULL)
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
#define octstr_duplicate(ostr)
Definition: octstr.h:187
char * name
Definition: smsc_cimd2.c:212
#define octstr_create(cstr)
Definition: octstr.h:125
static Octstr * colon
Definition: smsc_smasi.c:218
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void() gwlib_assert_init(void)
Definition: gwlib.c:72

◆ http_header_get_content_type()

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

Definition at line 3225 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 generic_receive_sms(), http_accept_request(), 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().

3227 {
3228  Octstr *h;
3229  long semicolon, equals, len;
3230 
3232  gw_assert(headers != NULL);
3233  gw_assert(type != NULL);
3234  gw_assert(charset != NULL);
3235 
3236  h = http_header_find_first(headers, "Content-Type");
3237  if (h == NULL) {
3238  *type = octstr_create("application/octet-stream");
3239  *charset = octstr_create("");
3240  } else {
3242  semicolon = octstr_search_char(h, ';', 0);
3243  if (semicolon == -1) {
3244  *type = h;
3245  *charset = octstr_create("");
3246  } else {
3247  *charset = octstr_duplicate(h);
3248  octstr_delete(*charset, 0, semicolon + 1);
3250  equals = octstr_search_char(*charset, '=', 0);
3251  if (equals == -1)
3252  octstr_truncate(*charset, 0);
3253  else {
3254  octstr_delete(*charset, 0, equals + 1);
3255  if (octstr_get_char(*charset, 0) == '"')
3256  octstr_delete(*charset, 0, 1);
3257  len = octstr_len(*charset);
3258  if (octstr_get_char(*charset, len - 1) == '"')
3259  octstr_truncate(*charset, len - 1);
3260  }
3261 
3262  octstr_truncate(h, semicolon);
3264  *type = h;
3265  }
3266 
3267  /*
3268  * According to HTTP/1.1 (RFC 2616, section 3.7.1) we have to ensure
3269  * to return charset 'iso-8859-1' in case of no given encoding and
3270  * content-type is a 'text' subtype.
3271  */
3272  if (octstr_len(*charset) == 0 &&
3273  octstr_ncompare(*type, octstr_imm("text"), 4) == 0)
3274  octstr_append_cstr(*charset, "ISO-8859-1");
3275  }
3276 }
gw_assert(wtls_machine->packet_to_send !=NULL)
int type
Definition: smsc_cimd2.c:215
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1511
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
Octstr * charset
Definition: test_ota.c:68
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
int octstr_ncompare(const Octstr *ostr1, const Octstr *ostr2, long n)
Definition: octstr.c:952
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define http_header_find_first(headers, name)
Definition: http.h:603
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void() gwlib_assert_init(void)
Definition: gwlib.c:72
void octstr_truncate(Octstr *ostr, int new_len)
Definition: octstr.c:1327
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406

◆ http_header_mark_transformation()

void http_header_mark_transformation ( List headers,
Octstr new_body,
Octstr new_type 
)

Definition at line 3203 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().

3205 {
3206  Octstr *new_length = NULL;
3207 
3208  /* Remove all headers that no longer apply to the new body. */
3209  http_header_remove_all(headers, "Content-Length");
3210  http_header_remove_all(headers, "Content-MD5");
3211  http_header_remove_all(headers, "Content-Type");
3212 
3213  /* Add headers that we need to describe the new body. */
3214  new_length = octstr_format("%ld", octstr_len(new_body));
3215  http_header_add(headers, "Content-Length", octstr_get_cstr(new_length));
3216  if(octstr_len(new_type))
3217  http_header_add(headers, "Content-Type", octstr_get_cstr(new_type));
3218 
3219  /* Perhaps we should add Warning: 214 "Transformation applied" too? */
3220 
3221  octstr_destroy(new_length);
3222 }
void http_header_add(List *headers, char *name, char *contents)
Definition: http.c:2886
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
long http_header_remove_all(List *headers, char *name)
Definition: http.c:3135

◆ http_header_pack()

void http_header_pack ( List headers)

Definition at line 2992 of file http.c.

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

Referenced by start_fetch().

2993 {
2994  Octstr *name, *value;
2995  Octstr *name2, *value2;
2996  long i, j;
2997 
2999  gw_assert(headers != NULL);
3000 
3001  /*
3002  * For each header, search forward headers for similar ones and if possible,
3003  * add it to current header and delete it
3004  */
3005  for(i = 0; i < gwlist_len(headers); i++) {
3006  http_header_get(headers, i, &name, &value);
3007  /* debug("http_header_pack", 0, "HTTP_HEADER_PACK: Processing header %d. [%s: %s]",
3008  i, octstr_get_cstr(name), octstr_get_cstr(value)); */
3009 
3010  for(j=i+1; j < gwlist_len(headers); j++) {
3011  http_header_get(headers, j, &name2, &value2);
3012 
3013  if(octstr_case_compare(name, name2) == 0) {
3014  if(octstr_len(value) + 2 + octstr_len(value2) > MAX_HEADER_LENGTH) {
3015  octstr_destroy(name2);
3016  octstr_destroy(value2);
3017  break;
3018  } else {
3019  Octstr *header;
3020 
3021  /* Delete old header */
3022  header = gwlist_get(headers, i);
3023  octstr_destroy(header);
3024  gwlist_delete(headers, i, 1);
3025 
3026  /* Adds comma and new value to old header value */
3027  octstr_append(value, octstr_imm(", "));
3028  octstr_append(value, value2);
3029  /* Creates a new header */
3030  header = octstr_create("");
3031  octstr_append(header, name);
3032  octstr_append(header, octstr_imm(": "));
3033  octstr_append(header, value);
3034  gwlist_insert(headers, i, header);
3035 
3036  /* Delete this header */
3037  header = gwlist_get(headers, j);
3038  octstr_destroy(header);
3039  gwlist_delete(headers, j, 1);
3040  j--;
3041  }
3042  }
3043  octstr_destroy(name2);
3044  octstr_destroy(value2);
3045  }
3047  octstr_destroy(value);
3048  }
3049 }
void http_header_get(List *headers, long i, Octstr **name, Octstr **value)
Definition: http.c:2902
gw_assert(wtls_machine->packet_to_send !=NULL)
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
#define MAX_HEADER_LENGTH
Definition: http.c:2987
char * name
Definition: smsc_cimd2.c:212
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:903
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
void gwlist_insert(List *list, long pos, void *item)
Definition: list.c:214
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void() gwlib_assert_init(void)
Definition: gwlib.c:72

◆ http_header_quoted_string_len()

long http_header_quoted_string_len ( Octstr header,
long  pos 
)

Definition at line 3293 of file http.c.

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

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

3294 {
3295  long len;
3296  long pos;
3297  int c;
3298 
3299  if (octstr_get_char(header, start) != '"')
3300  return -1;
3301 
3302  len = octstr_len(header);
3303  for (pos = start + 1; pos < len; pos++) {
3304  c = octstr_get_char(header, pos);
3305  if (c == '\\') /* quoted-pair */
3306  pos++;
3307  else if (c == '"')
3308  return pos - start + 1;
3309  }
3310 
3311  warning(0, "Header contains unterminated quoted-string:");
3312  warning(0, "%s", octstr_get_cstr(header));
3313  return len - start;
3314 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void warning(int err, const char *fmt,...)
Definition: log.c:660
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
static int start

◆ http_header_remove_all()

long http_header_remove_all ( List headers,
char *  name 
)

Definition at line 3135 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(), response(), return_reply(), send_request(), set_addr_tuple(), split_header_list(), start_fetch(), and xmlrpc_doc_send().

3136 {
3137  long i;
3138  Octstr *h;
3139  long count;
3140 
3142  gw_assert(headers != NULL);
3143  gw_assert(name != NULL);
3144 
3145  i = 0;
3146  count = 0;
3147  while (i < gwlist_len(headers)) {
3148  h = gwlist_get(headers, i);
3149  if (header_is_called(h, name)) {
3150  gwlist_delete(headers, i, 1);
3151  octstr_destroy(h);
3152  count++;
3153  } else
3154  i++;
3155  }
3156 
3157  return count;
3158 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
char * name
Definition: smsc_cimd2.c:212
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
void() gwlib_assert_init(void)
Definition: gwlib.c:72
static int header_is_called(Octstr *header, char *name)
Definition: http.c:2859

◆ http_header_split_auth_value()

List* http_header_split_auth_value ( Octstr value)

Definition at line 3351 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(), and octstr_len().

Referenced by pack_known_header().

3352 {
3353  List *result;
3354  Octstr *auth_scheme;
3355  Octstr *element;
3356  long i;
3357 
3358  /*
3359  * According to RFC2617, both "challenge" and "credentials"
3360  * consist of an auth-scheme followed by a list of auth-param.
3361  * Since we have to parse a list of challenges or credentials,
3362  * we have to look for auth-scheme to signal the start of
3363  * a new element. (We can't just split on commas because
3364  * they are also used to separate the auth-params.)
3365  *
3366  * An auth-scheme is a single token, while an auth-param is
3367  * always a key=value pair. So we can recognize an auth-scheme
3368  * as a token that is not followed by a '=' sign.
3369  *
3370  * Simple approach: First split at all commas, then recombine
3371  * the elements that belong to the same challenge or credential.
3372  * This is somewhat expensive but saves programmer thinking time.
3373  *
3374  * Richard Braakman
3375  */
3376 
3377  result = http_header_split_value(value);
3378  if (gwlist_len(result) == 0)
3379  return result;
3380 
3381  auth_scheme = gwlist_get(result, 0);
3382  i = 1;
3383  while (i < gwlist_len(result)) {
3384  int c;
3385  long pos;
3386 
3387  element = gwlist_get(result, i);
3388 
3389  /*
3390  * If the element starts with: token '='
3391  * then it's just an auth_param; append it to the current
3392  * auth_scheme. If it starts with: token token '='
3393  * then it's the start of a new auth scheme.
3394  *
3395  * To make the scan easier, we consider anything other
3396  * than whitespace or '=' to be part of a token.
3397  */
3398 
3399  /* Skip first token */
3400  for (pos = 0; pos < octstr_len(element); pos++) {
3401  c = octstr_get_char(element, pos);
3402  if (isspace(c) || c == '=')
3403  break;
3404  }
3405 
3406  /* Skip whitespace, if any */
3407  while (isspace(octstr_get_char(element, pos)))
3408  pos++;
3409 
3410  if (octstr_get_char(element, pos) == '=') {
3411  octstr_append_char(auth_scheme, ';');
3412  octstr_append(auth_scheme, element);
3413  gwlist_delete(result, i, 1);
3415  } else {
3416  char semicolon = ';';
3417  octstr_insert_data(element, pos, &semicolon, 1);
3418  auth_scheme = element;
3419  i++;
3420  }
3421  }
3422 
3423  return result;
3424 }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void octstr_append_char(Octstr *ostr, int ch)
Definition: octstr.c:1517
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1461
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
List * http_header_split_value(Octstr *value)
Definition: http.c:3317
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
Definition: list.c:102

◆ http_header_split_value()

List* http_header_split_value ( Octstr value)

Definition at line 3317 of file http.c.

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

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

3318 {
3319  long start; /* start of current element */
3320  long pos;
3321  long len;
3322  List *result;
3323  int c;
3324 
3325  /*
3326  * According to RFC2616 section 4.2, a field-value is either *TEXT
3327  * (the caller is responsible for not feeding us one of those) or
3328  * combinations of token, separators, and quoted-string. We're
3329  * looking for commas which are separators, and have to skip
3330  * commas in quoted-strings.
3331  */
3332 
3333  result = gwlist_create();
3334  len = octstr_len(value);
3335  start = 0;
3336  for (pos = 0; pos < len; pos++) {
3337  c = octstr_get_char(value, pos);
3338  if (c == ',') {
3339  http_header_add_element(result, value, start, pos);
3340  start = pos + 1;
3341  } else if (c == '"') {
3342  pos += http_header_quoted_string_len(value, pos);
3343  pos--; /* compensate for the loop's pos++ */
3344  }
3345  }
3346  http_header_add_element(result, value, start, len);
3347  return result;
3348 }
long http_header_quoted_string_len(Octstr *header, long start)
Definition: http.c:3293
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
#define gwlist_create()
Definition: list.h:136
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:406
static void http_header_add_element(List *list, Octstr *value, long start, long end)
Definition: http.c:3279
Definition: list.c:102
static int start

◆ http_header_value()

Octstr* http_header_value ( List headers,
Octstr header 
)

Definition at line 2932 of file http.c.

References colon, 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().

2933 {
2934  Octstr *value;
2935  long i;
2936  Octstr *os;
2937  long colon;
2938  Octstr *current_name;
2939 
2941  gw_assert(name);
2942 
2943  value = NULL;
2944  i = 0;
2945  while (i < gwlist_len(headers)) {
2946  os = gwlist_get(headers, i);
2947  if (os == NULL)
2948  colon = -1;
2949  else
2950  colon = octstr_search_char(os, ':', 0);
2951  if (colon == -1) {
2952  return NULL;
2953  } else {
2954  current_name = octstr_copy(os, 0, colon);
2955  }
2956  if (octstr_case_compare(current_name, name) == 0) {
2957  value = octstr_copy(os, colon + 1, octstr_len(os) - colon - 1);
2958  octstr_strip_blanks(value);
2959  octstr_destroy(current_name);
2960  return value;
2961  }
2962  octstr_destroy(current_name);
2963  ++i;
2964  }
2965 
2966  return NULL;
2967 }
gw_assert(wtls_machine->packet_to_send !=NULL)
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void octstr_strip_blanks(Octstr *text)
Definition: octstr.c:1346
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
char * name
Definition: smsc_cimd2.c:212
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:903
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
static Octstr * colon
Definition: smsc_smasi.c:218
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void() gwlib_assert_init(void)
Definition: gwlib.c:72

◆ http_init()

void http_init ( void  )

Definition at line 3598 of file http.c.

References client_init(), conn_pool_init(), gw_assert(), limbo, port_init(), proxy_init(), run_status, running, and server_init().

Referenced by gwlib_init().

3599 {
3601 
3602 #ifdef HAVE_LIBSSL
3603  conn_init_ssl();
3604 #endif /* HAVE_LIBSSL */
3605  proxy_init();
3606  client_init();
3607  conn_pool_init();
3608  port_init();
3609  server_init();
3610 #ifdef HAVE_LIBSSL
3611  server_ssl_init();
3612 #endif /* HAVE_LIBSSL */
3613 
3614  run_status = running;
3615 }
static void proxy_init(void)
Definition: http.c:225
gw_assert(wtls_machine->packet_to_send !=NULL)
static void server_init(void)
Definition: http.c:2773
static void client_init(void)
Definition: http.c:1840
Definition: http.c:115
static void conn_pool_init(void)
Definition: http.c:762
static void port_init(void)
Definition: http.c:2034
static enum @59 run_status
Definition: http.c:114

◆ http_method()

int http_method ( HTTPClient client)

Definition at line 2763 of file http.c.

References client().

2764 {
2765  return client->method;
2766 }
static void client(int port)
Definition: test_udp.c:77

◆ http_method2name()

char* http_method2name ( int  method)

Definition at line 3681 of file http.c.

References gw_assert(), HTTP_METHOD_GET, HTTP_METHOD_PATCH, http_methods, and method.

Referenced by http_accept_request(), and send_request().

3682 {
3684 
3685  return http_methods[method-1];
3686 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static int method
Definition: test_http.c:76
static char * http_methods[]
Definition: http.c:660

◆ http_name2method()

int http_name2method ( Octstr method)

Definition at line 3654 of file http.c.

References gw_assert(), HTTP_METHOD_DELETE, HTTP_METHOD_GET, HTTP_METHOD_HEAD, HTTP_METHOD_PATCH, HTTP_METHOD_POST, HTTP_METHOD_PUT, method, and octstr_str_compare().

Referenced by main(), parse_request_line(), and start_fetch().

3655 {
3656  gw_assert(method != NULL);
3657 
3658  if (octstr_str_compare(method, "GET") == 0) {
3659  return HTTP_METHOD_GET;
3660  }
3661  else if (octstr_str_compare(method, "POST") == 0) {
3662  return HTTP_METHOD_POST;
3663  }
3664  else if (octstr_str_compare(method, "HEAD") == 0) {
3665  return HTTP_METHOD_HEAD;
3666  }
3667  else if (octstr_str_compare(method, "PUT") == 0) {
3668  return HTTP_METHOD_PUT;
3669  }
3670  else if (octstr_str_compare(method, "DELETE") == 0) {
3671  return HTTP_METHOD_DELETE;
3672  }
3673  else if (octstr_str_compare(method, "PATCH") == 0) {
3674  return HTTP_METHOD_PATCH;
3675  }
3676 
3677  return -1;
3678 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static int method
Definition: test_http.c:76
int octstr_str_compare(const Octstr *ostr, const char *str)
Definition: octstr.c:973

◆ http_open_port()

int http_open_port ( int  port,
int  ssl 
)

Definition at line 2509 of file http.c.

References http_open_port_if(), and ssl.

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

2510 {
2511  return http_open_port_if(port, ssl, NULL);
2512 }
Definition: http.c:2014
int ssl
int http_open_port_if(int port, int ssl, Octstr *interface)
Definition: http.c:2483

◆ http_open_port_if()

int http_open_port_if ( int  port,
int  ssl,
Octstr interface 
)

Definition at line 2483 of file http.c.

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

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

2484 {
2485  struct port *p;
2486 
2487  if (ssl)
2488  info(0, "HTTP: Opening SSL server at port %d.", port);
2489  else
2490  info(0, "HTTP: Opening server at port %d.", port);
2491  p = port_add(port);
2492  p->port = port;
2493  p->ssl = ssl;
2494  p->fd = make_server_socket(port, (interface ? octstr_get_cstr(interface) : NULL));
2495  if (p->fd == -1) {
2496  port_remove(port);
2497  return -1;
2498  }
2499 
2501  keep_servers_open = 1;
2504 
2505  return 0;
2506 }
void info(int err, const char *fmt,...)
Definition: log.c:672
Definition: http.c:2014
static long server_thread_id
Definition: http.c:1894
int ssl
void gwlist_produce(List *list, void *item)
Definition: list.c:411
int port
Definition: http.c:2016
int ssl
Definition: http.c:2017
int fd
Definition: http.c:2015
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static List * new_server_sockets
Definition: http.c:1895
static void port_remove(int port)
Definition: http.c:2081
static int port
Definition: fakesmsc.c:121
int make_server_socket(int port, const char *interface_name)
Definition: socket.c:93
static int keep_servers_open
Definition: http.c:1897
void gwthread_wakeup(long thread)
static void start_server_thread(void)
Definition: http.c:2458
static struct port * port_add(int port)
Definition: http.c:2057

◆ http_receive_result_real()

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

Definition at line 1786 of file http.c.

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

1788 {
1789  HTTPServer *trans;
1790  void *request_id;
1791 
1792  if (blocking == 0)
1793  trans = gwlist_extract_first(caller);
1794  else
1795  trans = gwlist_consume(caller);
1796  if (trans == NULL)
1797  return NULL;
1798 
1799  request_id = trans->request_id;
1800  *status = trans->status;
1801 
1802  if (trans->status >= 0) {
1803  *final_url = trans->url;
1804  *headers = trans->response->headers;
1805  *body = trans->response->body;
1806 
1807  trans->url = NULL;
1808  trans->response->headers = NULL;
1809  trans->response->body = NULL;
1810  } else {
1811  *final_url = NULL;
1812  *headers = NULL;
1813  *body = NULL;
1814  }
1815 
1816  server_destroy(trans);
1817  return request_id;
1818 }
static void server_destroy(void *p)
Definition: http.c:730
void * request_id
Definition: http.c:669
long status
Definition: http.c:682
static HTTPCaller * caller
Definition: smsbox.c:442
Octstr * body
Definition: http.c:363
void * gwlist_extract_first(List *list)
Definition: list.c:305
Octstr * url
Definition: http.c:671
List * headers
Definition: http.c:362
HTTPEntity * response
Definition: http.c:684
void * gwlist_consume(List *list)
Definition: list.c:427

◆ http_remove_hop_headers()

void http_remove_hop_headers ( List headers)

Definition at line 3161 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().

3162 {
3163  Octstr *h;
3164  List *connection_headers;
3165 
3167  gw_assert(headers != NULL);
3168 
3169  /*
3170  * The hop-by-hop headers are a standard list, plus those named
3171  * in the Connection header(s).
3172  */
3173 
3174  connection_headers = http_header_find_all(headers, "Connection");
3175  while ((h = gwlist_consume(connection_headers))) {
3176  List *hop_headers;
3177  Octstr *e;
3178 
3179  octstr_delete(h, 0, strlen("Connection:"));
3180  hop_headers = http_header_split_value(h);
3181  octstr_destroy(h);
3182 
3183  while ((e = gwlist_consume(hop_headers))) {
3185  octstr_destroy(e);
3186  }
3187 
3188  gwlist_destroy(hop_headers, NULL);
3189  }
3190  gwlist_destroy(connection_headers, NULL);
3191 
3192  http_header_remove_all(headers, "Connection");
3193  http_header_remove_all(headers, "Keep-Alive");
3194  http_header_remove_all(headers, "Proxy-Authenticate");
3195  http_header_remove_all(headers, "Proxy-Authorization");
3196  http_header_remove_all(headers, "TE");
3197  http_header_remove_all(headers, "Trailers");
3198  http_header_remove_all(headers, "Transfer-Encoding");
3199  http_header_remove_all(headers, "Upgrade");
3200 }
List * http_header_find_all(List *headers, char *name)
Definition: http.c:3115
gw_assert(wtls_machine->packet_to_send !=NULL)
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1527
List * http_header_split_value(Octstr *value)
Definition: http.c:3317
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
void * gwlist_consume(List *list)
Definition: list.c:427
void() gwlib_assert_init(void)
Definition: gwlib.c:72
long http_header_remove_all(List *headers, char *name)
Definition: http.c:3135
Definition: list.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ http_request_url()

Octstr* http_request_url ( HTTPClient client)

Definition at line 2768 of file http.c.

References client().

2769 {
2770  return client->url;
2771 }
static void client(int port)
Definition: test_udp.c:77

◆ http_send_reply()

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

Definition at line 2695 of file http.c.

References client(), client_destroy(), client_reset(), conn_register, conn_write(), date(), date_format_http(), gwlist_get(), gwlist_len(), HTTP_METHOD_DELETE, HTTP_METHOD_HEAD, http_reason_phrase(), octstr_append(), octstr_destroy(), octstr_format(), octstr_format_append(), octstr_get_cstr, octstr_len(), port_get_fdset(), receive_request(), and response().

Referenced by brunet_receive_sms(), challenge(), clickatell_receive_sms(), client_thread(), delayed_http_reply(), generic_receive_sms(), 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().

2697 {
2698  Octstr *response;
2699  Octstr *date;
2700  long i;
2701  int ret;
2702 
2703  if (client->use_version_1_0)
2704  response = octstr_format("HTTP/1.0 %d %s\r\n", status, http_reason_phrase(status));
2705  else
2706  response = octstr_format("HTTP/1.1 %d %s\r\n", status, http_reason_phrase(status));
2707 
2708  /* identify ourselfs */
2709  octstr_format_append(response, "Server: " GW_NAME "/%s\r\n", GW_VERSION);
2710 
2711  /* let's inform the client of our time */
2712  date = date_format_http(time(NULL));
2715 
2716  octstr_format_append(response, "Content-Length: %ld\r\n", octstr_len(body));
2717 
2718  /* Indicate if we're keeping the connection or closing. */
2719  if (client->persistent_conn)
2720  octstr_format_append(response, "Connection: Keep-Alive\r\n");
2721  else
2722  octstr_format_append(response, "Connection: Close\r\n");
2723 
2724  for (i = 0; i < gwlist_len(headers); ++i)
2725  octstr_format_append(response, "%S\r\n", gwlist_get(headers, i));
2726  octstr_format_append(response, "\r\n");
2727 
2728  if (body != NULL && client->method != HTTP_METHOD_HEAD && client->method != HTTP_METHOD_DELETE)
2729  octstr_append(response, body);
2730 
2731  ret = conn_write(client->conn, response);
2733 
2734  /* obey return code of conn_write() */
2735  /* sending response was successful */
2736  if (ret == 0) {
2737  /* HTTP/1.0 or 1.1, hence keep-alive or keep-alive */
2738  if (!client->persistent_conn) {
2740  } else {
2741  /* XXX mark this HTTPClient in the keep-alive cleaner thread */
2744  }
2745  }
2746  /* queued for sending, we don't want to block */
2747  else if (ret == 1) {
2748  client->state = sending_reply;
2750  }
2751  /* error while sending response */
2752  else {
2754  }
2755 }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
long gwlist_len(List *list)
Definition: list.c:166
static void client(int port)
Definition: test_udp.c:77
void * gwlist_get(List *list, long pos)
Definition: list.c:292
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static void client_destroy(void *client)
Definition: http.c:1932
static const char * http_reason_phrase(int status)
Definition: http.c:2645
int conn_write(Connection *conn, Octstr *data)
Definition: conn.c:1051
static FDSet * port_get_fdset(int port)
Definition: http.c:2190
static void client_reset(HTTPClient *p)
Definition: http.c:1967
#define conn_register(conn, fdset, callback, data)
Definition: conn.h:215
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
static void receive_request(Connection *conn, void *data)
Definition: http.c:2251
Definition: octstr.c:118
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2507
Octstr * date_format_http(unsigned long unixtime)
Definition: date.c:89
static int date(int hex)
static int response(List *push_headers, Octstr **username, Octstr **password)

◆ http_set_client_timeout()

void http_set_client_timeout ( long  timeout)

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

Definition at line 1751 of file http.c.

References client_fdset, fdset_set_timeout(), and http_client_timeout.

Referenced by init_bearerbox(), init_smsbox(), and init_wapbox().

1752 {
1753  http_client_timeout = timeout;
1754  if (client_fdset != NULL) {
1755  /* we are already initialized set timeout in fdset */
1757  }
1758 }
static int http_client_timeout
Definition: http.c:91
static FDSet * client_fdset
Definition: http.c:647
void fdset_set_timeout(FDSet *set, long timeout)
Definition: fdset.c:547

◆ http_set_interface()

void http_set_interface ( const Octstr our_host)

Definition at line 1746 of file http.c.

References http_interface, octstr_duplicate, and our_host.

Referenced by config_reload().

1747 {
1749 }
static Octstr * http_interface
Definition: http.c:123
static Octstr * our_host
Definition: radius_acct.c:86
#define octstr_duplicate(ostr)
Definition: octstr.h:187

◆ http_set_server_timeout()

void http_set_server_timeout ( int  port,
long  timeout 
)

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

Definition at line 2477 of file http.c.

References port_set_timeout().

2478 {
2479  port_set_timeout(port, timeout);
2480 }
static void port_set_timeout(int port, long timeout)
Definition: http.c:2173
Definition: http.c:2014

◆ http_shutdown()

void http_shutdown ( void  )

Definition at line 3618 of file http.c.

References client_shutdown(), conn_pool_shutdown(), gw_assert(), gwlib_assert_init(), limbo, port_shutdown(), proxy_shutdown(), run_status, running, server_shutdown(), and terminating.

Referenced by gwlib_shutdown().

3619 {
3622 
3624 
3626  client_shutdown();
3627  server_shutdown();
3628  port_shutdown();
3629  proxy_shutdown();
3630 #ifdef HAVE_LIBSSL
3631  conn_shutdown_ssl();
3632  server_shutdown_ssl();
3633 #endif /* HAVE_LIBSSL */
3634  run_status = limbo;
3635 }
gw_assert(wtls_machine->packet_to_send !=NULL)
Definition: http.c:115
static void server_shutdown(void)
Definition: http.c:2799
static enum @59 run_status
Definition: http.c:114
static void conn_pool_shutdown(void)
Definition: http.c:769
void() gwlib_assert_init(void)
Definition: gwlib.c:72
static void port_shutdown(void)
Definition: http.c:2042
static void proxy_shutdown(void)
Definition: http.c:232
static void client_shutdown(void)
Definition: http.c:1848

◆ http_start_request()

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

Definition at line 1760 of file http.c.

References caller, gwlist_produce(), HTTP_MAX_FOLLOW, http_start_request(), method, pending_requests, HTTPServer::request_id, server_create(), start_client_threads(), and url.

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

1762 {
1763  HTTPServer *trans;
1764  int follow_remaining;
1765 
1766  if (follow)
1767  follow_remaining = HTTP_MAX_FOLLOW;
1768  else
1769  follow_remaining = 0;
1770 
1771  trans = server_create(caller, method, url, headers, body, follow_remaining,
1772  certkeyfile);
1773 
1774  if (id == NULL)
1775  /* We don't leave this NULL so http_receive_result can use NULL
1776  * to signal no more requests */
1777  trans->request_id = http_start_request;
1778  else
1779  trans->request_id = id;
1780 
1783 }
#define HTTP_MAX_FOLLOW
Definition: http.c:653
static List * pending_requests
Definition: http.c:633
void * request_id
Definition: http.c:669
void gwlist_produce(List *list, void *item)
Definition: list.c:411
static HTTPCaller * caller
Definition: smsbox.c:442
void http_start_request(HTTPCaller *caller, int method, Octstr *url, List *headers, Octstr *body, int follow, void *id, Octstr *certkeyfile)
Definition: http.c:1760
static int method
Definition: test_http.c:76
static HTTPServer * server_create(HTTPCaller *caller, int method, Octstr *url, List *headers, Octstr *body, int follow_remaining, Octstr *certkeyfile)
Definition: http.c:700
static Octstr * url
Definition: test_xmlrpc.c:84
static void start_client_threads(void)
Definition: http.c:1723

◆ http_status_class()

int http_status_class ( int  code)

Definition at line 3642 of file http.c.

References code, and HTTP_STATUS_UNKNOWN.

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

3643 {
3644  int sclass;
3645 
3646  if (code < 100 || code >= 600)
3647  sclass = HTTP_STATUS_UNKNOWN;
3648  else
3649  sclass = code - (code % 100);
3650  return sclass;
3651 }
int code
Definition: smsc_cimd2.c:346

◆ http_type_accepted()

int http_type_accepted ( List headers,
char *  type 
)

Definition at line 3503 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().

3504 {
3505  return http_something_accepted(headers, "Accept", type);
3506 }
int type
Definition: smsc_cimd2.c:215
static int http_something_accepted(List *headers, char *header_name, char *what)
Definition: http.c:3476

◆ http_urlparse_create()

HTTPURLParse* http_urlparse_create ( void  )

Definition at line 1313 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().

1314 {
1315  HTTPURLParse *p;
1316 
1317  p = gw_malloc(sizeof(HTTPURLParse));
1318  p->url = NULL;
1319  p->scheme = NULL;
1320  p->host = NULL;
1321  p->port = 0;
1322  p->user = NULL;
1323  p->pass = NULL;
1324  p->path = NULL;
1325  p->query = NULL;
1326  p->fragment = NULL;
1327 
1328  return p;
1329 }
Octstr * pass
Definition: http.h:247
Octstr * fragment
Definition: http.h:250
Octstr * query
Definition: http.h:249
unsigned long port
Definition: http.h:245
Octstr * host
Definition: http.h:244
Octstr * url
Definition: http.h:242
Octstr * path
Definition: http.h:248
Octstr * user
Definition: http.h:246
Octstr * scheme
Definition: http.h:243

◆ http_urlparse_destroy()

void http_urlparse_destroy ( HTTPURLParse p)

Definition at line 1332 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 generic_send_sms(), get_connection(), and parse_url().

1333 {
1334  gw_assert(p != NULL);
1335 
1336  octstr_destroy(p->url);
1337  octstr_destroy(p->scheme);
1338  octstr_destroy(p->host);
1339  octstr_destroy(p->user);
1340  octstr_destroy(p->pass);
1341  octstr_destroy(p->path);
1342  octstr_destroy(p->query);
1344  gw_free(p);
1345 }
Octstr * pass
Definition: http.h:247
gw_assert(wtls_machine->packet_to_send !=NULL)
Octstr * fragment
Definition: http.h:250
Octstr * query
Definition: http.h:249
Octstr * host
Definition: http.h:244
Octstr * url
Definition: http.h:242
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Octstr * path
Definition: http.h:248
Octstr * user
Definition: http.h:246
Octstr * scheme
Definition: http.h:243

◆ http_use_proxy()

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

Definition at line 268 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, ssl, and username.

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

270 {
271  Octstr *e;
272  int i;
273 
275  gw_assert(hostname != NULL);
277  gw_assert(port > 0);
278 
281 
283  proxy_port = port;
284  proxy_ssl = ssl;
286  for (i = 0; i < gwlist_len(exceptions); ++i) {
287  e = gwlist_get(exceptions, i);
288  debug("gwlib.http", 0, "HTTP: Proxy exception `%s'.", octstr_get_cstr(e));
290  }
291  if (exceptions_regex != NULL &&
292  (proxy_exceptions_regex = gw_regex_comp(exceptions_regex, REG_EXTENDED)) == NULL)
293  panic(0, "Could not compile pattern '%s'", octstr_get_cstr(exceptions_regex));
296  debug("gwlib.http", 0, "Using proxy <%s:%d> with %s scheme",
298  (proxy_ssl ? "HTTPS" : "HTTP"));
299 
301 }
Definition: http.c:2014
gw_assert(wtls_machine->packet_to_send !=NULL)
int ssl
#define mutex_unlock(m)
Definition: thread.h:136
void gwlist_append(List *list, void *item)
Definition: list.c:179
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static int proxy_ssl
Definition: http.c:202
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
unsigned char * username
Definition: test_cimd2.c:99
Definition: http.c:115
static regex_t * proxy_exceptions_regex
Definition: http.c:206
static int port
Definition: fakesmsc.c:121
unsigned char * password
Definition: test_cimd2.c:100
void http_close_proxy(void)
Definition: http.c:304
static enum @59 run_status
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static int proxy_port
Definition: http.c:201
Octstr * hostname
Definition: fakewap.c:232
static Octstr * proxy_username
Definition: http.c:203
static Mutex * proxy_mutex
Definition: http.c:199
static Octstr * proxy_hostname
Definition: http.c:200
static List * proxy_exceptions
Definition: http.c:205
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
#define panic
Definition: log.h:87
#define gwlist_create()
Definition: list.h:136
#define mutex_lock(m)
Definition: thread.h:130
static Octstr * proxy_password
Definition: http.c:204

◆ parse_cgivars()

void parse_cgivars ( List cgivars,
Octstr pairs 
)

Definition at line 2542 of file http.c.

References gwlist_append(), HTTPCGIVar::name, octstr_copy, octstr_destroy(), octstr_len(), octstr_search_char(), octstr_url_decode(), start, and HTTPCGIVar::value.

Referenced by generic_receive_sms(), and http_accept_request().

2543 {
2544  HTTPCGIVar *v;
2545  Octstr *pair;
2546  long ampersand, equal, start;
2547  long pairs_len = octstr_len(pairs);
2548 
2549  for (start = 0; start < pairs_len; start = ampersand + 1) {
2550  ampersand = octstr_search_char(pairs, '&', start);
2551  if (ampersand == -1)
2552  ampersand = pairs_len;
2553  pair = octstr_copy(pairs, start, ampersand - start);
2554 
2555  equal = octstr_search_char(pair, '=', 0);
2556  if (equal == -1)
2557  equal = octstr_len(pair);
2558 
2559  v = gw_malloc(sizeof(HTTPCGIVar));
2560  v->name = octstr_copy(pair, 0, equal);
2561  v->value = octstr_copy(pair, equal + 1, octstr_len(pair));
2562  octstr_url_decode(v->name);
2564  gwlist_append(cgivars, v);
2565 
2566  octstr_destroy(pair);
2567  }
2568 }
Octstr * value
Definition: http.h:216
void gwlist_append(List *list, void *item)
Definition: list.c:179
int octstr_url_decode(Octstr *ostr)
Definition: octstr.c:1746
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
Octstr * name
Definition: http.h:215
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
static int start

◆ parse_dump()

void parse_dump ( HTTPURLParse p)

Definition at line 1348 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().

1349 {
1350  if (p == NULL)
1351  return;
1352  debug("http.parse_url",0,"Parsing URL `%s':", octstr_get_cstr(p->url));
1353  debug("http.parse_url",0," Scheme: %s", octstr_get_cstr(p->scheme));
1354  debug("http.parse_url",0," Host: %s", octstr_get_cstr(p->host));
1355  debug("http.parse_url",0," Port: %ld", p->port);
1356  debug("http.parse_url",0," Username: %s", octstr_get_cstr(p->user));
1357  debug("http.parse_url",0," Password: %s", octstr_get_cstr(p->pass));
1358  debug("http.parse_url",0," Path: %s", octstr_get_cstr(p->path));
1359  debug("http.parse_url",0," Query: %s", octstr_get_cstr(p->query));
1360  debug("http.parse_url",0," Fragment: %s", octstr_get_cstr(p->fragment));
1361 }
Octstr * pass
Definition: http.h:247
Octstr * fragment
Definition: http.h:250
Octstr * query
Definition: http.h:249
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
unsigned long port
Definition: http.h:245
Octstr * host
Definition: http.h:244
Octstr * url
Definition: http.h:242
Octstr * path
Definition: http.h:248
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
Octstr * user
Definition: http.h:246
Octstr * scheme
Definition: http.h:243

◆ parse_url()

HTTPURLParse* parse_url ( Octstr url)

Definition at line 1377 of file http.c.

References colon, debug(), error(), HTTPURLParse::host, HTTP_PORT, 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(), octstr_url_decode(), parse_dump(), HTTPURLParse::pass, HTTPURLParse::path, HTTPURLParse::port, HTTPURLParse::query, HTTPURLParse::scheme, url, HTTPURLParse::url, and HTTPURLParse::user.

Referenced by generic_send_sms(), and get_connection().

1378 {
1379  HTTPURLParse *p;
1380  Octstr *prefix, *prefix_https;
1381  long prefix_len;
1382  int host_len, colon, slash, at, auth_sep, query;
1383  host_len = colon = slash = at = auth_sep = query = 0;
1384 
1385  prefix = octstr_imm("http://");
1386  prefix_https = octstr_imm("https://");
1387  prefix_len = octstr_len(prefix);
1388 
1389  if (octstr_case_search(url, prefix, 0) != 0) {
1390  if (octstr_case_search(url, prefix_https, 0) == 0) {
1391 #ifdef HAVE_LIBSSL
1392  debug("gwlib.http", 0, "HTTPS URL; Using SSL for the connection");
1393  prefix = prefix_https;
1394  prefix_len = octstr_len(prefix_https);
1395 #else
1396  error(0, "Attempt to use HTTPS <%s> but SSL not compiled in",
1397  octstr_get_cstr(url));
1398  return NULL;
1399 #endif
1400  } else {
1401  error(0, "URL <%s> doesn't start with `%s' nor `%s'",
1403  octstr_get_cstr(prefix_https));
1404  return NULL;
1405  }
1406  }
1407 
1408  /* an URL should be more (at least one charset) then the scheme itself */
1409  if (octstr_len(url) == prefix_len) {
1410  error(0, "URL <%s> is malformed.", octstr_get_cstr(url));
1411  return NULL;
1412  }
1413 
1414  /* check if colon and slashes are within scheme */
1415  colon = octstr_search_char(url, ':', prefix_len);
1416  slash = octstr_search_char(url, '/', prefix_len);
1417  if (colon == prefix_len || slash == prefix_len) {
1418  error(0, "URL <%s> is malformed.", octstr_get_cstr(url));
1419  return NULL;
1420  }
1421 
1422  /* create struct and add values succesively while parsing */
1423  p = http_urlparse_create();
1424  p->url = octstr_duplicate(url);
1425  p->scheme = octstr_duplicate(prefix);
1426 
1427  /* try to parse authentication separator */
1428  at = octstr_search_char(url, '@', prefix_len);
1429  if (at != -1) {
1430  if ((slash == -1 || ( slash != -1 && at < slash))) {
1431  auth_sep = octstr_search_char(url, ':', prefix_len);
1432  if (auth_sep != -1 && (auth_sep < at)) {
1433  octstr_set_char(url, auth_sep, '@');
1434  colon = octstr_search_char(url, ':', prefix_len);
1435  }
1436  } else {
1437  at = -1;
1438  }
1439  }
1440 
1441  /*
1442  * We have to watch out here for 4 cases:
1443  * a) hostname, no port or path
1444  * b) hostname, port, no path
1445  * c) hostname, path, no port
1446  * d) hostname, port and path
1447  */
1448 
1449  /* we only have the hostname, no port or path. */
1450  if (slash == -1 && colon == -1) {
1451  host_len = octstr_len(url) - prefix_len;
1452 #ifdef HAVE_LIBSSL
1453  p->port = (octstr_compare(p->scheme, octstr_imm("https://")) == 0) ?
1455 #else
1456  p->port = HTTP_PORT;
1457 #endif /* HAVE_LIBSSL */
1458  }
1459  /* we have a port, but no path. */
1460  else if (slash == -1) {
1461  host_len = colon - prefix_len;
1462  if (octstr_parse_long((long*) &(p->port), url, colon + 1, 10) == -1) {
1463  error(0, "URL <%s> has malformed port number.",
1464  octstr_get_cstr(url));
1466  return NULL;
1467  }
1468  }
1469  /* we have a path, but no port. */
1470  else if (colon == -1 || colon > slash) {
1471  host_len = slash - prefix_len;
1472 #ifdef HAVE_LIBSSL
1473  p->port = (octstr_compare(p->scheme, octstr_imm("https://")) == 0) ?
1475 #else
1476  p->port = HTTP_PORT;
1477 #endif /* HAVE_LIBSSL */
1478  }
1479  /* we have both, path and port. */
1480  else if (colon < slash) {
1481  host_len = colon - prefix_len;
1482  if (octstr_parse_long((long*) &(p->port), url, colon + 1, 10) == -1) {
1483  error(0, "URL <%s> has malformed port number.",
1484  octstr_get_cstr(url));
1486  return NULL;
1487  }
1488  /* none of the above, so there is something wrong here */
1489  } else {
1490  error(0, "Internal error in URL parsing logic.");
1492  return NULL;
1493  }
1494 
1495  /* there was an authenticator separator, so try to parse
1496  * the username and password credentials */
1497  if (at != -1) {
1498  int at2;
1499 
1500  at2 = octstr_search_char(url, '@', prefix_len);
1501  p->user = octstr_copy(url, prefix_len, at2 - prefix_len);
1502  p->pass = (at2 != at) ? octstr_copy(url, at2 + 1, at - at2 - 1) : NULL;
1503 
1504  /* url-decode user & pass */
1505  if (p->user != NULL)
1506  octstr_url_decode(p->user);
1507  if (p->pass != NULL)
1508  octstr_url_decode(p->pass);
1509 
1510  if (auth_sep != -1)
1511  octstr_set_char(url, auth_sep, ':');
1512 
1513  host_len = host_len - at + prefix_len - 1;
1514  prefix_len = at + 1;
1515  }
1516 
1517  /* query (CGI vars) */
1518  query = octstr_search_char(url, '?', (slash == -1) ? prefix_len : slash);
1519  if (query != -1) {
1520  p->query = octstr_copy(url, query + 1, octstr_len(url));
1521  if (colon == -1)
1522  host_len = slash != -1 ? slash - prefix_len : query - prefix_len;
1523  }
1524 
1525  /* path */
1526  p->path = (slash == -1) ?
1527  octstr_create("/") : ((query != -1) && (query > slash) ?
1528  octstr_copy(url, slash, query - slash) :
1529  octstr_copy(url, slash, octstr_len(url) - slash));
1530 
1531  /* hostname */
1532  p->host = octstr_copy(url, prefix_len, host_len);
1533 
1534  /* XXX add fragment too */
1535 
1536  /* dump components */
1537  parse_dump(p);
1538 
1539  return p;
1540 }
void error(int err, const char *fmt,...)
Definition: log.c:648
Octstr * pass
Definition: http.h:247
int octstr_url_decode(Octstr *ostr)
Definition: octstr.c:1746
Octstr * query
Definition: http.h:249
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
unsigned long port
Definition: http.h:245
Octstr * host
Definition: http.h:244
void http_urlparse_destroy(HTTPURLParse *p)
Definition: http.c:1332
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void parse_dump(HTTPURLParse *p)
Definition: http.c:1348
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * url
Definition: http.h:242
long octstr_case_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1102
#define octstr_create(cstr)
Definition: octstr.h:125
Octstr * path
Definition: http.h:248
static Octstr * colon
Definition: smsc_smasi.c:218
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
long octstr_parse_long(long *nump, Octstr *ostr, long pos, int base)
Definition: octstr.c:749
Octstr * user
Definition: http.h:246
HTTPURLParse * http_urlparse_create(void)
Definition: http.c:1313
static Octstr * url
Definition: test_xmlrpc.c:84
void octstr_set_char(Octstr *ostr, long pos, int ch)
Definition: octstr.c:415
Octstr * scheme
Definition: http.h:243
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.