Kannel: Open Source WAP and SMS gateway  svn-r5285
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
}
 

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)
 
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 329 of file http.h.

◆ HTTPClient

typedef struct HTTPClient HTTPClient

Definition at line 397 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 

Definition at line 202 of file http.h.

202  {
203  HTTP_METHOD_GET = 1,
204  HTTP_METHOD_POST = 2,
205  HTTP_METHOD_HEAD = 3,
206  HTTP_METHOD_PUT = 4,
208 };

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 2570 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().

2573 {
2574  HTTPClient *client;
2575  Octstr *query, *content_type, *charset;
2576  int question_mark;
2577 
2578  do {
2580  if (client == NULL) {
2581  debug("gwlib.http", 0, "HTTP: No clients with requests, quitting.");
2582  return NULL;
2583  }
2584  /* check whether client connection still ok */
2585  conn_wait(client->conn, 0);
2586  if (conn_error(client->conn) || conn_eof(client->conn)) {
2588  client = NULL;
2589  }
2590  } while(client == NULL);
2591 
2592  debug("gwlib.http", 0, "HTTP: Got %s request with url='%s' and body='%s'",
2593  http_method2name(client->method), octstr_get_cstr(client->url), octstr_get_cstr(client->request->body));
2594 
2595  *client_ip = octstr_duplicate(client->ip);
2596  *url = client->url;
2597  *headers = client->request->headers;
2598  *body = client->request->body;
2599  *cgivars = gwlist_create();
2600 
2601  /* is there a query string in the url? */
2602  question_mark = octstr_search_char(*url, '?', 0);
2603  if (question_mark >= 0) {
2604  /* parse the query string */
2605  query = octstr_copy(*url, question_mark + 1, octstr_len(*url));
2606  parse_cgivars(*cgivars, query);
2607  octstr_destroy(query);
2608 
2609  /* remove query string from url */
2610  octstr_truncate(*url, question_mark);
2611  }
2612 
2613  if (client->method == HTTP_METHOD_POST || client->method == HTTP_METHOD_PUT) {
2614  if (octstr_len(*body) > 0) {
2616  if (octstr_str_compare(content_type, "application/x-www-form-urlencoded") == 0) {
2617  /* parse the body */
2618  parse_cgivars(*cgivars, *body);
2619  }
2622  }
2623  } else {
2624  octstr_destroy(*body);
2625  *body = NULL;
2626  }
2627 
2628  client->persistent_conn = client_is_persistent(client->request->headers,
2629  client->use_version_1_0);
2630 
2631  client->url = NULL;
2632  client->request->headers = NULL;
2633  client->request->body = NULL;
2634  entity_destroy(client->request);
2635  client->request = NULL;
2636 
2637  return client;
2638 }
char * http_method2name(int method)
Definition: http.c:3677
Definition: http.c:2004
static HTTPClient * port_get_request(int port)
Definition: http.c:2139
static void parse_cgivars(List *cgivars, Octstr *pairs)
Definition: http.c:2541
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:3224
static int client_is_persistent(List *headers, int use_version_1_0)
Definition: http.c:1972
int conn_eof(Connection *conn)
Definition: conn.c:699
#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:1922
#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:898
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:710
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 3514 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().

3515 {
3516  Octstr *os;
3517 
3518  if (password != NULL)
3519  os = octstr_format("%S:%S", username, password);
3520  else
3521  os = octstr_format("%S", username);
3523  octstr_strip_blanks(os);
3524  octstr_insert(os, octstr_imm("Basic "), 0);
3525  http_header_add(headers, "Authorization", octstr_get_cstr(os));
3526  octstr_destroy(os);
3527 }
void http_header_add(List *headers, char *name, char *contents)
Definition: http.c:2885
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 3051 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().

3052 {
3053  Octstr *header;
3054  long i;
3055 
3057  gw_assert(to != NULL);
3058  gw_assert(from != NULL);
3059 
3060  for (i = 0; i < gwlist_len(from); ++i) {
3061  header = gwlist_get(from, i);
3062  gwlist_append(to, octstr_duplicate(header));
3063  }
3064 }
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:429
#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:429
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:429
void gwlist_remove_producer(List *list)
Definition: list.c:401

◆ http_cgi_variable()

Octstr* http_cgi_variable ( List list,
char *  name 
)

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

2836 {
2837  int i;
2838  HTTPCGIVar *v;
2839 
2841  gw_assert(list != NULL);
2842  gw_assert(name != NULL);
2843 
2844  for (i = 0; i < gwlist_len(list); ++i) {
2845  v = gwlist_get(list, i);
2846  if (octstr_str_compare(v->name, name) == 0)
2847  return v->value;
2848  }
2849  return NULL;
2850 }
Octstr * value
Definition: http.h:215
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:214
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 3439 of file http.c.

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

3440 {
3441  HTTPCGIVar *v;
3442  long i, len;
3443 
3445 
3446  len = gwlist_len(cgiargs);
3447 
3448  debug("gwlib.http", 0, "Dumping %ld cgi variables:", len);
3449  for (i = 0; i < len; i++) {
3450  v = gwlist_get(cgiargs, i);
3451  octstr_dump(v->name, 0);
3452  octstr_dump(v->value, 0);
3453  }
3454  debug("gwlib.http", 0, "End of dump.");
3455 }
Octstr * value
Definition: http.h:215
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:214
#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 3458 of file http.c.

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

Referenced by httpsmsc_receiver().

3459 {
3460  HTTPCGIVar *v;
3461  long i;
3462 
3463  if (os == NULL)
3464  return;
3465 
3467 
3468  for (i = 0; i < gwlist_len(cgiargs); i++) {
3469  v = gwlist_get(cgiargs, i);
3470  octstr_format_append(os, "&%E=%E", v->name, v->value);
3471  }
3472 }
Octstr * value
Definition: http.h:215
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:214
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 3508 of file http.c.

References charset, and http_something_accepted().

Referenced by add_charset_headers(), and normalize_charset().

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

◆ http_close_all_ports()

void http_close_all_ports ( void  )

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

2526 {
2527  if (server_thread_id != -1) {
2528  keep_servers_open = 0;
2532  }
2533 }
static long server_thread_id
Definition: http.c:1884
void gwthread_join_every(gwthread_func_t *func)
static int keep_servers_open
Definition: http.c:1887
void gwthread_wakeup(long thread)
static void server_thread(void *dummy)
Definition: http.c:2343
static volatile sig_atomic_t server_thread_is_running
Definition: http.c:1883

◆ http_close_client()

void http_close_client ( HTTPClient client)

Definition at line 2757 of file http.c.

References client(), and client_destroy().

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

2758 {
2760 }
static void client(int port)
Definition: test_udp.c:77
static void client_destroy(void *client)
Definition: http.c:1922

◆ http_close_port()

void http_close_port ( int  port)

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

2515 {
2516  int *p;
2517 
2518  p = gw_malloc(sizeof(*p));
2519  *p = port;
2522 }
static long server_thread_id
Definition: http.c:1884
void gwlist_produce(List *list, void *item)
Definition: list.c:411
static int port
Definition: fakesmsc.c:120
static List * closed_server_sockets
Definition: http.c:1886
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 2817 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().

2818 {
2819  HTTPCGIVar *v;
2820 
2822 
2823  if (args == NULL)
2824  return ;
2825 
2826  while ((v = gwlist_extract_first(args)) != NULL) {
2827  octstr_destroy(v->name);
2828  octstr_destroy(v->value);
2829  gw_free(v);
2830  }
2831  gwlist_destroy(args, NULL);
2832 }
Octstr * value
Definition: http.h:215
Octstr * name
Definition: http.h:214
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 2878 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().

2879 {
2882 }
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 3530 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().

3531 {
3532  long pos, len, end;
3533  int c, found = 0;
3534  Octstr *result = NULL;
3535 
3536  len = octstr_len(value);
3537  /* Find the start of the first parameter. */
3538  for (pos = 0; pos < len; pos++) {
3539  c = octstr_get_char(value, pos);
3540  if (c == ';')
3541  break;
3542  else if (c == '"')
3543  pos += http_header_quoted_string_len(value, pos) - 1;
3544  }
3545 
3546  if (pos >= len)
3547  return NULL; /* no parameters */
3548 
3549  for (pos++; pos > 0 && pos < len && found == 0; pos++) {
3550  Octstr *key = NULL;
3551  Octstr *val = NULL;
3552 
3553  end = octstr_search_char(value, '=', pos);
3554  if (end < 0)
3555  end = octstr_search_char(value, ';', pos);
3556  if (end < 0)
3557  end = octstr_len(value);
3558  key = octstr_copy(value, pos, end - pos);
3559  octstr_strip_blanks(key);
3560  pos = end;
3561 
3562  if (octstr_get_char(value, pos) == '=') {
3563  pos++;
3564  while (isspace(octstr_get_char(value, pos)))
3565  pos++;
3566  if (octstr_get_char(value, pos) == '"')
3567  end = pos + http_header_quoted_string_len(value, pos);
3568  else
3569  end = octstr_search_char(value, ';', pos);
3570  if (end < 0)
3571  end = octstr_len(value);
3572  val = octstr_copy(value, pos, end - pos);
3573  octstr_strip_blanks(val);
3574  pos = end;
3575  pos = octstr_search_char(value, ';', pos);
3576  }
3577 
3578  /* is this the pair we look for? bail out then*/
3579  if (octstr_case_compare(key, parameter) == 0) {
3580  found++;
3581  result = octstr_duplicate(val);
3582  }
3583 
3584  octstr_destroy(key);
3585  octstr_destroy(val);
3586  }
3587 
3588  return result;
3589 }
long http_header_quoted_string_len(Octstr *header, long start)
Definition: http.c:3292
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 1811 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().

1813 {
1814  HTTPCaller *caller;
1815  int status;
1816  void *ret;
1817 
1819  http_start_request(caller, method, url, request_headers,
1820  NULL, 1, http_get_real, NULL);
1821  ret = http_receive_result(caller, &status, final_url,
1822  reply_headers, reply_body);
1824  if (ret == NULL)
1825  return -1;
1826  return status;
1827 }
static HTTPCaller * caller
Definition: smsbox.c:429
void http_start_request(HTTPCaller *caller, int method, Octstr *url, List *headers, Octstr *body, int follow, void *id, Octstr *certkeyfile)
Definition: http.c:1750
static int method
Definition: test_http.c:76
#define http_receive_result(caller, status, final_url, headers, body)
Definition: http.h:385
int http_get_real(int method, Octstr *url, List *request_headers, Octstr **final_url, List **reply_headers, Octstr **reply_body)
Definition: http.c:1811
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 2885 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(), 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().

2886 {
2888  gw_assert(headers != NULL);
2889  gw_assert(name != NULL);
2890  gw_assert(contents != NULL);
2891 
2892  gwlist_append(headers, octstr_format("%s: %s", name, contents));
2893 }
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 3067 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().

3068 {
3069  long i;
3070  Octstr *name;
3071  Octstr *value;
3072 
3073  /*
3074  * Avoid doing this scan if old_headers is empty anyway.
3075  */
3076  if (gwlist_len(old_headers) > 0) {
3077  for (i = 0; i < gwlist_len(new_headers); i++) {
3078  http_header_get(new_headers, i, &name, &value);
3081  octstr_destroy(value);
3082  }
3083  }
3084 
3085  http_append_headers(old_headers, new_headers);
3086 }
void http_header_get(List *headers, long i, Octstr **name, Octstr **value)
Definition: http.c:2901
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:3051
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:3134

◆ http_header_dump()

void http_header_dump ( List headers)

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

3427 {
3428  long i;
3429 
3431 
3432  debug("gwlib.http", 0, "Dumping HTTP headers:");
3433  for (i = 0; headers != NULL && i < gwlist_len(headers); ++i)
3434  octstr_dump(gwlist_get(headers, i), 1);
3435  debug("gwlib.http", 0, "End of dump.");
3436 }
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 2968 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().

2969 {
2970  List *new;
2971  long i, len;
2972 
2974 
2975  if (headers == NULL)
2976  return NULL;
2977 
2978  new = http_create_empty_headers();
2979  len = gwlist_len(headers);
2980  for (i = 0; i < len; ++i)
2981  gwlist_append(new, octstr_duplicate(gwlist_get(headers, i)));
2982  return new;
2983 }
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:2871
#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 3114 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().

3115 {
3116  List *list;
3117  long i;
3118  Octstr *h;
3119 
3121  gw_assert(headers != NULL);
3122  gw_assert(name != NULL);
3123 
3124  list = gwlist_create();
3125  for (i = 0; i < gwlist_len(headers); ++i) {
3126  h = gwlist_get(headers, i);
3127  if (header_is_called(h, name))
3128  gwlist_append(list, octstr_duplicate(h));
3129  }
3130  return list;
3131 }
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:2858
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 3089 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().

3091 {
3092  long i, name_len;
3093  Octstr *h, *value;
3094 
3096  gw_assert(headers != NULL);
3097  gw_assert(name != NULL);
3098 
3099  name_len = strlen(name);
3100 
3101  for (i = 0; i < gwlist_len(headers); ++i) {
3102  h = gwlist_get(headers, i);
3103  if (header_is_called(h, name)) {
3104  value = octstr_copy_real(h, name_len + 1, octstr_len(h),
3105  file, line, func);
3106  octstr_strip_blanks(value);
3107  return value;
3108  }
3109  }
3110  return NULL;
3111 }
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:2858

◆ http_header_get()

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

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

2902 {
2903  Octstr *os;
2904  long colon;
2905 
2907  gw_assert(i >= 0);
2908  gw_assert(name != NULL);
2909  gw_assert(value != NULL);
2910 
2911  os = gwlist_get(headers, i);
2912  if (os == NULL)
2913  colon = -1;
2914  else
2915  colon = octstr_search_char(os, ':', 0);
2916  if (colon == -1) {
2917  error(0, "HTTP: Header does not contain a colon. BAD.");
2918  *name = octstr_create("X-Unknown");
2919  *value = octstr_duplicate(os);
2920  } else {
2921  *name = octstr_copy(os, 0, colon);
2922  *value = octstr_copy(os, colon + 1, octstr_len(os) - colon - 1);
2923  octstr_strip_blanks(*value);
2924  }
2925 }
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 3224 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 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().

3226 {
3227  Octstr *h;
3228  long semicolon, equals, len;
3229 
3231  gw_assert(headers != NULL);
3232  gw_assert(type != NULL);
3233  gw_assert(charset != NULL);
3234 
3235  h = http_header_find_first(headers, "Content-Type");
3236  if (h == NULL) {
3237  *type = octstr_create("application/octet-stream");
3238  *charset = octstr_create("");
3239  } else {
3241  semicolon = octstr_search_char(h, ';', 0);
3242  if (semicolon == -1) {
3243  *type = h;
3244  *charset = octstr_create("");
3245  } else {
3246  *charset = octstr_duplicate(h);
3247  octstr_delete(*charset, 0, semicolon + 1);
3249  equals = octstr_search_char(*charset, '=', 0);
3250  if (equals == -1)
3251  octstr_truncate(*charset, 0);
3252  else {
3253  octstr_delete(*charset, 0, equals + 1);
3254  if (octstr_get_char(*charset, 0) == '"')
3255  octstr_delete(*charset, 0, 1);
3256  len = octstr_len(*charset);
3257  if (octstr_get_char(*charset, len - 1) == '"')
3258  octstr_truncate(*charset, len - 1);
3259  }
3260 
3261  octstr_truncate(h, semicolon);
3263  *type = h;
3264  }
3265 
3266  /*
3267  * According to HTTP/1.1 (RFC 2616, section 3.7.1) we have to ensure
3268  * to return charset 'iso-8859-1' in case of no given encoding and
3269  * content-type is a 'text' subtype.
3270  */
3271  if (octstr_len(*charset) == 0 &&
3272  octstr_ncompare(*type, octstr_imm("text"), 4) == 0)
3273  octstr_append_cstr(*charset, "ISO-8859-1");
3274  }
3275 }
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:594
#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 3202 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().

3204 {
3205  Octstr *new_length = NULL;
3206 
3207  /* Remove all headers that no longer apply to the new body. */
3208  http_header_remove_all(headers, "Content-Length");
3209  http_header_remove_all(headers, "Content-MD5");
3210  http_header_remove_all(headers, "Content-Type");
3211 
3212  /* Add headers that we need to describe the new body. */
3213  new_length = octstr_format("%ld", octstr_len(new_body));
3214  http_header_add(headers, "Content-Length", octstr_get_cstr(new_length));
3215  if(octstr_len(new_type))
3216  http_header_add(headers, "Content-Type", octstr_get_cstr(new_type));
3217 
3218  /* Perhaps we should add Warning: 214 "Transformation applied" too? */
3219 
3220  octstr_destroy(new_length);
3221 }
void http_header_add(List *headers, char *name, char *contents)
Definition: http.c:2885
#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:3134

◆ http_header_pack()

void http_header_pack ( List headers)

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

2992 {
2993  Octstr *name, *value;
2994  Octstr *name2, *value2;
2995  long i, j;
2996 
2998  gw_assert(headers != NULL);
2999 
3000  /*
3001  * For each header, search forward headers for similar ones and if possible,
3002  * add it to current header and delete it
3003  */
3004  for(i = 0; i < gwlist_len(headers); i++) {
3005  http_header_get(headers, i, &name, &value);
3006  /* debug("http_header_pack", 0, "HTTP_HEADER_PACK: Processing header %d. [%s: %s]",
3007  i, octstr_get_cstr(name), octstr_get_cstr(value)); */
3008 
3009  for(j=i+1; j < gwlist_len(headers); j++) {
3010  http_header_get(headers, j, &name2, &value2);
3011 
3012  if(octstr_case_compare(name, name2) == 0) {
3013  if(octstr_len(value) + 2 + octstr_len(value2) > MAX_HEADER_LENGTH) {
3014  octstr_destroy(name2);
3015  octstr_destroy(value2);
3016  break;
3017  } else {
3018  Octstr *header;
3019 
3020  /* Delete old header */
3021  header = gwlist_get(headers, i);
3022  octstr_destroy(header);
3023  gwlist_delete(headers, i, 1);
3024 
3025  /* Adds comma and new value to old header value */
3026  octstr_append(value, octstr_imm(", "));
3027  octstr_append(value, value2);
3028  /* Creates a new header */
3029  header = octstr_create("");
3030  octstr_append(header, name);
3031  octstr_append(header, octstr_imm(": "));
3032  octstr_append(header, value);
3033  gwlist_insert(headers, i, header);
3034 
3035  /* Delete this header */
3036  header = gwlist_get(headers, j);
3037  octstr_destroy(header);
3038  gwlist_delete(headers, j, 1);
3039  j--;
3040  }
3041  }
3042  octstr_destroy(name2);
3043  octstr_destroy(value2);
3044  }
3046  octstr_destroy(value);
3047  }
3048 }
void http_header_get(List *headers, long i, Octstr **name, Octstr **value)
Definition: http.c:2901
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:2986
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 3292 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().

3293 {
3294  long len;
3295  long pos;
3296  int c;
3297 
3298  if (octstr_get_char(header, start) != '"')
3299  return -1;
3300 
3301  len = octstr_len(header);
3302  for (pos = start + 1; pos < len; pos++) {
3303  c = octstr_get_char(header, pos);
3304  if (c == '\\') /* quoted-pair */
3305  pos++;
3306  else if (c == '"')
3307  return pos - start + 1;
3308  }
3309 
3310  warning(0, "Header contains unterminated quoted-string:");
3311  warning(0, "%s", octstr_get_cstr(header));
3312  return len - start;
3313 }
#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 3134 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().

3135 {
3136  long i;
3137  Octstr *h;
3138  long count;
3139 
3141  gw_assert(headers != NULL);
3142  gw_assert(name != NULL);
3143 
3144  i = 0;
3145  count = 0;
3146  while (i < gwlist_len(headers)) {
3147  h = gwlist_get(headers, i);
3148  if (header_is_called(h, name)) {
3149  gwlist_delete(headers, i, 1);
3150  octstr_destroy(h);
3151  count++;
3152  } else
3153  i++;
3154  }
3155 
3156  return count;
3157 }
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:2858

◆ http_header_split_auth_value()

List* http_header_split_auth_value ( Octstr value)

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

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

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

◆ http_header_value()

Octstr* http_header_value ( List headers,
Octstr header 
)

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

2932 {
2933  Octstr *value;
2934  long i;
2935  Octstr *os;
2936  long colon;
2937  Octstr *current_name;
2938 
2940  gw_assert(name);
2941 
2942  value = NULL;
2943  i = 0;
2944  while (i < gwlist_len(headers)) {
2945  os = gwlist_get(headers, i);
2946  if (os == NULL)
2947  colon = -1;
2948  else
2949  colon = octstr_search_char(os, ':', 0);
2950  if (colon == -1) {
2951  return NULL;
2952  } else {
2953  current_name = octstr_copy(os, 0, colon);
2954  }
2955  if (octstr_case_compare(current_name, name) == 0) {
2956  value = octstr_copy(os, colon + 1, octstr_len(os) - colon - 1);
2957  octstr_strip_blanks(value);
2958  octstr_destroy(current_name);
2959  return value;
2960  }
2961  octstr_destroy(current_name);
2962  ++i;
2963  }
2964 
2965  return NULL;
2966 }
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 3597 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().

3598 {
3600 
3601 #ifdef HAVE_LIBSSL
3602  conn_init_ssl();
3603 #endif /* HAVE_LIBSSL */
3604  proxy_init();
3605  client_init();
3606  conn_pool_init();
3607  port_init();
3608  server_init();
3609 #ifdef HAVE_LIBSSL
3610  server_ssl_init();
3611 #endif /* HAVE_LIBSSL */
3612 
3613  run_status = running;
3614 }
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:2772
static void client_init(void)
Definition: http.c:1830
Definition: http.c:115
static void conn_pool_init(void)
Definition: http.c:762
static void port_init(void)
Definition: http.c:2024
static enum @59 run_status
Definition: http.c:114

◆ http_method()

int http_method ( HTTPClient client)

Definition at line 2762 of file http.c.

References client().

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

◆ http_method2name()

char* http_method2name ( int  method)

Definition at line 3677 of file http.c.

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

Referenced by http_accept_request(), and send_request().

3678 {
3680 
3681  return http_methods[method-1];
3682 }
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 3653 of file http.c.

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

Referenced by main(), and start_fetch().

3654 {
3655  gw_assert(method != NULL);
3656 
3657  if (octstr_str_compare(method, "GET") == 0) {
3658  return HTTP_METHOD_GET;
3659  }
3660  else if (octstr_str_compare(method, "POST") == 0) {
3661  return HTTP_METHOD_POST;
3662  }
3663  else if (octstr_str_compare(method, "HEAD") == 0) {
3664  return HTTP_METHOD_HEAD;
3665  }
3666  else if (octstr_str_compare(method, "PUT") == 0) {
3667  return HTTP_METHOD_PUT;
3668  }
3669  else if (octstr_str_compare(method, "DELETE") == 0) {
3670  return HTTP_METHOD_DELETE;
3671  }
3672 
3673  return -1;
3674 }
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 2508 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().

2509 {
2510  return http_open_port_if(port, ssl, NULL);
2511 }
Definition: http.c:2004
int ssl
int http_open_port_if(int port, int ssl, Octstr *interface)
Definition: http.c:2482

◆ http_open_port_if()

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

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

2483 {
2484  struct port *p;
2485 
2486  if (ssl)
2487  info(0, "HTTP: Opening SSL server at port %d.", port);
2488  else
2489  info(0, "HTTP: Opening server at port %d.", port);
2490  p = port_add(port);
2491  p->port = port;
2492  p->ssl = ssl;
2493  p->fd = make_server_socket(port, (interface ? octstr_get_cstr(interface) : NULL));
2494  if (p->fd == -1) {
2495  port_remove(port);
2496  return -1;
2497  }
2498 
2500  keep_servers_open = 1;
2503 
2504  return 0;
2505 }
void info(int err, const char *fmt,...)
Definition: log.c:672
Definition: http.c:2004
static long server_thread_id
Definition: http.c:1884
int ssl
void gwlist_produce(List *list, void *item)
Definition: list.c:411
int port
Definition: http.c:2006
int ssl
Definition: http.c:2007
int fd
Definition: http.c:2005
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
static List * new_server_sockets
Definition: http.c:1885
static void port_remove(int port)
Definition: http.c:2071
static int port
Definition: fakesmsc.c:120
int make_server_socket(int port, const char *interface_name)
Definition: socket.c:93
static int keep_servers_open
Definition: http.c:1887
void gwthread_wakeup(long thread)
static void start_server_thread(void)
Definition: http.c:2457
static struct port * port_add(int port)
Definition: http.c:2047

◆ 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 1776 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.

1778 {
1779  HTTPServer *trans;
1780  void *request_id;
1781 
1782  if (blocking == 0)
1783  trans = gwlist_extract_first(caller);
1784  else
1785  trans = gwlist_consume(caller);
1786  if (trans == NULL)
1787  return NULL;
1788 
1789  request_id = trans->request_id;
1790  *status = trans->status;
1791 
1792  if (trans->status >= 0) {
1793  *final_url = trans->url;
1794  *headers = trans->response->headers;
1795  *body = trans->response->body;
1796 
1797  trans->url = NULL;
1798  trans->response->headers = NULL;
1799  trans->response->body = NULL;
1800  } else {
1801  *final_url = NULL;
1802  *headers = NULL;
1803  *body = NULL;
1804  }
1805 
1806  server_destroy(trans);
1807  return request_id;
1808 }
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:429
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 3160 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().

3161 {
3162  Octstr *h;
3163  List *connection_headers;
3164 
3166  gw_assert(headers != NULL);
3167 
3168  /*
3169  * The hop-by-hop headers are a standard list, plus those named
3170  * in the Connection header(s).
3171  */
3172 
3173  connection_headers = http_header_find_all(headers, "Connection");
3174  while ((h = gwlist_consume(connection_headers))) {
3175  List *hop_headers;
3176  Octstr *e;
3177 
3178  octstr_delete(h, 0, strlen("Connection:"));
3179  hop_headers = http_header_split_value(h);
3180  octstr_destroy(h);
3181 
3182  while ((e = gwlist_consume(hop_headers))) {
3184  octstr_destroy(e);
3185  }
3186 
3187  gwlist_destroy(hop_headers, NULL);
3188  }
3189  gwlist_destroy(connection_headers, NULL);
3190 
3191  http_header_remove_all(headers, "Connection");
3192  http_header_remove_all(headers, "Keep-Alive");
3193  http_header_remove_all(headers, "Proxy-Authenticate");
3194  http_header_remove_all(headers, "Proxy-Authorization");
3195  http_header_remove_all(headers, "TE");
3196  http_header_remove_all(headers, "Trailers");
3197  http_header_remove_all(headers, "Transfer-Encoding");
3198  http_header_remove_all(headers, "Upgrade");
3199 }
List * http_header_find_all(List *headers, char *name)
Definition: http.c:3114
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:3316
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:3134
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 2767 of file http.c.

References client().

2768 {
2769  return client->url;
2770 }
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 2694 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().

2696 {
2697  Octstr *response;
2698  Octstr *date;
2699  long i;
2700  int ret;
2701 
2702  if (client->use_version_1_0)
2703  response = octstr_format("HTTP/1.0 %d %s\r\n", status, http_reason_phrase(status));
2704  else
2705  response = octstr_format("HTTP/1.1 %d %s\r\n", status, http_reason_phrase(status));
2706 
2707  /* identify ourselfs */
2708  octstr_format_append(response, "Server: " GW_NAME "/%s\r\n", GW_VERSION);
2709 
2710  /* let's inform the client of our time */
2711  date = date_format_http(time(NULL));
2714 
2715  octstr_format_append(response, "Content-Length: %ld\r\n", octstr_len(body));
2716 
2717  /* Indicate if we're keeping the connection or closing. */
2718  if (client->persistent_conn)
2719  octstr_format_append(response, "Connection: Keep-Alive\r\n");
2720  else
2721  octstr_format_append(response, "Connection: Close\r\n");
2722 
2723  for (i = 0; i < gwlist_len(headers); ++i)
2724  octstr_format_append(response, "%S\r\n", gwlist_get(headers, i));
2725  octstr_format_append(response, "\r\n");
2726 
2727  if (body != NULL && client->method != HTTP_METHOD_HEAD && client->method != HTTP_METHOD_DELETE)
2728  octstr_append(response, body);
2729 
2730  ret = conn_write(client->conn, response);
2732 
2733  /* obey return code of conn_write() */
2734  /* sending response was successful */
2735  if (ret == 0) {
2736  /* HTTP/1.0 or 1.1, hence keep-alive or keep-alive */
2737  if (!client->persistent_conn) {
2739  } else {
2740  /* XXX mark this HTTPClient in the keep-alive cleaner thread */
2743  }
2744  }
2745  /* queued for sending, we don't want to block */
2746  else if (ret == 1) {
2747  client->state = sending_reply;
2749  }
2750  /* error while sending response */
2751  else {
2753  }
2754 }
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:1922
static const char * http_reason_phrase(int status)
Definition: http.c:2644
int conn_write(Connection *conn, Octstr *data)
Definition: conn.c:1045
static FDSet * port_get_fdset(int port)
Definition: http.c:2180
static void client_reset(HTTPClient *p)
Definition: http.c:1957
#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:2250
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 1741 of file http.c.

References client_fdset, fdset_set_timeout(), and http_client_timeout.

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

1742 {
1743  http_client_timeout = timeout;
1744  if (client_fdset != NULL) {
1745  /* we are already initialized set timeout in fdset */
1747  }
1748 }
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 1736 of file http.c.

References http_interface, octstr_duplicate, and our_host.

Referenced by config_reload().

1737 {
1739 }
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 2476 of file http.c.

References port_set_timeout().

2477 {
2478  port_set_timeout(port, timeout);
2479 }
static void port_set_timeout(int port, long timeout)
Definition: http.c:2163
Definition: http.c:2004

◆ http_shutdown()

void http_shutdown ( void  )

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

3618 {
3621 
3623 
3625  client_shutdown();
3626  server_shutdown();
3627  port_shutdown();
3628  proxy_shutdown();
3629 #ifdef HAVE_LIBSSL
3630  conn_shutdown_ssl();
3631  server_shutdown_ssl();
3632 #endif /* HAVE_LIBSSL */
3633  run_status = limbo;
3634 }
gw_assert(wtls_machine->packet_to_send !=NULL)
Definition: http.c:115
static void server_shutdown(void)
Definition: http.c:2798
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:2032
static void proxy_shutdown(void)
Definition: http.c:232
static void client_shutdown(void)
Definition: http.c:1838

◆ 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 1750 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().

1752 {
1753  HTTPServer *trans;
1754  int follow_remaining;
1755 
1756  if (follow)
1757  follow_remaining = HTTP_MAX_FOLLOW;
1758  else
1759  follow_remaining = 0;
1760 
1761  trans = server_create(caller, method, url, headers, body, follow_remaining,
1762  certkeyfile);
1763 
1764  if (id == NULL)
1765  /* We don't leave this NULL so http_receive_result can use NULL
1766  * to signal no more requests */
1767  trans->request_id = http_start_request;
1768  else
1769  trans->request_id = id;
1770 
1773 }
#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:429
void http_start_request(HTTPCaller *caller, int method, Octstr *url, List *headers, Octstr *body, int follow, void *id, Octstr *certkeyfile)
Definition: http.c:1750
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:1713

◆ http_status_class()

int http_status_class ( int  code)

Definition at line 3641 of file http.c.

References code, and HTTP_STATUS_UNKNOWN.

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

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

◆ http_type_accepted()

int http_type_accepted ( List headers,
char *  type 
)

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

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

◆ http_urlparse_create()

HTTPURLParse* http_urlparse_create ( void  )

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

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

◆ http_urlparse_destroy()

void http_urlparse_destroy ( HTTPURLParse p)

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

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

◆ 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:2004
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:120
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_dump()

void parse_dump ( HTTPURLParse p)

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

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

◆ parse_url()

HTTPURLParse* parse_url ( Octstr url)

Definition at line 1373 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(), parse_dump(), HTTPURLParse::pass, HTTPURLParse::path, HTTPURLParse::port, HTTPURLParse::query, HTTPURLParse::scheme, url, HTTPURLParse::url, and HTTPURLParse::user.

Referenced by get_connection().

1374 {
1375  HTTPURLParse *p;
1376  Octstr *prefix, *prefix_https;
1377  long prefix_len;
1378  int host_len, colon, slash, at, auth_sep, query;
1379  host_len = colon = slash = at = auth_sep = query = 0;
1380 
1381  prefix = octstr_imm("http://");
1382  prefix_https = octstr_imm("https://");
1383  prefix_len = octstr_len(prefix);
1384 
1385  if (octstr_case_search(url, prefix, 0) != 0) {
1386  if (octstr_case_search(url, prefix_https, 0) == 0) {
1387 #ifdef HAVE_LIBSSL
1388  debug("gwlib.http", 0, "HTTPS URL; Using SSL for the connection");
1389  prefix = prefix_https;
1390  prefix_len = octstr_len(prefix_https);
1391 #else
1392  error(0, "Attempt to use HTTPS <%s> but SSL not compiled in",
1393  octstr_get_cstr(url));
1394  return NULL;
1395 #endif
1396  } else {
1397  error(0, "URL <%s> doesn't start with `%s' nor `%s'",
1399  octstr_get_cstr(prefix_https));
1400  return NULL;
1401  }
1402  }
1403 
1404  /* an URL should be more (at least one charset) then the scheme itself */
1405  if (octstr_len(url) == prefix_len) {
1406  error(0, "URL <%s> is malformed.", octstr_get_cstr(url));
1407  return NULL;
1408  }
1409 
1410  /* check if colon and slashes are within scheme */
1411  colon = octstr_search_char(url, ':', prefix_len);
1412  slash = octstr_search_char(url, '/', prefix_len);
1413  if (colon == prefix_len || slash == prefix_len) {
1414  error(0, "URL <%s> is malformed.", octstr_get_cstr(url));
1415  return NULL;
1416  }
1417 
1418  /* create struct and add values succesively while parsing */
1419  p = http_urlparse_create();
1420  p->url = octstr_duplicate(url);
1421  p->scheme = octstr_duplicate(prefix);
1422 
1423  /* try to parse authentication separator */
1424  at = octstr_search_char(url, '@', prefix_len);
1425  if (at != -1) {
1426  if ((slash == -1 || ( slash != -1 && at < slash))) {
1427  auth_sep = octstr_search_char(url, ':', prefix_len);
1428  if (auth_sep != -1 && (auth_sep < at)) {
1429  octstr_set_char(url, auth_sep, '@');
1430  colon = octstr_search_char(url, ':', prefix_len);
1431  }
1432  } else {
1433  at = -1;
1434  }
1435  }
1436 
1437  /*
1438  * We have to watch out here for 4 cases:
1439  * a) hostname, no port or path
1440  * b) hostname, port, no path
1441  * c) hostname, path, no port
1442  * d) hostname, port and path
1443  */
1444 
1445  /* we only have the hostname, no port or path. */
1446  if (slash == -1 && colon == -1) {
1447  host_len = octstr_len(url) - prefix_len;
1448 #ifdef HAVE_LIBSSL
1449  p->port = (octstr_compare(p->scheme, octstr_imm("https://")) == 0) ?
1451 #else
1452  p->port = HTTP_PORT;
1453 #endif /* HAVE_LIBSSL */
1454  }
1455  /* we have a port, but no path. */
1456  else if (slash == -1) {
1457  host_len = colon - prefix_len;
1458  if (octstr_parse_long((long*) &(p->port), url, colon + 1, 10) == -1) {
1459  error(0, "URL <%s> has malformed port number.",
1460  octstr_get_cstr(url));
1462  return NULL;
1463  }
1464  }
1465  /* we have a path, but no port. */
1466  else if (colon == -1 || colon > slash) {
1467  host_len = slash - prefix_len;
1468 #ifdef HAVE_LIBSSL
1469  p->port = (octstr_compare(p->scheme, octstr_imm("https://")) == 0) ?
1471 #else
1472  p->port = HTTP_PORT;
1473 #endif /* HAVE_LIBSSL */
1474  }
1475  /* we have both, path and port. */
1476  else if (colon < slash) {
1477  host_len = colon - prefix_len;
1478  if (octstr_parse_long((long*) &(p->port), url, colon + 1, 10) == -1) {
1479  error(0, "URL <%s> has malformed port number.",
1480  octstr_get_cstr(url));
1482  return NULL;
1483  }
1484  /* none of the above, so there is something wrong here */
1485  } else {
1486  error(0, "Internal error in URL parsing logic.");
1488  return NULL;
1489  }
1490 
1491  /* there was an authenticator separator, so try to parse
1492  * the username and password credentials */
1493  if (at != -1) {
1494  int at2;
1495 
1496  at2 = octstr_search_char(url, '@', prefix_len);
1497  p->user = octstr_copy(url, prefix_len, at2 - prefix_len);
1498  p->pass = (at2 != at) ? octstr_copy(url, at2 + 1, at - at2 - 1) : NULL;
1499 
1500  if (auth_sep != -1)
1501  octstr_set_char(url, auth_sep, ':');
1502 
1503  host_len = host_len - at + prefix_len - 1;
1504  prefix_len = at + 1;
1505  }
1506 
1507  /* query (CGI vars) */
1508  query = octstr_search_char(url, '?', (slash == -1) ? prefix_len : slash);
1509  if (query != -1) {
1510  p->query = octstr_copy(url, query + 1, octstr_len(url));
1511  if (colon == -1)
1512  host_len = slash != -1 ? slash - prefix_len : query - prefix_len;
1513  }
1514 
1515  /* path */
1516  p->path = (slash == -1) ?
1517  octstr_create("/") : ((query != -1) && (query > slash) ?
1518  octstr_copy(url, slash, query - slash) :
1519  octstr_copy(url, slash, octstr_len(url) - slash));
1520 
1521  /* hostname */
1522  p->host = octstr_copy(url, prefix_len, host_len);
1523 
1524  /* XXX add fragment too */
1525 
1526  /* dump components */
1527  parse_dump(p);
1528 
1529  return p;
1530 }
void error(int err, const char *fmt,...)
Definition: log.c:648
Octstr * pass
Definition: http.h:246
Octstr * query
Definition: http.h:248
#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:244
Octstr * host
Definition: http.h:243
void http_urlparse_destroy(HTTPURLParse *p)
Definition: http.c:1328
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void parse_dump(HTTPURLParse *p)
Definition: http.c:1344
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * url
Definition: http.h:241
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:247
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:245
HTTPURLParse * http_urlparse_create(void)
Definition: http.c:1309
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:242
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.