Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
octstr.h File Reference
#include <stdio.h>
#include <stdarg.h>
#include "list.h"

Go to the source code of this file.

Macros

#define octstr_create(cstr)   (Octstr*)gw_claim_area(octstr_create_real((cstr), __FILE__, __LINE__, __func__))
 
#define octstr_create_from_data(data, len)   (Octstr*)gw_claim_area(octstr_create_from_data_real((data), (len), __FILE__, __LINE__, __func__))
 
#define octstr_create_from_data_trace(data, len, file, line, func)   (Octstr*)gw_claim_area(octstr_create_from_data_real(data, len, file, line, func))
 
#define octstr_copy(ostr, from, len)   gw_claim_area(octstr_copy_real((ostr), (from), (len), __FILE__, __LINE__, __func__))
 
#define octstr_duplicate(ostr)   gw_claim_area(octstr_duplicate_real((ostr), __FILE__, __LINE__, __func__))
 
#define octstr_get_cstr(ostr)   (octstr_get_cstr_real(ostr, __FILE__, __LINE__, __func__))
 
#define octstr_dump(ostr, level, ...)   octstr_dump_real(ostr, level, GW_DEBUG, ##__VA_ARGS__)
 
#define octstr_format_valist(fmt, args)   gw_claim_area(octstr_format_valist_real(fmt, args))
 

Typedefs

typedef struct Octstr Octstr
 
typedef int(* octstr_func_t) (int)
 

Functions

void octstr_init (void)
 
void octstr_shutdown (void)
 
Octstroctstr_create_real (const char *cstr, const char *file, long line, const char *func)
 
Octstroctstr_create_from_data_real (const char *data, long len, const char *file, long line, const char *func)
 
Octstroctstr_imm (const char *cstr)
 
void octstr_destroy (Octstr *ostr)
 
void octstr_destroy_item (void *os)
 
long octstr_len (const Octstr *ostr)
 
Octstroctstr_copy_real (const Octstr *ostr, long from, long len, const char *file, long line, const char *func)
 
Octstroctstr_duplicate_real (const Octstr *ostr, const char *file, long line, const char *func)
 
Octstroctstr_cat (Octstr *ostr1, Octstr *ostr2)
 
int octstr_get_char (const Octstr *ostr, long pos)
 
void octstr_set_char (Octstr *ostr, long pos, int ch)
 
void octstr_get_many_chars (char *buf, Octstr *ostr, long pos, long len)
 
char * octstr_get_cstr_real (const Octstr *ostr, const char *file, long line, const char *func)
 
void octstr_append_from_hex (Octstr *ostr, char *hex)
 
void octstr_binary_to_hex (Octstr *ostr, int uppercase)
 
int octstr_hex_to_binary (Octstr *ostr)
 
void octstr_binary_to_base64 (Octstr *ostr)
 
void octstr_base64_to_binary (Octstr *ostr)
 
long octstr_parse_long (long *number, Octstr *ostr, long pos, int base)
 
long octstr_parse_double (double *number, Octstr *ostr, long pos)
 
int octstr_check_range (Octstr *ostr, long pos, long len, octstr_func_t filter)
 
void octstr_convert_range (Octstr *ostr, long pos, long len, octstr_func_t map)
 
void octstr_convert_printable (Octstr *ostr)
 
int octstr_compare (const Octstr *ostr1, const Octstr *ostr2)
 
int octstr_case_compare (const Octstr *ostr1, const Octstr *ostr2)
 
int octstr_ncompare (const Octstr *ostr1, const Octstr *ostr2, long n)
 
int octstr_str_compare (const Octstr *ostr1, const char *str)
 
int octstr_str_case_compare (const Octstr *ostr1, const char *str)
 
int octstr_str_ncompare (const Octstr *ostr, const char *str, long n)
 
int octstr_print (FILE *f, Octstr *ostr)
 
long octstr_search_char (const Octstr *ostr, int ch, long pos)
 
long octstr_rsearch_char (const Octstr *ostr, int ch, long pos)
 
long octstr_search_chars (const Octstr *ostr, const Octstr *chars, long pos)
 
long octstr_search (const Octstr *haystack, const Octstr *needle, long pos)
 
long octstr_case_search (const Octstr *haystack, const Octstr *needle, long pos)
 
long octstr_case_nsearch (const Octstr *haystack, const Octstr *needle, long pos, long n)
 
long octstr_str_search (const Octstr *haystack, const char *needle, long pos)
 
int octstr_pretty_print (FILE *f, Octstr *ostr)
 
int octstr_write_to_socket (int socket, Octstr *ostr)
 
long octstr_write_data (Octstr *ostr, int fd, long from)
 
int octstr_append_from_socket (Octstr *ostr, int socket)
 
void octstr_insert (Octstr *ostr1, const Octstr *ostr2, long pos)
 
void octstr_insert_data (Octstr *ostr, long pos, const char *data, long len)
 
void octstr_insert_char (Octstr *ostr, long pos, const char c)
 
void octstr_append_data (Octstr *ostr, const char *data, long len)
 
void octstr_append (Octstr *ostr1, const Octstr *ostr2)
 
void octstr_append_cstr (Octstr *ostr, const char *cstr)
 
void octstr_append_char (Octstr *ostr, int ch)
 
void octstr_truncate (Octstr *ostr, int new_len)
 
void octstr_strip_blanks (Octstr *ostr)
 
void octstr_strip_crlfs (Octstr *ostr)
 
void octstr_strip_nonalphanums (Octstr *ostr)
 
void octstr_shrink_blanks (Octstr *ostr)
 
void octstr_delete (Octstr *ostr1, long pos, long len)
 
Octstroctstr_read_file (const char *filename)
 
Octstroctstr_read_pipe (FILE *f)
 
Listoctstr_split_words (const Octstr *ostr)
 
Listoctstr_split (const Octstr *os, const Octstr *sep)
 
int octstr_item_match (void *item, void *pattern)
 
int octstr_item_case_match (void *item, void *pattern)
 
void octstr_dump_real (const Octstr *ostr, int level,...)
 
void octstr_dump_short (Octstr *ostr, int level, const char *name)
 
int octstr_url_decode (Octstr *ostr)
 
void octstr_url_encode (Octstr *ostr)
 
long octstr_get_bits (Octstr *ostr, long bitpos, int numbits)
 
void octstr_set_bits (Octstr *ostr, long bitpos, int numbits, unsigned long value)
 
void octstr_append_uintvar (Octstr *ostr, unsigned long value)
 
long octstr_extract_uintvar (Octstr *ostr, unsigned long *value, long pos)
 
void octstr_append_decimal (Octstr *ostr, long value)
 
Octstroctstr_format (const char *fmt,...)
 
Octstroctstr_format_valist_real (const char *fmt, va_list args)
 
void octstr_format_append (Octstr *os, const char *fmt,...)
 
unsigned long octstr_hash_key (Octstr *ostr)
 
int octstr_recode (Octstr *tocode, Octstr *fromcode, Octstr *orig)
 
void octstr_strip_char (Octstr *text, char ch)
 
int octstr_isnum (Octstr *ostr1)
 
void octstr_replace (Octstr *haystack, Octstr *needle, Octstr *repl)
 
void octstr_replace_first (Octstr *haystack, Octstr *needle, Octstr *repl)
 
int octstr_symbolize (Octstr *ostr)
 
void octstr_delete_matching (Octstr *haystack, Octstr *needle)
 
int octstr_is_all_hex (Octstr *os)
 
void octstr_convert_to_html_entities (Octstr *input)
 
void octstr_convert_from_html_entities (Octstr *input)
 

Macro Definition Documentation

#define octstr_copy (   ostr,
  from,
  len 
)    gw_claim_area(octstr_copy_real((ostr), (from), (len), __FILE__, __LINE__, __func__))

Definition at line 178 of file octstr.h.

Referenced by at2_extract_line(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_extract(), at2_read_pending_incoming_messages(), cfg_read(), cgw_read_op(), check_reversible(), check_variable_syntax(), client_read_status(), copy_until_assign(), copy_until_coma(), copy_until_nul(), data_sm_to_msg(), date_parse_http(), decode_type(), eat_string_parm(), extract_msgdata_part(), find_charset_encoding(), generic_parse_reply(), get_fields(), get_header_value(), get_mime_boundary(), get_msg_filename(), get_variable(), handle_dlr(), handle_operation(), http_get_header_parameter(), http_header_add_element(), http_header_get(), http_header_value(), httpd_serve(), msg_to_bb(), octstr_convert_from_html_entities(), octstr_split(), octstr_split_by_pos(), oisd_accept_delivery_report_message(), oisd_accept_message(), oisd_get_packet(), pack_challenge(), pack_credentials(), pack_warning(), packet_add_parm(), packet_encode_message(), packet_extract(), packet_get_parm(), parm_parse(), parse_attr_value(), parse_attribute(), parse_cgivars(), parse_charset(), parse_data(), parse_get_line(), parse_get_nul_string(), parse_get_octets(), parse_get_seperated_block(), parse_st_octet_string(), parse_string(), parse_url(), parse_xml_tag(), pass_field_name(), pass_field_value(), pdu_to_msg(), radius_authenticate_pdu(), read_line(), read_msg(), sema_submit_msg(), set_charset(), smsbox_req_handle(), soap_fetch_xml_data(), soap_format_xml(), split_headers(), unlocked_get(), unpack_tpis(), urltrans_fill_escape_codes(), wap_map_url(), wsp_cap_unpack_list(), wsp_strip_parameters(), wtp_pack_sar_result(), and wtp_unpack_wdp_datagram().

#define octstr_create (   cstr)    (Octstr*)gw_claim_area(octstr_create_real((cstr), __FILE__, __LINE__, __func__))

Definition at line 125 of file octstr.h.

Referenced by accept_escaped(), add_content_type(), add_push_application_id(), at2_check_sms_memory(), at2_close_device(), at2_convertpdu(), at2_encode7bituncompressed(), at2_encode8bituncompressed(), at2_flush_buffer(), at2_format_address_field(), at2_init_device(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), at2_read_modems(), at2_send_one_message(), at2_wait_line(), at2_wait_modem_command(), attr_dict_construct(), bb_alog_sms(), bb_print_status(), bb_smscconn_receive(), bb_smscconn_send_failed(), bb_smscconn_sent(), boxc_sent_pop(), boxc_sent_push(), boxc_status(), brunet_receive_sms(), brunet_send_sms(), build_response(), cgw_handle_op(), cgwop_create(), cgwop_tostr(), charset_gsm_to_utf8(), charset_utf8_to_gsm(), check_args(), check_comparisons(), check_data_content_type_header(), check_data_x_wap_application_id_header(), cimd2_submit_msg(), cimd_receive_msg(), cimd_submit_msg(), clickatell_receive_sms(), clickatell_send_sms(), client(), client_session(), client_thread(), conn_wrap_fd(), convert(), convert_content(), convert_q_value(), create_dlr_from_msg(), create_onetrans(), data_sm_to_msg(), date_format_http(), decode_binary_data(), deconvert_content(), delayed_http_reply(), describe_code(), dlr_add(), dlr_find(), emi2_handle_smscreq(), emimsg_create_reply(), emimsg_tostring(), encode_binary_data(), entity_create(), expand_file(), fix_boundary_element(), generic_get_field_map(), generic_parse_reply(), generic_receive_sms(), get_data(), get_msg_filename(), get_pattern(), get_variable(), get_x_kannel_from_xml(), gsm2number(), gw_netaddr_to_octstr(), handle_dlr(), handle_login(), handle_operation(), handle_pdu(), handle_split(), hash_create(), html_to_sms(), http_header_get(), http_header_get_content_type(), http_header_pack(), http_something_accepted(), http_thread(), httpd_add_smsc(), httpd_check_authorization(), httpd_check_status(), httpd_flush_dlr(), httpd_graceful_restart(), httpd_isolate(), httpd_loglevel(), httpd_reload_lists(), httpd_remove_message(), httpd_remove_smsc(), httpd_restart(), httpd_restart_smsc(), httpd_resume(), httpd_serve(), httpd_shutdown(), httpd_stop_smsc(), httpd_suspend(), init_bearerbox(), init_smsbox(), kannel_parse_reply(), kannel_receive_sms(), kannel_send_sms(), main(), main_connection_loop(), main_loop(), make_close_delimiter(), make_confirmedpush_pdu(), make_emi31(), make_emi60(), make_part_delimiter(), make_push_pdu(), make_resume_reply_pdu(), make_start_delimiter(), md5digest(), meta_data_merge(), meta_data_set_value(), meta_data_set_values(), meta_data_unpack(), mime_decompile(), mime_entity_dump_real(), mime_entity_to_octstr(), mime_something_to_entity(), msg_cb(), msg_pack(), msg_to_cgwop(), msg_to_emimsg(), msg_to_pdu(), normalize_charset(), numhash_create(), obey_request(), obey_request_thread(), octstr_append_from_hex(), octstr_cat(), octstr_copy_real(), octstr_format_valist_real(), octstr_read_file(), octstr_read_pipe(), ois_adjust_sm_text(), oisd_accept_message(), oisd_expand_gsm7(), oisd_shrink_gsm7(), oisd_submit_msg(), open_receiver(), open_transceiver(), open_transmitter(), operation_name(), ota_compile(), ota_pack_push_headers(), ota_pack_udh(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_7bit(), pack_accept(), pack_accept_charset(), pack_accept_language(), pack_appid_list(), pack_cache_control(), pack_challenge(), pack_content_disposition(), pack_content_range(), pack_credentials(), pack_pragma(), pack_range_value(), pack_server_address(), pack_udhdata(), pack_warning(), packet_add_int_parm(), packet_create(), packet_display_error(), packet_encode_message(), pap_convert_content(), parse_array_element(), parse_attribute(), parse_client_specifier(), parse_cookie(), parse_data_element(), parse_document(), parse_element(), parse_entities(), parse_fault_element(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_ota_syncsettings(), parse_param_element(), parse_params_element(), parse_rawmessage_to_msg(), parse_st_octet_string(), parse_struct_element(), parse_url(), parse_value_element(), pass_data_headers(), pass_extension_headers(), pass_optional_header(), pdu_to_msg(), prepend_catenation_udh(), push_content_create(), radius_acct_init(), radius_attr_pack(), radius_pdu_pack(), radius_type_convert(), randomize(), recover_absolute_uri(), reply_known_capabilities(), return_reply(), run_batch(), run_connects(), sema_decode_msg(), sema_encode_msg(), sema_receive_msg(), send_logoff(), send_messages(), send_post(), send_smpp_thread(), sendsms_thread(), server(), set_charset(), set_cookies(), setup_official_name(), si_compile(), simple_binary_create(), sl_compile(), smasi_pdu_pack(), smpp_emu_writer(), smpp_pdu_dump_line(), smpp_pdu_init(), smpp_pdu_pack(), sms_send(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_req_sendsms(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_start(), smsbox_thread(), smsc2_rout(), smsc2_status(), smsc_at2_create(), smsc_cgw_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_fake_create(), smsc_oisd_create(), smsc_open(), smsc_smasi_create(), smsc_soap_create(), smsc_wrapper_create(), soap_bouyg_content_attribute(), soap_create_map(), soap_fetch_xml_data(), soap_format_xml(), soap_map_xml_data(), soap_mobitai_content_attribute(), soap_msgdata_deps(), soap_o2o_dlrmask_smsc_yn_attribute(), soap_o2o_dlrmask_success_01_attribute(), soap_o2o_msgdata_attribute(), soap_parse_dlr(), soap_parse_mo(), soap_read_response(), soap_release_dependences(), soap_send_loop(), soap_server(), soap_write_date(), soap_xmlnode_get_octstr(), start_fetch(), start_request(), store_spool_save(), store_status(), store_to_dict(), store_uuid(), string_table_apply(), tokenize_date(), udp_addwdp_from_server(), udpc_create(), unpack_challenge(), unpack_parameter(), unpack_range_value(), unpack_warning_value(), urltrans_fill_escape_codes(), urltrans_get_pattern(), wap_map_url_config(), wap_map_url_config_device_home(), wap_msg_send(), wapbox_start(), wdp_create(), wml_binary_create(), wml_charsets(), wml_compile(), wsp_cap_pack_list(), wsp_encoding_version_to_string(), wsp_headers_pack(), wsp_pack_retry_after(), wsp_pack_separate_content_type(), wsp_pdu_pack(), wsp_unpack_integer_value(), wsp_unpack_version_value(), wsp_unpack_well_known_field(), wtp_pdu_pack(), xidris_parse_reply(), xidris_receive_sms(), and xmlrpc_doc_parse().

#define octstr_create_from_data_trace (   data,
  len,
  file,
  line,
  func 
)    (Octstr*)gw_claim_area(octstr_create_from_data_real(data, len, file, line, func))

Definition at line 136 of file octstr.h.

Referenced by octstr_copy_real(), octstr_create_real(), and octstr_duplicate_real().

#define octstr_duplicate (   ostr)    gw_claim_area(octstr_duplicate_real((ostr), __FILE__, __LINE__, __func__))

Definition at line 187 of file octstr.h.

Referenced by add_sar_transaction(), at2_format_address_field(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), at2_pdu_extract(), at2_read_modems(), at2_read_pending_incoming_messages(), at2_scan_for_telnet_escapes(), at2_send_one_message(), at2_wait_modem_command(), bb_alog_init(), bb_alog_sms(), begin_sar_result(), brunet_parse_reply(), brunet_receive_sms(), cfg_create(), cfg_get_configfile(), cfg_get_group_checksum(), cfg_get_group_name(), cfg_get_real(), cfg_read(), cfg_set(), cfgloc_create(), cgw_handle_op(), cgwop_add(), charset_to_utf8(), check_data_content_type_header(), check_data_x_wap_application_id_header(), check_reversible(), clickatell_parse_reply(), clickatell_receive_sms(), client_thread(), concat_handling_check_and_handle(), convert(), create_dlr_from_msg(), create_onetrans(), create_session(), create_tr_invoke_ind(), dict_keys(), dlr_add(), dlr_entry_duplicate(), dlr_find(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), emi2_handle_smscreq(), emimsg_duplicate(), eq_create_http_request(), eq_create_submit(), extract_base64(), extract_msgdata_part_by_coding(), find_translation(), generic_parse_reply(), generic_receive_sms(), get_pattern(), get_x_kannel_from_headers(), handle_bind_receiver(), handle_bind_transmitter(), handle_dlr(), handle_operation(), handle_pdu(), http_accept_request(), http_append_headers(), http_get_header_parameter(), http_header_duplicate(), http_header_find_all(), http_header_get(), http_header_get_content_type(), http_set_interface(), http_use_proxy(), httpd_serve(), identify_to_bearerbox(), indicate_confirmedpush(), indicate_push_disconnect(), init_configuration(), init_reroute(), init_smsbox_routes(), ip_allowed_by_user(), item_create(), kannel_parse_reply(), kannel_receive_sms(), kannel_send_sms(), main(), make_confirmed_push_request(), make_confirmedpush_pdu(), make_emi31(), make_emi60(), make_push_pdu(), make_push_request(), make_session_request(), make_unit_push_request(), meta_data_merge(), meta_data_set_value(), meta_data_set_values(), mime_entity_body(), mime_entity_duplicate(), mime_entity_set_body(), msg_cb(), msg_to_bb(), msg_to_cgwop(), msg_to_emimsg(), msg_to_pdu(), name(), normalize_charset(), number_to_string(), obey_request(), obey_request_thread(), octstr_recode(), open_connection(), open_receiver(), open_transceiver(), open_transmitter(), ota_pack_message(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_into_push_datagram(), pack_into_result_datagram(), pack_ip_datagram(), pack_md5(), pack_server_address(), pack_sms_datagram(), packet_add_hex_parm(), packet_encode_message(), pap_request_thread(), parm_parse(), parse2trans(), parse_address(), parse_address_value(), parse_attribute(), parse_bad_message_response_value(), parse_cgivars_for_password(), parse_cgivars_for_username(), parse_charset(), parse_element(), parse_get_rest(), parse_progress_note_value(), parse_push_message_value(), parse_push_response_value(), parse_quality_of_service_value(), parse_response_result_value(), parse_url(), parse_url_value(), parse_value(), pdu_to_msg(), proxy_thread(), proxy_unpack_credentials(), push_machine_create(), radius_acct_get_msisdn(), radius_authenticate_pdu(), remember_receiver(), request_confirmed_push(), request_push(), request_unit_push(), response(), response_push_message(), route_incoming_to_smsc(), route_msg(), run_batch(), sema_receive_msg(), send_message(), server(), server_create(), session_machine_create(), set_dlr_url(), set_group_name(), set_referer_url(), set_service_name(), set_smsbox_id(), set_smsc_id(), smpp_create(), sms_msgdata_len(), sms_receive(), sms_to_client(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_sendota_post(), smsc_at2_create(), smsc_smpp_create(), smsc_soap_create(), smscconn_create(), soap_msgdata_attribute(), soap_o2o_msgdata_attribute(), soap_parse_mo(), soap_release_dependences(), split_headers(), start_fetch(), store_file_init(), store_spool_init(), string_table_add_many(), udp_addwdp_from_client(), udp_addwdp_from_server(), unpack_credentials(), unpack_datagram(), unpack_invoke(), unpack_negative_ack(), unpack_result(), unpack_segmented_invoke(), update_tables(), url_result_thread(), urltrans_fill_escape_codes(), wap_addr_create(), wap_map_url(), wap_map_user(), wap_push_ppg_pushuser_authenticate(), wap_push_ppg_pushuser_dlr_url_get(), wap_push_ppg_pushuser_smsbox_id_get(), wap_push_ppg_pushuser_smsc_id_get(), wapme_smsproxy_parse_reply(), wdp_create(), wdp_msg2event(), wsp_cap_duplicate(), wtp_pack_invoke(), wtp_pack_result(), wtp_unpack_wdp_datagram(), xidris_parse_reply(), xidris_receive_sms(), xidris_send_sms(), xmlrpc_call_create(), xmlrpc_fault_create(), xmlrpc_parse_error(), xmlrpc_scalar_create(), and xmlrpc_scalar_print().

#define octstr_format_valist (   fmt,
  args 
)    gw_claim_area(octstr_format_valist_real(fmt, args))

Definition at line 693 of file octstr.h.

Referenced by octstr_format(), and octstr_format_append().

#define octstr_get_cstr (   ostr)    (octstr_get_cstr_real(ostr, __FILE__, __LINE__, __func__))

Definition at line 233 of file octstr.h.

Referenced by accept_boxc(), add_client_sdu_size(), add_dlr_mask(), add_dlr_url(), add_group(), add_msisdn(), add_network_info(), add_push_flag(), add_via(), add_x_wap_tod(), at2_check_sms_memory(), at2_close_device(), at2_decode7bituncompressed(), at2_detect_modem_type(), at2_detect_speed(), at2_device_thread(), at2_extract_line(), at2_format_address_field(), at2_init_device(), at2_login_device(), at2_open_device(), at2_open_device1(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), at2_pdu_extract(), at2_read_buffer(), at2_read_delete_message(), at2_read_modems(), at2_read_pending_incoming_messages(), at2_read_sms_memory(), at2_send_messages(), at2_send_one_message(), at2_set_message_storage(), at2_set_speed(), at2_shutdown_cb(), at2_start_cb(), at2_wait_modem_command(), at2_write(), at2_write_ctrlz(), at2_write_line(), authorise_username(), bb_alog_sms(), bb_print_status(), bb_reload_smsc_groups(), bb_remove_message(), bb_smscconn_receive(), boxc_receiver(), boxc_sender(), boxc_status(), brunet_init(), brunet_parse_reply(), brunet_receive_sms(), brunet_send_sms(), cfg_dump(), cfg_get_group_checksum(), cfg_get_real(), cfg_read(), cgw_handle_op(), cgw_listener(), cgw_open_listening_socket(), cgw_open_send_connection(), cgw_read_op(), challenge(), charset_convert(), charset_from_utf8(), charset_to_utf8(), check_application_headers(), check_reversible(), check_x_wap_application_id_header(), cid_matches(), cimd2_accept_delivery_report_message(), cimd2_accept_message(), cimd2_close_socket(), cimd2_destroy(), cimd2_get_packet(), cimd2_handle_request(), cimd2_login(), cimd2_logout(), cimd2_receive_msg(), cimd2_request(), cimd2_send_alive(), cimd2_send_response(), cimd2_shutdown_cb(), cimd2_start_cb(), cimd2_stop_cb(), cimd2_submit_msg(), cimd_submit_msg(), clear_sent(), clickatell_parse_reply(), clickatell_receive_sms(), clickatell_send_sms(), client(), client_create(), client_destroy(), client_read_status(), client_reset(), client_session(), client_thread(), concat_handling_check_and_handle(), concat_handling_clear_old_parts(), config_reload(), conn_open_tcp_nb_with_port(), conn_open_tcp_with_port(), conn_pool_get(), connect_to_bearerbox_real(), convert_addr_from_pdu(), convert_cimd2_to_gsm(), convert_content(), convert_wmlscript_to_wmlscriptc(), copy_until_assign(), copy_until_coma(), create_dlr_from_msg(), create_onetrans(), create_oneuser(), data_sm_to_msg(), date_parse_iso(), deconvert_content(), deduce_body_state(), delayed_http_reply(), dispatch(), dlr_add(), dlr_find(), dlr_init(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), do_queue_cleanup(), does_prefix_match(), dump_pdu(), emi2_handle_smscreq(), emi2_idleprocessing(), emi2_idletimeout_handling(), emi2_listener(), emi2_open_listening_socket(), emi2_receiver(), emi2_send_loop(), emi2_sender(), emimsg_send(), error_converting(), error_from_network_error_code(), error_requesting(), error_requesting_back(), expand_file(), expire_cookies(), fake_listener(), fake_open_connection(), field_count_op(), field_count_reply(), fill_message(), fix_boundary_element(), for_each_file(), generic_init(), generic_parse_reply(), generic_receive_sms(), generic_send_sms(), get_and_set_debugs(), get_connection(), get_cookies(), get_data(), get_fields(), get_header_value(), get_matching_translations(), get_msg_filename(), get_msg_surrogate(), get_pattern(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), grp_dump(), gw_accept(), handle_cancel(), handle_dlr(), handle_enquire(), handle_login(), handle_mo_dcs(), handle_operation(), handle_pdu(), handle_set(), handle_submit(), handle_submit_sm(), handle_transaction(), have_cookie(), header_is_called(), http_add_basic_auth(), http_header_combine(), http_header_mark_transformation(), http_header_quoted_string_len(), http_open_port_if(), http_queue_thread(), http_remove_hop_headers(), http_send_reply(), http_use_proxy(), httpadmin_run(), httpd_add_smsc(), httpd_loglevel(), httpd_remove_message(), httpd_remove_smsc(), httpd_restart_smsc(), httpd_stop_smsc(), httpsmsc_receiver(), httpsmsc_send(), httpsmsc_send_cb(), httpsmsc_shutdown(), init_batch(), init_bearerbox(), init_reroute(), init_smsbox(), init_smsbox_routes(), init_wapbox(), io_thread(), ip_allowed_by_user(), kannel_receive_sms(), kannel_send_sms(), main(), make_reply_headers(), md5(), md5digest(), meta_data_merge(), meta_data_unpack(), mime_decompile(), mime_entity_dump_real(), mime_something_to_entity(), msg_to_bb(), msg_to_emimsg(), msg_to_pdu(), my_dump(), normalize_charset(), normalize_number(), number_to_cstr(), numhash_create(), numhash_get_key(), obey_request(), obey_request_thread(), octstr_hash_key(), ois_adjust_sm_text(), ois_append_msisdn(), ois_append_sm_text(), ois_open_receiver(), oisd_accept_message(), oisd_close_socket(), oisd_destroy(), oisd_get_packet(), oisd_login(), oisd_receive_msg(), oisd_request(), oisd_send_delivery_request(), oisd_send_response(), oisd_shutdown_cb(), oisd_start_cb(), oisd_stop_cb(), oisd_submit_msg(), open_connection(), open_file(), open_receiver(), open_send_connection(), open_transceiver(), open_transmitter(), ota_compile(), ota_pack_message(), ota_pack_push_headers(), ota_tokenize_settings(), our_hash_func(), pack_content_disposition(), pack_content_range(), pack_credentials(), pack_known_header(), pack_range(), pack_warning(), packet_add_parm(), packet_check(), packet_check_can_receive(), packet_check_header(), packet_check_parameter(), packet_display_error(), packet_encode_message(), packet_extract(), pap_compile(), pap_request_thread(), parse_address(), parse_array_element(), parse_attribute(), parse_cookie(), parse_data_element(), parse_document(), parse_dump(), parse_element(), parse_fault_element(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_msg_to_rawmessage(), parse_ota_syncsettings(), parse_pap_value(), parse_param_element(), parse_params_element(), parse_struct_element(), parse_url(), parse_uuid(), parse_value_element(), parse_xml_tag(), pass_extension_headers(), pass_optional_header(), pdu_to_msg(), post_content_create(), proxy_add_authentication(), proxy_thread(), push_content_create(), push_headers_create(), radius_acct_get_msisdn(), radius_acct_init(), radius_type_convert(), read_from_box(), read_pdu(), read_test_ppg_config(), receive_push_reply(), receive_reply(), reconnect(), reload_bool(), reload_int(), rename_store(), report_versions(), return_reply(), route_incoming_to_boxc(), run_batch(), run_smsbox(), run_wapbox(), sema_encode_msg(), sema_msg_session_mt(), sema_receive_msg(), send_messages(), send_msg(), send_post(), send_request(), sendsms_thread(), server(), server_thread(), set_charset(), set_cookies(), shutdown_cb(), si_compile(), skip_until_after_colon(), sl_compile(), smasi_pdu_unpack(), smasi_thread(), smpp_pdu_dump_line(), smpp_pdu_init(), sms_charset_processing(), sms_receive(), sms_send(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_req_sendsms(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_thread(), smsbox_xmlrpc_post(), smsboxc_run(), smsc2_add_smsc(), smsc2_graceful_restart(), smsc2_reload_lists(), smsc2_remove_smsc(), smsc2_restart_smsc(), smsc2_rout(), smsc2_start(), smsc2_stop_smsc(), smsc_at2_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_http_create(), smsc_oisd_create(), smsc_open(), smsc_smasi_create(), smsc_smpp_create(), smsc_soap_create(), smscconn_create(), smscconn_send(), soap_add_msg_cb(), soap_client_init_query(), soap_convert_token(), soap_create_map(), soap_fetch_xml_data(), soap_format_xml(), soap_get_index(), soap_listener(), soap_map_xml_data(), soap_msgdata_attribute(), soap_msgdata_deps(), soap_o2o_msgdata_attribute(), soap_parse_dlr(), soap_parse_mo(), soap_parse_response(), soap_read_date(), soap_read_response(), soap_release_dependences(), soap_send_loop(), soap_server(), soap_server_start(), soap_server_stop(), soap_shutdown_cb(), soap_start_cb(), soap_stop_cb(), start_cb(), start_fetch(), status_cb(), store_file_init(), store_file_load(), store_spool_init(), store_spool_save(), store_uuid(), string_to_versioned_number(), tcpip_connect_nb_to_server_with_port(), tcpip_connect_to_server_with_port(), tell_fatal_error(), transform_message(), udp_addwdp_from_client(), udp_addwdp_from_server(), udp_create_address(), udp_get_ip(), udp_get_port(), udp_receiver(), udp_sender(), udp_sendto(), udp_start(), udpc_create(), unlocked_write(), update_table(), update_tables(), url_result_thread(), urltrans_fill_escape_codes(), version_report_string(), wait_for_ack(), wait_for_client(), wap_addr_create(), wap_addr_tuple_dump(), wap_map_url(), wap_push_ppg_pushuser_authenticate(), wap_push_ppg_pushuser_client_phone_number_acceptable(), wapme_smsproxy_init(), wapme_smsproxy_send_sms(), wml_compile(), wrapper_receiver(), wrapper_sender(), wrapper_shutdown(), wsp_headers_pack(), wsp_headers_unpack(), wsp_pack_application_header(), wsp_pack_date(), wsp_pack_integer_string(), wsp_pack_version_value(), wsp_unpack_app_header(), wsp_unpack_well_known_field(), xidris_init(), xidris_parse_reply(), xidris_receive_sms(), xidris_send_sms(), xml_error(), and xmlrpc_doc_parse().

Typedef Documentation

typedef struct Octstr Octstr

Definition at line 104 of file octstr.h.

typedef int(* octstr_func_t) (int)

Definition at line 295 of file octstr.h.

Function Documentation

void octstr_append ( Octstr ostr1,
const Octstr ostr2 
)

Definition at line 1502 of file octstr.c.

References gw_assert(), Octstr::len, and octstr_insert().

Referenced by add_part_header(), add_wsp_get(), append_crlf(), assembly_sar_event(), at2_init_device(), at2_pdu_encode(), at2_pdu_extract(), at2_wait_modem_command(), build_request(), build_response(), cfg_get_group_checksum(), cgw_handle_op(), cgwop_tostr(), challenge(), charset_gsm_to_utf8(), charset_utf8_to_gsm(), concat_handling_check_and_handle(), conn_write(), conn_write_withlen(), convert(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), emi2_handle_smscreq(), emimsg_tostring(), encode_binary_data(), expand_file(), get_pattern(), get_x_kannel_from_xml(), http_header_pack(), http_header_split_auth_value(), http_send_reply(), httpd_serve(), main(), make_close_delimiter(), make_multipart_value(), make_part_delimiter(), make_start_delimiter(), make_url(), mime_decompile(), mime_entity_to_octstr(), mime_something_to_entity(), msg_to_cgwop(), msg_to_emimsg(), obey_request(), octstr_append_from_hex(), octstr_format_append(), octstr_recode(), oisd_send_delivery_request(), oisd_shrink_gsm7(), ota_pack_push_headers(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_7bit(), pack_cache_control(), pack_md5(), pack_quoted_string(), pack_server_address(), pack_tpis(), packet_encode_message(), parse2trans(), pass_field_name(), pass_field_value(), proxy_unpack_credentials(), push_content_create(), radius_authenticate_pdu(), radius_type_convert(), read_body_until_eof(), read_chunked_body_data(), read_mime_headers(), read_some_headers(), recover_absolute_uri(), send_message(), set_cookies(), sms_split(), sms_to_client(), smsc2_status(), smsc_emi2_create(), soap_format_xml(), soap_msgdata_attribute(), soap_o2o_msgdata_attribute(), start_request(), unpack_cache_directive(), unpack_challenge(), unpack_credentials(), unpack_optional_q_value(), unpack_parameter(), unpack_warning_value(), urltrans_fill_escape_codes(), wap_map_url(), wml_charsets(), wsp_cap_pack_list(), wsp_pack_quoted_text(), wsp_pack_text(), wsp_pack_value(), xidris_send_sms(), and xmlrpc_print_array().

1503 {
1504  gw_assert(ostr1 != NULL);
1505  octstr_insert(ostr1, ostr2, ostr1->len);
1506 }
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1301
gw_assert(wtls_machine->packet_to_send!=NULL)
long len
Definition: octstr.c:121
void octstr_append_char ( Octstr ostr,
int  ch 
)

Definition at line 1515 of file octstr.c.

References gw_assert(), Octstr::len, and octstr_insert_data().

Referenced by add_wsp_disconnect(), add_wsp_get(), append_encoded_integer(), at2_convertpdu(), at2_decode7bituncompressed(), at2_encode7bituncompressed(), at2_encode8bituncompressed(), at2_format_address_field(), at2_init_device(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), cgw_handle_op(), cgwop_tostr(), charset_gsm_to_utf8(), charset_utf8_to_gsm(), convert_html_entity(), convert_q_value(), decode_binary_data(), emi2_handle_smscreq(), emimsg_tostring(), encode_binary_data(), get_pattern(), gsm2number(), html_to_sms(), http_header_split_auth_value(), httpsmsc_receiver(), main(), msg_to_emimsg(), oisd_expand_gsm7(), oisd_send_delivery_request(), oisd_send_response(), oisd_shrink_gsm7(), ota_tokenize_bookmarks(), ota_tokenize_settings(), output_char(), output_st_char(), output_variable(), pack_7bit(), pack_challenge(), pack_credentials(), pack_md5(), pack_parameter(), pack_quoted_string(), pack_range_value(), pack_server_address(), packet_encode_message(), parse2trans(), parse_value(), parse_variable(), prepend_catenation_udh(), proxy_unpack_credentials(), randomize(), recover_absolute_uri(), reply_known_capabilities(), set_cookies(), smasi_pdu_pack(), sms_to_client(), smsc_emi2_create(), soap_format_xml(), string_table_apply(), string_table_output(), tokenize_date(), unpack_cache_directive(), unpack_challenge(), unpack_credentials(), unpack_parameter(), unpack_range_value(), unpack_warning_value(), urltrans_fill_escape_codes(), wml_binary_output(), wml_charsets(), wsp_cap_pack_list(), wsp_pack_long_integer(), wsp_pack_quoted_text(), wsp_pack_retry_after(), wsp_pack_short_integer(), wsp_pack_text(), wsp_pack_value(), and wsp_unpack_version_value().

1516 {
1517  unsigned char c = ch;
1518 
1519  gw_assert(ch >= 0);
1520  gw_assert(ch <= UCHAR_MAX);
1521  octstr_insert_data(ostr, ostr->len, &c, 1);
1522 }
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1459
gw_assert(wtls_machine->packet_to_send!=NULL)
long len
Definition: octstr.c:121
void octstr_append_data ( Octstr ostr,
const char *  data,
long  len 
)

Definition at line 1495 of file octstr.c.

References gw_assert(), Octstr::len, and octstr_insert_data().

Referenced by add_wsp_connect(), append_integer(), at2_read_buffer(), charset_convert(), client_session(), conn_write_data(), conn_write_withlen(), convert(), gen_data(), get_pattern(), main(), octstr_append_from_socket(), octstr_append_uintvar(), octstr_format_valist_real(), octstr_read_pipe(), radius_authenticate_pdu(), read_data(), read_line(), send_post(), set_charset(), unlocked_read(), and wap_msg_send().

1496 {
1497  gw_assert(ostr != NULL);
1498  octstr_insert_data(ostr, ostr->len, data, len);
1499 }
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1459
gw_assert(wtls_machine->packet_to_send!=NULL)
long len
Definition: octstr.c:121
void octstr_append_decimal ( Octstr ostr,
long  value 
)

Definition at line 1974 of file octstr.c.

References octstr_append_cstr().

Referenced by cgw_handle_op(), cgwop_create(), convert(), get_pattern(), msg_to_emimsg(), pack_server_address(), smsc_emi2_create(), unpack_parameter(), unpack_range_value(), urltrans_fill_escape_codes(), wsp_unpack_integer_value(), wsp_unpack_version_value(), and wsp_unpack_well_known_field().

1975 {
1976  char tmp[128];
1977 
1978  sprintf(tmp, "%ld", value);
1979  octstr_append_cstr(ostr, tmp);
1980 }
void octstr_append_cstr(Octstr *ostr, const char *cstr)
Definition: octstr.c:1509
void octstr_append_from_hex ( Octstr ostr,
char *  hex 
)

Definition at line 449 of file octstr.c.

References gw_assert(), Octstr::immutable, octstr_append(), octstr_create, octstr_destroy(), octstr_hex_to_binary(), and seems_valid.

Referenced by cimd_submit_msg(), client_thread(), main(), ota_pack_push_headers(), ota_pack_udh(), ota_tokenize_bookmarks(), and ota_tokenize_settings().

450 {
451  Octstr *output;
452 
453  seems_valid(ostr);
454  gw_assert(!ostr->immutable);
455 
456  output = octstr_create(hex);
457  octstr_hex_to_binary(output);
458  octstr_append(ostr, output);
459  octstr_destroy(output);
460 }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1502
int immutable
Definition: octstr.c:123
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_hex_to_binary(Octstr *ostr)
Definition: octstr.c:492
int octstr_append_from_socket ( Octstr ostr,
int  socket 
)

Definition at line 1278 of file octstr.c.

References error(), gw_assert(), Octstr::immutable, octstr_append_data(), and seems_valid.

Referenced by cimd2_get_packet(), cimd2_receive_msg(), oisd_get_packet(), and oisd_receive_msg().

1279 {
1280  unsigned char buf[4096];
1281  int len;
1282 
1283  seems_valid(ostr);
1284  gw_assert(!ostr->immutable);
1285 
1286 again:
1287  len = recv(socket, buf, sizeof(buf), 0);
1288  if (len < 0 && errno == EINTR)
1289  goto again;
1290 
1291  if (len < 0) {
1292  error(errno, "Could not read from socket %d", socket);
1293  return -1;
1294  }
1295 
1296  octstr_append_data(ostr, buf, len);
1297  return len;
1298 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1495
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
void octstr_append_uintvar ( Octstr ostr,
unsigned long  value 
)

Definition at line 1929 of file octstr.c.

References octstr_append_data(), and start.

Referenced by add_wsp_disconnect(), add_wsp_get(), ota_pack_push_headers(), output_variable(), pack_content_range(), pack_qvalue(), pack_range_value(), parse_attribute(), parse_element(), reply_known_capabilities(), simple_binary_output(), string_table_apply(), wml_binary_output(), wsp_cap_pack_list(), and wsp_pack_value().

1930 {
1931  /* A uintvar is defined to be up to 32 bits large, so it will
1932  * fit in 5 octets. */
1933  unsigned char octets[5];
1934  int i;
1935  int start;
1936 
1937  /* Handle last byte separately; it has no continuation bit,
1938  * and must be encoded even if value is 0. */
1939  octets[4] = value & 0x7f;
1940  value >>= 7;
1941 
1942  for (i = 3; value > 0 && i >= 0; i--) {
1943  octets[i] = 0x80 | (value & 0x7f);
1944  value >>= 7;
1945  }
1946  start = i + 1;
1947 
1948  octstr_append_data(ostr, octets + start, 5 - start);
1949 }
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1495
static int start
void octstr_base64_to_binary ( Octstr ostr)

Definition at line 661 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, seems_valid, and warning().

Referenced by extract_base64(), pack_credentials(), pack_md5(), response(), and soap_msgdata_deps().

662 {
663  long triplet;
664  long pos, len;
665  long to;
666  int quadpos = 0;
667  int warned = 0;
668  unsigned char *data;
669 
670  seems_valid(ostr);
671  gw_assert(!ostr->immutable);
672 
673  len = ostr->len;
674  data = ostr->data;
675 
676  if (len == 0)
677  return;
678 
679  to = 0;
680  triplet = 0;
681  quadpos = 0;
682  for (pos = 0; pos < len; pos++) {
683  int c = data[pos];
684  int sixbits;
685 
686  if (c >= 'A' && c <= 'Z') {
687  sixbits = c - 'A';
688  } else if (c >= 'a' && c <= 'z') {
689  sixbits = 26 + c - 'a';
690  } else if (c >= '0' && c <= '9') {
691  sixbits = 52 + c - '0';
692  } else if (c == '+') {
693  sixbits = 62;
694  } else if (c == '/') {
695  sixbits = 63;
696  } else if (c == '=') {
697  /* These can only occur at the end of encoded
698  * text. RFC 2045 says we can assume it really
699  * is the end. */
700  break;
701  } else if (isspace(c)) {
702  /* skip whitespace */
703  continue;
704  } else {
705  if (!warned) {
706  warning(0, "Unusual characters in base64 "
707  "encoded text.");
708  warned = 1;
709  }
710  continue;
711  }
712 
713  triplet = (triplet << 6) | sixbits;
714  quadpos++;
715 
716  if (quadpos == 4) {
717  data[to++] = (triplet >> 16) & 0xff;
718  data[to++] = (triplet >> 8) & 0xff;
719  data[to++] = triplet & 0xff;
720  quadpos = 0;
721  }
722  }
723 
724  /* Deal with leftover octets */
725  switch (quadpos) {
726  case 0:
727  break;
728  case 3: /* triplet has 18 bits, we want the first 16 */
729  data[to++] = (triplet >> 10) & 0xff;
730  data[to++] = (triplet >> 2) & 0xff;
731  break;
732  case 2: /* triplet has 12 bits, we want the first 8 */
733  data[to++] = (triplet >> 4) & 0xff;
734  break;
735  case 1:
736  warning(0, "Bad padding in base64 encoded text.");
737  break;
738  }
739 
740  ostr->len = to;
741  data[to] = '\0';
742 
743  seems_valid(ostr);
744 }
void warning(int err, const char *fmt,...)
Definition: log.c:624
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_binary_to_base64 ( Octstr ostr)

Definition at line 540 of file octstr.c.

References Octstr::data, from, gw_assert(), Octstr::immutable, Octstr::len, lines, octstr_grow(), octstr_imm(), octstr_insert(), and seems_valid.

Referenced by http_add_basic_auth(), proxy_add_authentication(), soap_o2o_msgdata_attribute(), transfer_encode(), unpack_credentials(), and wsp_unpack_well_known_field().

541 {
542  static const unsigned char base64[64] =
543  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
544  long triplets;
545  long lines;
546  long orig_len;
547  unsigned char *data;
548  long from, to;
549  int left_on_line;
550 
551  seems_valid(ostr);
552  gw_assert(!ostr->immutable);
553 
554  if (ostr->len == 0) {
555  /* Always terminate with CR LF */
556  octstr_insert(ostr, octstr_imm("\015\012"), 0);
557  return;
558  }
559 
560  /* The lines must be 76 characters each (or less), and each
561  * triplet will expand to 4 characters, so we can fit 19
562  * triplets on one line. We need a CR LF after each line,
563  * which will add 2 octets per 19 triplets (rounded up). */
564  triplets = (ostr->len + 2) / 3; /* round up */
565  lines = (triplets + 18) / 19;
566 
567  octstr_grow(ostr, triplets * 4 + lines * 2);
568  orig_len = ostr->len;
569  data = ostr->data;
570 
571  ostr->len = triplets * 4 + lines * 2;
572  data[ostr->len] = '\0';
573 
574  /* This function works back-to-front, so that encoded data will
575  * not overwrite source data.
576  * from points to the start of the last triplet (which may be
577  * an odd-sized one), and to points to the start of where the
578  * last quad should go. */
579  from = (triplets - 1) * 3;
580  to = (triplets - 1) * 4 + (lines - 1) * 2;
581 
582  /* First write the CR LF after the last quad */
583  data[to + 5] = 10; /* LF */
584  data[to + 4] = 13; /* CR */
585  left_on_line = triplets - ((lines - 1) * 19);
586 
587  /* base64 encoding is in 3-octet units. To handle leftover
588  * octets, conceptually we have to zero-pad up to the next
589  * 6-bit unit, and pad with '=' characters for missing 6-bit
590  * units.
591  * We do it by first completing the first triplet with
592  * zero-octets, and after the loop replacing some of the
593  * result characters with '=' characters.
594  * There is enough room for this, because even with a 1 or 2
595  * octet source string, space for four octets of output
596  * will be reserved.
597  */
598  switch (orig_len % 3) {
599  case 0:
600  break;
601  case 1:
602  data[orig_len] = 0;
603  data[orig_len + 1] = 0;
604  break;
605  case 2:
606  data[orig_len + 1] = 0;
607  break;
608  }
609 
610  /* Now we only have perfect triplets. */
611  while (from >= 0) {
612  long whole_triplet;
613 
614  /* Add a newline, if necessary */
615  if (left_on_line == 0) {
616  to -= 2;
617  data[to + 5] = 10; /* LF */
618  data[to + 4] = 13; /* CR */
619  left_on_line = 19;
620  }
621 
622  whole_triplet = (data[from] << 16) |
623  (data[from + 1] << 8) |
624  data[from + 2];
625  data[to + 3] = base64[whole_triplet % 64];
626  data[to + 2] = base64[(whole_triplet >> 6) % 64];
627  data[to + 1] = base64[(whole_triplet >> 12) % 64];
628  data[to] = base64[(whole_triplet >> 18) % 64];
629 
630  to -= 4;
631  from -= 3;
632  left_on_line--;
633  }
634 
635  gw_assert(left_on_line == 0);
636  gw_assert(from == -3);
637  gw_assert(to == -4);
638 
639  /* Insert padding characters in the last quad. Remember that
640  * there is a CR LF between the last quad and the end of the
641  * string. */
642  switch (orig_len % 3) {
643  case 0:
644  break;
645  case 1:
646  gw_assert(data[ostr->len - 3] == 'A');
647  gw_assert(data[ostr->len - 4] == 'A');
648  data[ostr->len - 3] = '=';
649  data[ostr->len - 4] = '=';
650  break;
651  case 2:
652  gw_assert(data[ostr->len - 3] == 'A');
653  data[ostr->len - 3] = '=';
654  break;
655  }
656 
657  seems_valid(ostr);
658 }
static List * lines
Definition: mtbatch.c:88
static Octstr * from
Definition: mtbatch.c:95
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1301
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_binary_to_hex ( Octstr ostr,
int  uppercase 
)

Definition at line 463 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, octstr_grow(), and seems_valid.

Referenced by at2_scan_for_telnet_escapes(), bb_alog_sms(), convert(), dlr_spool_add(), get_pattern(), kannel_send_sms(), main(), make_emi60(), msg_to_cgwop(), msg_to_emimsg(), ota_pack_push_headers(), our_hash_func(), pack_7bit(), packet_add_hex_parm(), soap_msgdata_attribute(), and urltrans_fill_escape_codes().

464 {
465  unsigned char *hexits;
466  long i, tmp;
467 
468  seems_valid(ostr);
469  gw_assert(!ostr->immutable);
470  if (ostr->len == 0)
471  return;
472 
473  hexits = uppercase ? "0123456789ABCDEF" : "0123456789abcdef";
474  octstr_grow(ostr, ostr->len * 2);
475 
476  /* In-place modification must be done back-to-front to avoid
477  * overwriting the data while we read it. Even the order of
478  * the two assignments is important, to get i == 0 right. */
479  for (i = ostr->len - 1; i >= 0; i--) {
480  tmp = i << 1; /* tmp = i * 2; */
481  ostr->data[tmp + 1] = hexits[ostr->data[i] & 0xf];
482  ostr->data[tmp] = hexits[ostr->data[i] >> 4];
483  }
484 
485  ostr->len = ostr->len * 2;
486  ostr->data[ostr->len] = '\0';
487 
488  seems_valid(ostr);
489 }
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_case_compare ( const Octstr ostr1,
const Octstr ostr2 
)

Definition at line 901 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid.

Referenced by brunet_parse_reply(), cfg_get_bool(), check_comparisons(), get_x_kannel_from_headers(), handle_transaction(), http_get_header_parameter(), http_header_pack(), http_header_value(), init_bearerbox(), init_smsbox(), init_wapbox(), kannel_parse_reply(), normalize_charset(), octstr_item_case_match(), octstr_recode(), ota_pack_push_headers(), ota_pack_udh(), pack_challenge(), pack_credentials(), pack_pragma(), pap_get_content(), parse_array_element(), parse_attribute(), parse_bearer(), parse_client_specifier(), parse_data_element(), parse_delivery_method(), parse_document(), parse_element(), parse_fault_element(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_network(), parse_ota_syncsettings(), parse_param_element(), parse_params_element(), parse_priority(), parse_requirement(), parse_state(), parse_struct_element(), parse_value_element(), qualifiers(), select_bearer_network(), set_any_value(), smsbox_req_handle(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_xmlrpc_post(), smsc_http_create(), soap_msgdata_deps(), string_to_number(), string_to_versioned_number(), url_result_thread(), uses_gsm_msisdn_address(), uses_ipv4_address(), uses_ipv6_address(), wap_map_url(), wina_bearer_identifier(), and xidris_parse_reply().

902 {
903  int c1, c2;
904  long i, len;
905 
906  seems_valid(os1);
907  seems_valid(os2);
908 
909  if (os1->len < os2->len)
910  len = os1->len;
911  else
912  len = os2->len;
913 
914  if (len == 0) {
915  if (os1->len == 0 && os2->len > 0)
916  return -1;
917  if (os1->len > 0 && os2->len == 0)
918  return 1;
919  return 0;
920  }
921 
922  c1 = c2 = 0;
923  for (i = 0; i < len; ++i) {
924  c1 = toupper(os1->data[i]);
925  c2 = toupper(os2->data[i]);
926  if (c1 != c2)
927  break;
928  }
929 
930  if (i == len) {
931  if (i == os1->len && i == os2->len)
932  return 0;
933  if (i == os1->len)
934  return -1;
935  return 1;
936  } else {
937  /*
938  c1 = toupper(os1->data[i]);
939  c2 = toupper(os2->data[i]);
940  */
941  if (c1 < c2)
942  return -1;
943  if (c1 == c2)
944  return 0;
945  return 1;
946  }
947 }
#define seems_valid(ostr)
Definition: octstr.c:169
long octstr_case_nsearch ( const Octstr haystack,
const Octstr needle,
long  pos,
long  n 
)

Definition at line 1127 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by check_control_content_type_header(), check_data_content_type_header(), check_data_x_wap_application_id_header(), drop_extension_headers(), drop_optional_header(), pass_extension_headers(), and pass_optional_header().

1128 {
1129  long i, j;
1130  int c1, c2;
1131 
1132  seems_valid(haystack);
1133  seems_valid(needle);
1134  gw_assert(pos >= 0);
1135 
1136  /* Always "find" an empty string */
1137  if (needle->len == 0)
1138  return 0;
1139 
1140  for (i = pos; i <= haystack->len - needle->len && i < n; ++i) {
1141  for (j = 0; j < needle->len && j < n; ++j) {
1142  c1 = toupper(haystack->data[i + j]);
1143  c2 = toupper(needle->data[j]);
1144  if (c1 != c2)
1145  break;
1146  }
1147  if (j == needle->len)
1148  return i;
1149  }
1150 
1151  return -1;
1152 }
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
long octstr_case_search ( const Octstr haystack,
const Octstr needle,
long  pos 
)

Definition at line 1100 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by check_control_content_type_header(), drop_extension_headers(), get_mime_boundary(), http_something_accepted(), parse_appid_header(), parse_url(), strip_prefix_and_suffix(), and type_is().

1101 {
1102  long i, j;
1103  int c1, c2;
1104 
1105  seems_valid(haystack);
1106  seems_valid(needle);
1107  gw_assert(pos >= 0);
1108 
1109  /* Always "find" an empty string */
1110  if (needle->len == 0)
1111  return 0;
1112 
1113  for (i = pos; i <= haystack->len - needle->len; ++i) {
1114  for (j = 0; j < needle->len; ++j) {
1115  c1 = toupper(haystack->data[i + j]);
1116  c2 = toupper(needle->data[j]);
1117  if (c1 != c2)
1118  break;
1119  }
1120  if (j == needle->len)
1121  return i;
1122  }
1123 
1124  return -1;
1125 }
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
Octstr* octstr_cat ( Octstr ostr1,
Octstr ostr2 
)

Definition at line 381 of file octstr.c.

References Octstr::data, Octstr::len, octstr_create, seems_valid, and Octstr::size.

382 {
383  Octstr *ostr;
384 
385  seems_valid(ostr1);
386  seems_valid(ostr2);
387 
388  ostr = octstr_create("");
389  ostr->len = ostr1->len + ostr2->len;
390  ostr->size = ostr->len + 1;
391  ostr->data = gw_malloc(ostr->size);
392 
393  if (ostr1->len > 0)
394  memcpy(ostr->data, ostr1->data, ostr1->len);
395  if (ostr2->len > 0)
396  memcpy(ostr->data + ostr1->len, ostr2->data, ostr2->len);
397  ostr->data[ostr->len] = '\0';
398 
399  seems_valid(ostr);
400  return ostr;
401 }
long size
Definition: octstr.c:122
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_check_range ( Octstr ostr,
long  pos,
long  len,
octstr_func_t  filter 
)

Definition at line 812 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by convert_addr_from_pdu(), get_originator_type(), handle_dlr(), handle_pdu(), is_token(), msg_to_cgwop(), msg_to_emimsg(), msg_to_pdu(), octstr_hex_to_binary(), octstr_symbolize(), oisd_send_delivery_request(), pack_parameter(), packet_add_address_parm(), packet_check(), packet_check_header(), packet_check_parameter(), packet_encode_message(), parm_valid_address(), and run_batch().

814 {
815  long end = pos + len;
816 
817  seems_valid(ostr);
818  gw_assert(len >= 0);
819 
820  if (pos >= ostr->len)
821  return 1;
822  if (end > ostr->len)
823  end = ostr->len;
824 
825  for ( ; pos < end; pos++) {
826  if (!filter(ostr->data[pos]))
827  return 0;
828  }
829 
830  return 1;
831 }
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_compare ( const Octstr ostr1,
const Octstr ostr2 
)

Definition at line 869 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid.

Referenced by add_connection_header(), add_content_transfer_encoding_type(), add_content_type(), add_delimiter(), add_push_application_id(), at2_read_modems(), at2_read_pending_incoming_messages(), at2_send_one_message(), authorise_username(), boxc_receiver(), brunet_receive_sms(), cgw_read_op(), cgwop_get(), charset_to_utf8(), check_comparisons(), check_do_elements(), check_reversible(), cid_matches(), clickatell_parse_body(), client_thread(), cmp_conn_grp_checksum(), cmp_conn_grp_id(), cmp_rout_grp_checksum(), cmp_route(), content_transformable(), dlr_init(), dlr_mem_entry_match(), generic_receive_sms(), handle_dlr(), have_cookie(), httpd_check_authorization(), init_bearerbox(), init_smsbox(), init_wapbox(), ip_allowed_by_ppg(), ip_allowed_by_user(), item_has_key(), kannel_receive_sms(), main(), meta_data_merge(), mime_something_to_entity(), msg_to_bb(), my_cmp(), my_sort_cmp(), name(), obey_request_thread(), octstr_cmp_cb(), octstr_item_match(), octstr_sort_cb(), ota_tokenize_settings(), pack_appid_list(), packet_encode_message(), pap_convert_content(), pap_request_thread(), parse2trans(), parse_address_value(), parse_attr_value(), parse_attribute(), parse_bad_message_response_value(), parse_code(), parse_document(), parse_element(), parse_pap_value(), parse_progress_note_value(), parse_push_message_value(), parse_push_response_value(), parse_quality_of_service_value(), parse_request_line(), parse_response_result_value(), parse_url(), password_matches(), proxy_used_for_host(), push_has_pi_push_id(), radius_authenticate_pdu(), remember_receiver(), return_reply(), sendsms_thread(), session_has_addr(), session_has_pi_client_address(), set_any_value(), set_attribute_value(), smsbox_req_sendota(), smsc2_add_smsc(), smsc2_find(), smsc2_restart_smsc(), smsc_at2_create(), smsc_open(), smscconn_create(), soap_get_index(), soap_server(), start_fetch(), string_table_add(), string_table_apply(), string_table_sort_list(), test_header_combine(), transfer_encode(), udp_addwdp(), udp_receiver(), udpc_find_mapping(), update_table(), update_tables(), urltrans_find_username(), user_find_by_username(), wap_event_accept_or_create(), wap_map_user(), wildcarded_ip_found(), wsp_cap_get_data(), wsp_encoding_string_to_version(), and xidris_receive_sms().

870 {
871  int ret;
872  long len;
873 
874  seems_valid(ostr1);
875  seems_valid(ostr2);
876 
877  if (ostr1->len < ostr2->len)
878  len = ostr1->len;
879  else
880  len = ostr2->len;
881 
882  if (len == 0) {
883  if (ostr1->len == 0 && ostr2->len > 0)
884  return -1;
885  if (ostr1->len > 0 && ostr2->len == 0)
886  return 1;
887  return 0;
888  }
889 
890  ret = memcmp(ostr1->data, ostr2->data, len);
891  if (ret == 0) {
892  if (ostr1->len < ostr2->len)
893  ret = -1;
894  else if (ostr1->len > ostr2->len)
895  ret = 1;
896  }
897  return ret;
898 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_convert_from_html_entities ( Octstr input)

Definition at line 2802 of file octstr.c.

References octstr_copy, octstr_delete(), octstr_destroy(), octstr_find_entity(), octstr_insert_char(), and octstr_search_char().

2803 {
2804  int startpos = 0, endpos;
2805  int entity;
2806  Octstr *match;
2807 
2808  while ((startpos = octstr_search_char(input, '&', startpos)) != -1) {
2809  endpos = octstr_search_char(input, ';', startpos + 1);
2810  if (endpos >= 0) {
2811  match = octstr_copy(input, startpos + 1, endpos - startpos - 1);
2812  entity = octstr_find_entity(match, 0, 0);
2813  if (entity >= 0) {
2814  octstr_delete(input, startpos, endpos - startpos + 1);
2815  octstr_insert_char(input, startpos, entity);
2816  }
2817  octstr_destroy(match);
2818  }
2819  startpos++;
2820  }
2821 }
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1010
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
void octstr_insert_char(Octstr *ostr, long pos, const char c)
Definition: octstr.c:1479
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
static int octstr_find_entity(Octstr *input, int startfind, int endfind)
Definition: octstr.c:2758
Definition: octstr.c:118
void octstr_convert_printable ( Octstr ostr)

Definition at line 862 of file octstr.c.

References Octstr::len, make_printable(), and octstr_convert_range().

Referenced by bb_alog_sms(), and get_pattern().

863 {
864  octstr_convert_range(ostr, 0, ostr->len, make_printable);
865 }
void octstr_convert_range(Octstr *ostr, long pos, long len, octstr_func_t map)
Definition: octstr.c:834
static int make_printable(int c)
Definition: octstr.c:856
long len
Definition: octstr.c:121
void octstr_convert_range ( Octstr ostr,
long  pos,
long  len,
octstr_func_t  map 
)

Definition at line 834 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, and seems_valid.

Referenced by check_variable_syntax(), octstr_convert_printable(), parse_charset(), and parse_constant().

836 {
837  long end = pos + len;
838 
839  seems_valid(ostr);
840  gw_assert(!ostr->immutable);
841  gw_assert(len >= 0);
842 
843  if (pos >= ostr->len)
844  return;
845  if (end > ostr->len)
846  end = ostr->len;
847 
848  for ( ; pos < end; pos++) {
849  ostr->data[pos] = map(ostr->data[pos]);
850  }
851 
852  seems_valid(ostr);
853 }
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_convert_to_html_entities ( Octstr input)

Definition at line 2736 of file octstr.c.

References octstr_get_char(), and octstr_len().

Referenced by soap_msgdata_attribute(), soap_o2o_msgdata_attribute(), and xmlrpc_scalar_print().

2737 {
2738  int i;
2739 
2740  for (i = 0; i < octstr_len(input); ++i) {
2741  switch (octstr_get_char(input, i)) {
2742 #define ENTITY(a,b) \
2743  case a: \
2744  octstr_delete(input, i, 1); \
2745  octstr_insert(input, octstr_imm("&" b ";"), i); \
2746  i += sizeof(b); break;
2747 #include "gwlib/html-entities.def"
2748 #undef ENTITY
2749  }
2750  }
2751 }
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
Octstr* octstr_copy_real ( const Octstr ostr,
long  from,
long  len,
const char *  file,
long  line,
const char *  func 
)

Definition at line 349 of file octstr.c.

References Octstr::data, from, gw_assert(), Octstr::len, octstr_create, octstr_create_from_data_trace, and seems_valid_real().

Referenced by http_header_find_first_real().

351 {
352  if (ostr == NULL)
353  return octstr_create("");
354 
355  seems_valid_real(ostr, file, line, func);
356  gw_assert(from >= 0);
357  gw_assert(len >= 0);
358 
359  if (from >= ostr->len)
360  return octstr_create("");
361 
362  if (len > ostr->len - from)
363  len = ostr->len - from;
364 
365  return octstr_create_from_data_trace(ostr->data + from, len, file,
366  line, func);
367 }
static void seems_valid_real(const Octstr *ostr, const char *filename, long lineno, const char *function)
Definition: octstr.c:2543
FILE * file
Definition: log.c:133
static Octstr * from
Definition: mtbatch.c:95
#define octstr_create_from_data_trace(data, len, file, line, func)
Definition: octstr.h:136
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
Octstr* octstr_create_from_data_real ( const char *  data,
long  len,
const char *  file,
long  line,
const char *  func 
)

Definition at line 248 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, seems_valid, and Octstr::size.

250 {
251  Octstr *ostr;
252 
253  gw_assert(len >= 0);
254  if (data == NULL)
255  gw_assert(len == 0);
256 
257  /* if gw_assert is disabled just return NULL
258  * and caller will check for NULL or just crash.
259  */
260  if (len < 0 || (data == NULL && len != 0))
261  return NULL;
262 
263  ostr = gw_malloc_trace(sizeof(*ostr), file, line, func);
264  if (len == 0) {
265  ostr->len = 0;
266  ostr->size = 0;
267  ostr->data = NULL;
268  } else {
269  ostr->len = len;
270  ostr->size = len + 1;
271  ostr->data = gw_malloc_trace(ostr->size, file, line, func);
272  memcpy(ostr->data, data, len);
273  ostr->data[len] = '\0';
274  }
275  ostr->immutable = 0;
276  seems_valid(ostr);
277  return ostr;
278 }
FILE * file
Definition: log.c:133
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
Octstr* octstr_create_real ( const char *  cstr,
const char *  file,
long  line,
const char *  func 
)

Definition at line 241 of file octstr.c.

References gw_assert(), and octstr_create_from_data_trace.

243 {
244  gw_assert(cstr != NULL);
245  return octstr_create_from_data_trace(cstr, strlen(cstr), file, line, func);
246 }
FILE * file
Definition: log.c:133
#define octstr_create_from_data_trace(data, len, file, line, func)
Definition: octstr.h:136
gw_assert(wtls_machine->packet_to_send!=NULL)
void octstr_delete ( Octstr ostr1,
long  pos,
long  len 
)

Definition at line 1525 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, and seems_valid.

Referenced by at2_detect_modem_type(), at2_format_address_field(), at2_init_device(), at2_pdu_encode(), at2_scan_for_telnet_escapes(), cgw_decode_msg(), cgw_encode_msg(), charset_gsm_to_latin1(), check_data_content_type_header(), check_data_x_wap_application_id_header(), client_read_status(), compare_octstr_sequence(), concat_handling_check_and_handle(), conn_read_line(), convert_addr_from_pdu(), convert_cimd2_to_gsm(), data_sm_to_msg(), decode_binary_data(), dlr_find(), drop_character(), drop_extension_headers(), drop_header_true(), drop_separator(), eat_char(), eat_checksum(), eat_number(), eat_string_parm(), emi2_handle_smscreq(), encode_binary_data(), escape_data(), expand_file(), extract_msgdata_part(), find_translation(), fix_boundary_element(), get_originator_type(), get_start_param(), handle_operation(), handle_two_terminators(), http_header_get_content_type(), http_remove_hop_headers(), httpd_serve(), main(), meta_data_pack(), mime_something_to_entity(), msg_to_emimsg(), msg_to_pdu(), octstr_convert_from_html_entities(), octstr_delete_matching(), octstr_drop_leading_blanks(), octstr_drop_trailing_zeros(), octstr_replace(), octstr_replace_first(), octstr_shrink_blanks(), octstr_split_by_pos(), octstr_strip_blanks(), octstr_strip_char(), octstr_strip_crlfs(), octstr_strip_nonalphanums(), oisd_shrink_gsm7(), pack_7bit(), pack_cache_control(), pack_challenge(), pack_known_header(), pack_parameter(), pack_quoted_string(), packet_extract(), packet_set_checksum(), parse_address(), parse_appid_header(), parse_attr_value(), parse_attribute(), parse_body_part(), parse_cgivars(), parse_data(), parse_entities(), parse_epilogue(), parse_get_rest(), parse_ppg_specifier(), parse_preamble(), parse_url_value(), parse_value(), pass_data_headers(), pass_extension_headers(), pass_optional_header(), pdu_to_msg(), radius_authenticate_pdu(), radius_pdu_pack(), read_line(), remove_crs(), remove_long(), remove_prefix(), replace_octstr_char(), response(), send_message(), set_charset(), skip_tail(), soap_parse_dlr(), soap_parse_mo(), split_headers(), string_table_apply(), strip_keyword(), strip_prefix_and_suffix(), unescape_data(), unlocked_read(), unlocked_write(), unpack_broken_parameters(), unpack_credentials(), unpack_datagram(), unpack_warning_value(), wap_map_url(), write_data(), wsp_pack_list(), wsp_strip_parameters(), wsp_unpack_well_known_field(), and wtp_unpack_wdp_datagram().

1526 {
1527  seems_valid(ostr1);
1528  gw_assert(!ostr1->immutable);
1529 
1530  if (pos > ostr1->len)
1531  pos = ostr1->len;
1532  if (pos + len > ostr1->len)
1533  len = ostr1->len - pos;
1534  if (len > 0) {
1535  memmove(ostr1->data + pos, ostr1->data + pos + len,
1536  ostr1->len - pos - len);
1537  ostr1->len -= len;
1538  ostr1->data[ostr1->len] = '\0';
1539  }
1540 
1541  seems_valid(ostr1);
1542 }
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_delete_matching ( Octstr haystack,
Octstr needle 
)

Definition at line 2700 of file octstr.c.

References gw_assert(), Octstr::immutable, octstr_delete(), octstr_len(), octstr_search(), and seems_valid.

Referenced by push_content_create().

2701 {
2702  int p = 0;
2703  long len;
2704 
2705  seems_valid(haystack);
2706  seems_valid(needle);
2707  gw_assert(!haystack->immutable);
2708  len = octstr_len(needle);
2709 
2710  while ((p = octstr_search(haystack, needle, p)) != -1) {
2711  octstr_delete(haystack, p, len);
2712  }
2713 }
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1068
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
void octstr_destroy ( Octstr ostr)

Definition at line 322 of file octstr.c.

References Octstr::data, Octstr::immutable, and seems_valid.

Referenced by accept_boxc(), accept_escaped(), add_client_sdu_size(), add_crs(), add_group(), add_msg_cb(), add_msisdn(), add_push_flag(), add_via(), add_wsp_get(), add_x_wap_tod(), ap_destroy(), at2_close_device(), at2_detect_modem_type(), at2_device_thread(), at2_extract_line(), at2_flush_buffer(), at2_init_device(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), at2_pdu_extract(), at2_read_pending_incoming_messages(), at2_scan_for_telnet_escapes(), at2_send_one_message(), at2_set_message_storage(), at2_wait_line(), at2_wait_modem_command(), attribute_destroy(), bb_alog_shutdown(), bb_alog_sms(), bb_print_status(), bb_smscconn_send_failed(), bb_smscconn_sent(), bearerbox_address_destroy(), boxc_cleanup(), boxc_destroy(), boxc_receiver(), boxc_sent_pop(), boxc_sent_push(), boxc_status(), brunet_parse_body(), brunet_receive_sms(), brunet_send_sms(), cfg_destroy(), cfg_dump(), cfg_get_bool(), cfg_get_group_checksum(), cfg_get_integer(), cfg_get_list(), cfg_read(), cfgloc_destroy(), cgw_handle_op(), cgw_listener(), cgw_read_op(), cgw_sender(), cgwop_create(), cgwop_destroy(), cgwop_send(), challenge(), charset_gsm_to_utf8(), charset_utf8_to_gsm(), check_application_headers(), check_comparisons(), check_data_content_type_header(), check_data_x_wap_application_id_header(), check_do_elements(), check_reversible(), check_variable_name(), check_variable_syntax(), check_x_wap_application_id_header(), cid_matches(), cimd2_accept_delivery_report_message(), cimd2_accept_message(), cimd2_destroy(), cimd2_request(), cimd2_submit_msg(), clickatell_parse_body(), clickatell_receive_sms(), clickatell_send_sms(), client_destroy(), client_is_persistent(), client_read_status(), client_shutdown(), client_thread(), cmp_conn_grp_checksum(), cmp_conn_grp_id(), cmp_rout_grp_checksum(), concat_handling_check_and_handle(), concat_handling_clear_old_parts(), config_reload(), conn_destroy(), conn_pool_get(), conndata_destroy(), content_transformable(), convert(), convert_content(), convert_wml_to_wmlc(), cookie_destroy(), create_dlr_from_msg(), create_onetrans(), create_oneuser(), date_parse_http(), decode_binary_data(), deconvert_content(), deduce_body_state(), delayed_http_reply(), deliver_to_bearerbox_real(), destroy_concatMsg(), destroy_group(), destroy_onetrans(), destroy_oneuser(), dispatch(), dlr_add(), dlr_find(), dlr_init(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), dlr_spool_shutdown(), do_queue_cleanup(), eat_int_parm(), eat_string_parm(), emi2_handle_smscreq(), emi2_listener(), emi2_receiver(), emi2_sender(), emimsg_destroy(), emimsg_send(), emimsg_tostring(), encode_binary_data(), entity_destroy(), eq_destroy_event(), expand_file(), extract_msgdata_part_by_coding(), fake_listener(), fieldmap_destroy(), fill_message(), find_charset_encoding(), find_translation(), fix_boundary_element(), flag_date_length(), for_each_file(), generic_init(), generic_parse_reply(), generic_receive_sms(), generic_send_sms(), get_and_set_debugs(), get_data(), get_msg_filename(), get_pattern(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), grp_dump(), handle_connect_reply(), handle_dlr(), handle_enquire(), handle_get_reply(), handle_login(), handle_operation(), handle_pdu(), handle_push_message(), handle_submit(), handle_transaction(), hash_destroy(), http_accept_request(), http_add_basic_auth(), http_close_proxy(), http_destroy_cgiargs(), http_get_header_parameter(), http_header_add_element(), http_header_combine(), http_header_mark_transformation(), http_header_pack(), http_header_remove_all(), http_header_split_auth_value(), http_header_value(), http_queue_thread(), http_remove_hop_headers(), http_send_reply(), http_something_accepted(), http_thread(), http_urlparse_destroy(), httpadmin_run(), httpadmin_start(), httpadmin_stop(), httpd_emu(), httpd_serve(), httpsmsc_receiver(), httpsmsc_send_cb(), init_bearerbox(), init_reroute(), init_smsbox(), init_smsbox_routes(), init_wapbox(), io_thread(), ip_allowed_by_user(), item_destroy(), kannel_parse_reply(), kannel_receive_sms(), kannel_send_sms(), kill_kannel(), main(), main_connection_loop(), make_reply_headers(), md5digest(), meta_data_destroy(), meta_data_merge(), meta_data_pack(), meta_data_set_values(), meta_data_unpack(), mime_entity_body(), mime_entity_destroy(), mime_entity_dump_real(), mime_entity_set_body(), mime_entity_to_octstr(), mime_multipart_start_elem(), mime_something_to_entity(), msg_cb(), msg_to_bb(), msg_to_cgwop(), msg_to_emimsg(), msg_to_pdu(), normalize_charset(), normalize_number(), numhash_create(), obey_request(), obey_request_thread(), octstr_append_from_hex(), octstr_convert_from_html_entities(), octstr_destroy_item(), octstr_format_append(), octstr_read_file(), octstr_read_pipe(), octstr_recode(), ois_open_receiver(), oisd_accept_delivery_report_message(), oisd_destroy(), oisd_request(), oisd_shrink_gsm7(), oisd_submit_msg(), open_send_connection(), ota_compile(), ota_pack_message(), ota_pack_push_headers(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_7bit(), pack_accept(), pack_accept_charset(), pack_accept_language(), pack_appid_list(), pack_cache_control(), pack_challenge(), pack_content_disposition(), pack_content_range(), pack_credentials(), pack_md5(), pack_pragma(), pack_range_value(), pack_server_address(), pack_warning(), packet_add_hex_parm(), packet_add_int_parm(), packet_add_parm(), packet_check_can_receive(), packet_destroy(), packet_display_error(), packet_encode_message(), packet_get_hex_parm(), packet_get_int_parm(), pap_convert_content(), pap_get_content(), pap_request_thread(), parm_destroy(), parse_address(), parse_address_value(), parse_appid_header(), parse_array_element(), parse_attr_value(), parse_attribute(), parse_body_part(), parse_cdata(), parse_cgivars(), parse_charset(), parse_client_specifier(), parse_code(), parse_constant(), parse_data(), parse_data_element(), parse_document(), parse_element(), parse_entities(), parse_fault_element(), parse_inline_string(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_ota_syncsettings(), parse_param_element(), parse_params_element(), parse_preamble(), parse_push_message_value(), parse_push_response_value(), parse_request_line(), parse_st_octet_string(), parse_struct_element(), parse_text(), parse_url_value(), parse_uuid(), parse_value(), parse_value_element(), parse_variable(), parse_xml_tag(), pass_extension_headers(), pass_field_name(), pass_field_value(), pass_optional_header(), pattern_list_matches_ip(), port_add(), port_get_fdset(), port_get_request(), port_put_request(), port_remove(), port_set_timeout(), prepend_char(), proxy_add_authentication(), proxy_thread(), proxy_unpack_credentials(), push_content_create(), push_headers_create(), radius_acct_init(), radius_acct_shutdown(), radius_authenticate_pdu(), radius_pdu_pack(), radius_pdu_unpack(), radius_type_convert(), read_body_until_eof(), read_body_with_length(), read_chunked_body_crlf(), read_chunked_body_data(), read_chunked_body_len(), read_from_bearerbox_real(), read_from_box(), read_mime_headers(), read_msg(), read_pdu(), read_ppg_config(), read_some_headers(), receive_push_reply(), receive_reply(), receive_request(), receive_smpp_thread(), recover_absolute_uri(), report_versions(), response(), return_replies_thread(), return_reply(), route_incoming_to_boxc(), route_incoming_to_smsc(), run_batch(), run_requests(), run_smsbox(), sar_info_destroy(), sardata_destroy(), sema_encode_msg(), sema_msg_session_mt(), send_bad_message_response(), send_enquire_link(), send_file(), send_gnack(), send_invoke_connect(), send_invoke_disconnect(), send_invoke_get(), send_logoff(), send_messages(), send_msg(), send_pdu(), send_post(), send_push_response(), send_request(), send_smpp_thread(), send_to_pi(), send_udp(), send_unbind(), sendsms_thread(), server(), server_destroy(), server_thread(), set_addr_tuple(), set_bearer_defaults(), set_charset(), set_dlr_mask(), set_group_name(), set_network_defaults(), set_referer_url(), shutdown_cb(), si_compile(), simple_binary_destroy(), sl_compile(), smasi_destroy(), smasi_pdu_pack(), smasi_pdu_unpack(), smpp_destroy(), smpp_emu(), smpp_emu_handle_pdu(), smpp_emu_reader(), smpp_emu_writer(), smpp_pdu_dump_line(), smpp_pdu_init(), smpp_pdu_pack(), smpp_pdu_read_len(), smpp_tlv_destroy(), smpp_tlv_get_by_tag(), sms_msgdata_len(), sms_split(), sms_to_client(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_start(), smsbox_thread(), smsbox_xmlrpc_post(), smsc2_cleanup(), smsc2_restart_smsc(), smsc2_start(), smsc_cgw_create(), smsc_emi2_create(), smsc_emu_submit_ack(), smsc_fake_create(), smsc_http_create(), smsc_open(), smsc_smpp_create(), smsc_soap_create(), smscconn_create(), smscconn_destroy(), smscconn_reconfig(), soap_create_map(), soap_destroy_map(), soap_fetch_xml_data(), soap_format_xml(), soap_map_xml_data(), soap_parse_dlr(), soap_parse_mo(), socket_shutdown(), split_headers(), start_fetch(), start_push(), start_request(), status_cb(), store_dumper(), store_file_load(), store_spool_save(), store_spool_shutdown(), store_to_dict(), string_table_add(), string_table_apply(), string_table_collect_strings(), string_table_destroy(), string_table_proposal_destroy(), string_table_sort_list(), tcpip_connect_nb_to_server_with_port(), tcpip_connect_to_server_with_port(), tell_fatal_error(), tokenize_date(), transform_message(), type_is(), udp_addwdp(), udp_addwdp_from_client(), udp_addwdp_from_server(), udp_die(), udp_receiver(), udp_start(), udpc_create(), udpc_destroy(), unpack_cache_directive(), unpack_challenge(), unpack_credentials(), unpack_datagram(), unpack_optional_q_value(), unpack_parameter(), unpack_range_value(), unpack_warning_value(), update_table(), update_tables(), url_result_thread(), urltrans_fill_escape_codes(), wait_for_ack(), wait_for_client(), wap_addr_destroy(), wap_map_destroy(), wap_map_url(), wap_msg_recv(), wap_msg_send(), wap_push_ppg_pushuser_authenticate(), wap_push_ppg_shutdown(), wap_user_map_destroy(), wapme_smsproxy_send_sms(), wml_binary_destroy(), wrapper_sender(), write_msg(), write_to_bearerbox_real(), wsp_cap_destroy(), wsp_headers_pack(), wsp_pack_list(), wsp_pack_retry_after(), wsp_pack_separate_content_type(), wsp_unpack_app_header(), wsp_unpack_well_known_field(), wtp_tpi_destroy(), wtp_unpack_wdp_datagram(), xidris_parse_reply(), xidris_receive_sms(), xidris_send_sms(), xml_error(), xmlrpc_call_destroy(), xmlrpc_call_print(), xmlrpc_doc_destroy(), xmlrpc_doc_print(), xmlrpc_doc_send(), xmlrpc_fault_destroy(), xmlrpc_member_destroy(), xmlrpc_print_array(), xmlrpc_print_struct(), xmlrpc_response_print(), xmlrpc_scalar_destroy(), xmlrpc_scalar_print(), and xmlrpc_value_print().

323 {
324  if (ostr != NULL) {
325  seems_valid(ostr);
326  if (!ostr->immutable) {
327  gw_free(ostr->data);
328  gw_free(ostr);
329  }
330  }
331 }
int immutable
Definition: octstr.c:123
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
void octstr_dump_real ( const Octstr ostr,
int  level,
  ... 
)

Definition at line 2113 of file octstr.c.

References error(), GW_DEBUG, GW_ERROR, GW_INFO, GW_WARNING, info(), octstr_dump_debug(), octstr_dump_LOGLEVEL, and warning().

2114 {
2115  va_list p;
2116  unsigned int loglevel;
2117 
2118  va_start(p, level);
2119  loglevel = va_arg(p, unsigned int);
2120  va_end(p);
2121 
2122  switch (loglevel) {
2123  case GW_DEBUG:
2124  octstr_dump_debug(ostr, level);
2125  break;
2126  case GW_INFO:
2127  octstr_dump_LOGLEVEL(info, ostr, level);
2128  break;
2129  case GW_WARNING:
2130  octstr_dump_LOGLEVEL(warning, ostr, level);
2131  break;
2132  case GW_ERROR:
2133  octstr_dump_LOGLEVEL(error, ostr, level);
2134  break;
2135  default:
2136  octstr_dump_debug(ostr, level);
2137  break;
2138  }
2139 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
Definition: log.h:69
Definition: log.h:69
void warning(int err, const char *fmt,...)
Definition: log.c:624
static void octstr_dump_debug(const Octstr *ostr, int level)
Definition: octstr.c:1988
#define octstr_dump_LOGLEVEL(loglevel, ostr, level)
Definition: octstr.c:2057
Definition: log.h:69
Definition: log.h:69
void octstr_dump_short ( Octstr ostr,
int  level,
const char *  name 
)

Definition at line 2142 of file octstr.c.

References Octstr::data, debug(), Octstr::len, octstr_dump, and seems_valid.

Referenced by main(), and radius_pdu_unpack().

2143 {
2144  char buf[100];
2145  char *p;
2146  long i;
2147  int c;
2148 
2149  if (ostr == NULL) {
2150  debug("gwlib.octstr", 0, "%*s%s: NULL", level, "", name);
2151  return;
2152  }
2153 
2154  seems_valid(ostr);
2155 
2156  if (ostr->len < 20) {
2157  p = buf;
2158  for (i = 0; i < ostr->len; i++) {
2159  c = ostr->data[i];
2160  if (c == '\n') {
2161  *p++ = '\\';
2162  *p++ = 'n';
2163  } else if (!isprint(c)) {
2164  break;
2165  } else if (c == '"') {
2166  *p++ = '\\';
2167  *p++ = '"';
2168  } else if (c == '\\') {
2169  *p++ = '\\';
2170  *p++ = '\\';
2171  } else {
2172  *p++ = c;
2173  }
2174  }
2175  if (i == ostr->len) {
2176  *p++ = 0;
2177  /* We got through the loop without hitting nonprintable
2178  * characters. */
2179  debug("gwlib.octstr", 0, "%*s%s: \"%s\"", level, "", name, buf);
2180  return;
2181  }
2182  }
2183 
2184  debug("gwlib.octstr", 0, "%*s%s:", level, "", name);
2185  octstr_dump(ostr, level + 1);
2186 }
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
char * name
Definition: smsc_cimd2.c:212
#define seems_valid(ostr)
Definition: octstr.c:169
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
Octstr* octstr_duplicate_real ( const Octstr ostr,
const char *  file,
long  line,
const char *  func 
)

Definition at line 371 of file octstr.c.

References Octstr::data, Octstr::len, octstr_create_from_data_trace, and seems_valid_real().

373 {
374  if (ostr == NULL)
375  return NULL;
376  seems_valid_real(ostr, file, line, func);
377  return octstr_create_from_data_trace(ostr->data, ostr->len, file, line, func);
378 }
static void seems_valid_real(const Octstr *ostr, const char *filename, long lineno, const char *function)
Definition: octstr.c:2543
FILE * file
Definition: log.c:133
#define octstr_create_from_data_trace(data, len, file, line, func)
Definition: octstr.h:136
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
long octstr_extract_uintvar ( Octstr ostr,
unsigned long *  value,
long  pos 
)

Definition at line 1952 of file octstr.c.

References octstr_get_char().

Referenced by is_default_cap(), parse_get_uintvar(), sanitize_capabilities(), wsp_cap_get_client_sdu(), wsp_cap_get_server_sdu(), and wsp_cap_unpack_list().

1953 {
1954  int c;
1955  int count;
1956  unsigned long ui;
1957 
1958  ui = 0;
1959  for (count = 0; count < 5; count++) {
1960  c = octstr_get_char(ostr, pos + count);
1961  if (c < 0)
1962  return -1;
1963  ui = (ui << 7) | (c & 0x7f);
1964  if (!(c & 0x80)) {
1965  *value = ui;
1966  return pos + count + 1;
1967  }
1968  }
1969 
1970  return -1;
1971 }
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
Octstr* octstr_format ( const char *  fmt,
  ... 
)

Definition at line 2462 of file octstr.c.

References octstr_format_valist.

Referenced by add_client_sdu_size(), add_crs(), add_msg_cb(), add_push_application_id(), add_push_flag(), add_via(), add_wsp_get(), at2_init_device(), at2_pdu_decode_report_sm(), at2_send_one_message(), at2_set_message_storage(), at2_write_line(), bb_print_status(), boxc_status(), brunet_send_sms(), build_request(), challenge(), check_x_wap_application_id_header(), clickatell_send_sms(), client_thread(), concat_handling_check_and_handle(), config_reload(), conn_pool_key(), create_dlr_from_msg(), create_onetrans(), date_create_iso(), dlr_find(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), eat_string_parm(), emimsg_tostring(), error_converting(), error_requesting(), error_requesting_back(), fix_boundary_element(), flag_date_length(), for_each_file(), get_msg_filename(), get_originator_type(), get_ton_npi_value(), handle_dlr(), handle_pdu(), handle_submit_sm(), headers_acceptable(), http_add_basic_auth(), http_header_add(), http_header_mark_transformation(), http_send_reply(), httpd_add_smsc(), httpd_loglevel(), httpd_remove_message(), httpd_remove_smsc(), httpd_restart_smsc(), httpd_serve(), httpd_stop_smsc(), init_configuration(), kannel_send_sms(), kill_kannel(), main(), make_multipart_value(), msg_to_emimsg(), msg_to_pdu(), obey_request(), open_send_connection(), pap_request_thread(), parse_appid_header(), parse_array(), parse_array_element(), parse_code(), parse_constant(), parse_data(), parse_data_element(), parse_document(), parse_fault(), parse_fault_element(), parse_inline_string(), parse_member(), parse_member_element(), parse_methodcall(), parse_methodcall_element(), parse_methodresponse(), parse_methodresponse_element(), parse_param(), parse_param_element(), parse_params(), parse_params_element(), parse_struct(), parse_struct_element(), parse_value(), parse_value_element(), parse_xml_tag(), port_key(), prepend_char(), proxy_add_authentication(), push_content_create(), radius_type_convert(), read_ppg_config(), route_incoming_to_boxc(), send_bad_message_response(), send_messages(), send_push_response(), send_smpp_thread(), set_bearer_defaults(), set_network_defaults(), set_time(), smpp_emu_writer(), smpp_pdu_init(), smpp_tlv_get_by_tag(), smsbox_req_sendota(), smsbox_sendota_post(), smsbox_xmlrpc_post(), smsc2_status(), smsc_at2_create(), smsc_cgw_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_fake_create(), smsc_http_create(), smsc_loopback_create(), smsc_oisd_create(), smsc_smpp_create(), smsc_soap_create(), soap_bouyg_validity_attribute(), soap_o2o_msgdata_attribute(), soap_o2o_validity30_attribute(), soap_rand_attribute(), soap_send(), soap_write_date(), store_file_init(), store_spool_save(), tell_fatal_error(), tell_ppg_name(), type_is(), unpack_datagram(), version_report_string(), wap_event_accept_or_create(), wap_push_ppg_pushuser_authenticate(), wapme_smsproxy_send_sms(), xidris_send_sms(), xml_error(), xmlrpc_call_print(), xmlrpc_doc_print(), xmlrpc_fault_print(), xmlrpc_print_array(), xmlrpc_print_struct(), xmlrpc_response_print(), xmlrpc_scalar_print(), and xmlrpc_value_print().

2463 {
2464  Octstr *os;
2465  va_list args;
2466 
2467  va_start(args, fmt);
2468  os = octstr_format_valist(fmt, args);
2469  va_end(args);
2470  return os;
2471 }
#define octstr_format_valist(fmt, args)
Definition: octstr.h:693
Definition: octstr.c:118
void octstr_format_append ( Octstr os,
const char *  fmt,
  ... 
)
Octstr* octstr_format_valist_real ( const char *  fmt,
va_list  args 
)

Definition at line 2474 of file octstr.c.

References convert(), format_flags(), format_prec(), format_type(), format_width(), gw_assert(), octstr_append_data(), octstr_create, seems_valid, and VARGS.

2475 {
2476  Octstr *os;
2477  size_t n;
2478 
2479  os = octstr_create("");
2480 
2481  while (*fmt != '\0') {
2482  struct format format = { 0, };
2483 
2484  n = strcspn(fmt, "%");
2485  octstr_append_data(os, fmt, n);
2486  fmt += n;
2487 
2488  gw_assert(*fmt == '%' || *fmt == '\0');
2489  if (*fmt == '\0')
2490  continue;
2491 
2492  ++fmt;
2493  format_flags(&format, &fmt);
2494  format_width(&format, &fmt, VARGS(args));
2495  format_prec(&format, &fmt, VARGS(args));
2496  format_type(&format, &fmt);
2497  convert(os, &format, &fmt, VARGS(args));
2498  }
2499 
2500  seems_valid(os);
2501  return os;
2502 }
#define VARGS(x)
Definition: octstr.c:89
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1495
static void format_type(struct format *format, const char **fmt)
Definition: octstr.c:2280
static void format_flags(struct format *format, const char **fmt)
Definition: octstr.c:2213
static void format_width(struct format *format, const char **fmt, VALPARM(args))
Definition: octstr.c:2239
static void convert(Octstr *os, struct format *format, const char **fmt, VALPARM(args))
Definition: octstr.c:2298
#define octstr_create(cstr)
Definition: octstr.h:125
static void format_prec(struct format *format, const char **fmt, VALPARM(args))
Definition: octstr.c:2257
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
long octstr_get_bits ( Octstr ostr,
long  bitpos,
int  numbits 
)

Definition at line 1801 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by deduce_tid(), get_tid(), unpack_ack(), unpack_tpis(), wtp_type(), and wtp_unpack_wdp_datagram().

1802 {
1803  long pos;
1804  long result;
1805  int mask;
1806  int shiftwidth;
1807 
1808  seems_valid(ostr);
1809  gw_assert(bitpos >= 0);
1810  gw_assert(numbits <= 32);
1811  gw_assert(numbits >= 0);
1812 
1813  pos = bitpos / 8;
1814  bitpos = bitpos % 8;
1815 
1816  /* This also takes care of the len == 0 case */
1817  if (pos >= ostr->len)
1818  return 0;
1819 
1820  mask = (1 << numbits) - 1;
1821 
1822  /* It's easy if the range fits in one octet */
1823  if (bitpos + numbits <= 8) {
1824  /* shiftwidth is the number of bits to ignore on the right.
1825  * bitpos 0 is the leftmost bit. */
1826  shiftwidth = 8 - (bitpos + numbits);
1827  return (ostr->data[pos] >> shiftwidth) & mask;
1828  }
1829 
1830  /* Otherwise... */
1831  result = 0;
1832  while (bitpos + numbits > 8) {
1833  result = (result << 8) | ostr->data[pos];
1834  numbits -= (8 - bitpos);
1835  bitpos = 0;
1836  pos++;
1837  if (pos >= ostr->len)
1838  return (result << numbits) & mask;
1839  }
1840 
1841  gw_assert(bitpos == 0);
1842  result <<= numbits;
1843  result |= ostr->data[pos] >> (8 - numbits);
1844  return result & mask;
1845 }
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_get_char ( const Octstr ostr,
long  pos 
)

Definition at line 404 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid.

Referenced by accept_escaped(), accept_safe(), add_crs(), at2_convertpdu(), at2_decode7bituncompressed(), at2_encode7bituncompressed(), at2_encode8bituncompressed(), at2_extract_line(), at2_format_address_field(), at2_pdu_decode(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_extract(), at2_scan_for_telnet_escapes(), calculate_checksum(), cfg_read(), charset_gsm_to_latin1(), charset_gsm_to_nrc_iso_21_german(), charset_gsm_to_utf8(), charset_gsm_truncate(), charset_latin1_to_gsm(), charset_nrc_iso_21_german_to_gsm(), charset_utf8_to_gsm(), check_variable_syntax(), client_session(), concat_handling_check_and_handle(), concatenated_message(), conn_read_line(), convert_addr_from_pdu(), convert_cimd2_to_gsm(), convert_gsm_to_cimd2(), convert_html_entity(), create_peek_window(), data_sm_to_msg(), date_parse_http(), decode_bearer_indication(), decode_binary_data(), decode_integer(), drop_extension_headers(), eat_char(), eat_checksum(), emi2_handle_smscreq(), encode_binary_data(), escape_data(), escape_fragment(), expand_file(), extract_msgdata_part(), fix_boundary_element(), generic_receive_sms(), get_fields(), get_mime_boundary(), get_originator_type(), get_pattern(), get_start_param(), get_variable(), get_varint(), get_wtp_pdu_type(), gsm2number(), handle_connect_reply(), handle_get_reply(), handle_operation(), html_to_sms(), http_get_header_parameter(), http_header_get_content_type(), http_header_quoted_string_len(), http_header_split_auth_value(), http_header_split_value(), httpd_serve(), is_default_cap(), issafe(), kannel_receive_sms(), main(), mime_something_to_entity(), msg_to_emimsg(), msg_to_pdu(), octstr_convert_to_html_entities(), octstr_drop_leading_blanks(), octstr_drop_trailing_zeros(), octstr_dump_debug(), octstr_extract_uintvar(), octstr_is_all_hex(), octstr_isnum(), octstr_search_chars(), octstr_shrink_blanks(), octstr_strip_blanks(), octstr_strip_char(), octstr_strip_crlfs(), octstr_strip_nonalphanums(), oisd_accept_delivery_report_message(), oisd_accept_message(), oisd_expand_gsm7_to_bits(), oisd_request(), oisd_shrink_gsm7(), pack_7bit(), pack_cache_control(), pack_challenge(), pack_content_range(), pack_credentials(), pack_if_range(), pack_quoted_string(), pack_range(), pack_range_value(), pack_warning(), packet_check_header(), packet_check_parameter(), packet_extract(), packet_parse_header(), packet_set_checksum(), parse_address(), parse_constant(), parse_date(), parse_dom_fragment(), parse_escaped_value(), parse_field_name(), parse_field_value(), parse_get_char(), parse_global_phone_number(), parse_http_version(), parse_ipv4(), parse_ipv4_fragment(), parse_ipv6(), parse_ipv6_fragment(), parse_msg_to_rawmessage(), parse_peek_char(), parse_ppg_specifier(), parse_qualifier_keyword(), parse_qualifier_value(), parse_qvalue(), parse_st_octet_string(), parse_terminator(), parse_transport_padding(), parse_type(), parse_value(), parse_variable(), pass_extension_headers(), pass_field_name(), pass_field_value(), pattern_matches_ip(), pdu_to_msg(), qualifiers(), radius_type_convert(), read_mime_headers(), read_some_headers(), recover_absolute_uri(), remove_crs(), resend_sar_result(), sanitize_capabilities(), send_packet(), set_tid(), set_tid_new(), skip_html_tag(), smsbox_req_handle(), soap_fetch_xml_data(), soap_format_xml(), split_headers(), string_table_apply(), strip_keyword(), tokenize_date(), unescape_data(), unpack_datagram(), unpack_parameter(), unpack_warning_value(), urltrans_fill_escape_codes(), wait_for_ack(), wap_map_url(), wap_msg_send(), wsp_cap_get_method_mor(), wsp_cap_get_push_mor(), wsp_cap_pack_list(), wsp_cap_unpack_list(), wsp_pack_integer_string(), wsp_pack_retry_after(), wsp_pack_text(), wsp_pack_version_value(), wsp_strip_parameters(), and wtp_unpack_wdp_datagram().

405 {
406  seems_valid(ostr);
407  if (pos >= ostr->len || pos < 0)
408  return -1;
409  return ostr->data[pos];
410 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
char* octstr_get_cstr_real ( const Octstr ostr,
const char *  file,
long  line,
const char *  func 
)

Definition at line 437 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid_real().

439 {
440  if (!ostr)
441  return "(null)";
442  seems_valid_real(ostr, file, line, func);
443  if (ostr->len == 0)
444  return "";
445  return ostr->data;
446 }
static void seems_valid_real(const Octstr *ostr, const char *filename, long lineno, const char *function)
Definition: octstr.c:2543
FILE * file
Definition: log.c:133
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_get_many_chars ( char *  buf,
Octstr ostr,
long  pos,
long  len 
)

Definition at line 423 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by cimd_submit_msg(), compare_octstr_sequence(), conn_read_withlen(), convert_html_entity(), html_comment_begins(), packet_extract(), parse_integer(), parse_msg_to_rawmessage(), read_msg(), smpp_pdu_read_len(), wap_msg_recv(), and write_data().

424 {
425  gw_assert(buf != NULL);
426  seems_valid(ostr);
427 
428  if (pos >= ostr->len)
429  return;
430  if (pos + len > ostr->len)
431  len = ostr->len - pos;
432  if (len > 0)
433  memcpy(buf, ostr->data + pos, len);
434 }
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
unsigned long octstr_hash_key ( Octstr ostr)

Definition at line 2521 of file octstr.c.

References octstr_get_cstr, and octstr_len().

Referenced by dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), key_to_index(), and store_spool_save().

2522 {
2523  unsigned long b = 378551;
2524  unsigned long a = 63689;
2525  unsigned long hash = 0;
2526  unsigned long i = 0;
2527  unsigned long len = octstr_len(ostr);
2528  const char *str = octstr_get_cstr(ostr);
2529 
2530  for(i = 0; i < len; str++, i++) {
2531  hash = hash*a+(*str);
2532  a = a*b;
2533  }
2534 
2535  return (hash & 0x7FFFFFFF);
2536 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
int octstr_hex_to_binary ( Octstr ostr)

Definition at line 492 of file octstr.c.

References Octstr::data, gw_assert(), gw_isxdigit(), Octstr::immutable, Octstr::len, octstr_check_range(), and seems_valid.

Referenced by accept_escaped(), at2_pdu_extract(), decode_binary_data(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), handle_operation(), main(), octstr_append_from_hex(), packet_get_hex_parm(), push_content_create(), and soap_msgdata_deps().

493 {
494  long len, i;
495  unsigned char *p;
496 
497  seems_valid(ostr);
498  gw_assert(!ostr->immutable);
499 
500  if (ostr->len == 0)
501  return 0;
502 
503  /* Check if it's in the right format */
504  if (!octstr_check_range(ostr, 0, ostr->len, gw_isxdigit))
505  return -1;
506 
507  len = ostr->len;
508 
509  /* Convert ascii data to binary values */
510  for (i = 0, p = ostr->data; i < len; i++, p++) {
511  if (*p >= '0' && *p <= '9')
512  *p -= '0';
513  else if (*p >= 'a' && *p <= 'f')
514  *p = *p - 'a' + 10;
515  else if (*p >= 'A' && *p <= 'F')
516  *p = *p - 'A' + 10;
517  else {
518  /* isxdigit checked the whole string, so we should
519  * not be able to get here. */
520  gw_assert(0);
521  *p = 0;
522  }
523  }
524 
525  /* De-hexing will compress data by factor of 2 */
526  len = ostr->len / 2;
527 
528  for (i = 0; i < len; i++) {
529  ostr->data[i] = ostr->data[i * 2] * 16 | ostr->data[i * 2 + 1];
530  }
531 
532  ostr->len = len;
533  ostr->data[len] = '\0';
534 
535  seems_valid(ostr);
536  return 0;
537 }
int octstr_check_range(Octstr *ostr, long pos, long len, octstr_func_t filter)
Definition: octstr.c:812
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int gw_isxdigit(int c)
Definition: utils.c:994
Octstr* octstr_imm ( const char *  cstr)

Definition at line 281 of file octstr.c.

References CSTR_TO_LONG, Octstr::data, gw_assert(), Octstr::immutable, immutables_init, Octstr::len, MAX_IMMUTABLES, mutex_lock, mutex_unlock, panic, seems_valid, and Octstr::size.

Referenced by add_connection_header(), add_content_transfer_encoding_type(), add_content_type(), add_delimiter(), add_group(), add_push_application_id(), add_via(), append_crlf(), at2_check_sms_memory(), at2_detect_modem_type(), at2_extract_line(), at2_init_device(), at2_pdu_extract(), at2_read_modems(), at2_send_one_message(), at2_wait_modem_command(), authorise_user(), bb_alog_sms(), bb_reload_smsc_groups(), brunet_parse_body(), brunet_parse_reply(), brunet_send_sms(), build_request(), build_response(), cfg_get_bool(), cfg_read(), cgw_decode_msg(), cgw_encode_msg(), cgw_handle_op(), cgw_read_op(), cgwop_create(), cgwop_tostr(), challenge(), charset_to_utf8(), check_config(), check_control_content_type_header(), check_control_headers(), cid_matches(), clickatell_parse_body(), clickatell_parse_reply(), clickatell_send_sms(), client_is_persistent(), client_thread(), cmp_conn_grp_id(), config_reload(), conn_pool_key(), connect_denied(), construct_linear_table(), construct_numbered_table(), content_transformable(), convert_addr_from_pdu(), core_is_allowed_in_group(), create_dlr_from_msg(), create_onetrans(), create_oneuser(), describe_code(), dlr_db_fields_create(), dlr_find(), dlr_init(), dlr_init_spool(), drop_extension_headers(), drop_optional_header(), escape_fragment(), expand_file(), find_charset_encoding(), fix_boundary_element(), generic_get_field_map(), generic_init(), generic_receive_sms(), get_data(), get_mime_boundary(), get_start_param(), get_x_kannel_from_headers(), handle_dlr(), handle_pdu(), handle_transaction(), http_add_basic_auth(), http_header_get_content_type(), http_header_pack(), httpadmin_start(), httpd_serve(), init_batch(), init_bearerbox(), init_configuration(), init_reroute(), init_smsbox(), init_smsbox_routes(), init_wapbox(), ip_allowed_by_ppg(), ip_allowed_by_user(), kannel_parse_reply(), kannel_receive_sms(), kannel_send_sms(), main(), make_multipart_value(), make_url(), mime_decompile(), mime_entity_dump_real(), mime_entity_to_octstr(), mime_multipart_start_elem(), mime_something_to_entity(), msg_to_bb(), msg_to_cgwop(), msg_to_pdu(), name(), normalize_charset(), obey_request(), obey_request_thread(), octstr_binary_to_base64(), octstr_recode(), open_send_connection(), ota_pack_message(), ota_pack_push_headers(), ota_pack_udh(), ota_tokenize_bookmarks(), ota_tokenize_settings(), pack_appid_list(), pack_cache_control(), pack_challenge(), pack_content_range(), pack_credentials(), pack_pragma(), pack_range(), packet_encode_message(), pap_convert_content(), pap_get_content(), pap_request_thread(), parse2trans(), parse_address_value(), parse_appid_header(), parse_array_element(), parse_attr_value(), parse_attribute(), parse_bad_message_response_value(), parse_bearer(), parse_client_specifier(), parse_data_element(), parse_date(), parse_delivery_method(), parse_document(), parse_element(), parse_entities(), parse_fault_element(), parse_http_version(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_network(), parse_ota_syncsettings(), parse_pap_value(), parse_param_element(), parse_params_element(), parse_priority(), parse_progress_note_value(), parse_push_message_value(), parse_push_response_value(), parse_quality_of_service_value(), parse_request_line(), parse_requirement(), parse_response_result_value(), parse_state(), parse_struct_element(), parse_url(), parse_url_value(), parse_value_element(), pass_data_headers(), pass_extension_headers(), pattern_list_matches_ip(), prefix_allowed(), prepend_crlf(), proxy_add_authentication(), push_content_create(), qualifiers(), radius_acct_init(), read_ppg_config(), read_test_ppg_config(), reply(), response(), return_reply(), select_bearer_network(), server(), set_addr_tuple(), set_any_value(), set_attribute_value(), set_dlr_mask(), set_dlr_url(), set_smsbox_id(), set_smsc_id(), skip_html_comment(), smpp_pdu_init(), smpp_tlv_get_by_name(), smpp_tlv_get_by_tag(), sms_to_client(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_start(), smsbox_xmlrpc_post(), smsc2_add_smsc(), smsc2_restart_smsc(), smsc2_start(), smsc2_status(), smsc_at2_create(), smsc_cgw_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_fake_create(), smsc_http_create(), smsc_oisd_create(), smsc_open(), smsc_smpp_create(), smsc_soap_create(), smscconn_create(), smscconn_instances(), soap_create_map(), soap_fetch_xml_data(), soap_map_xml_data(), soap_msgdata_deps(), soap_parse_dlr(), soap_read_response(), soap_release_dependences(), soap_server(), start_fetch(), start_request(), status_cb(), test_header_combine(), transfer_encode(), type_is(), udp_start(), unpack_challenge(), unpack_optional_q_value(), unpack_parameter(), update_table(), update_tables(), url_result_thread(), urltrans_add_cfg(), urltrans_fill_escape_codes(), uses_gsm_msisdn_address(), uses_ipv4_address(), uses_ipv6_address(), wap_event_accept_or_create(), wap_map_url_config(), wap_map_url_config_device_home(), wapbox_start(), wildcarded_ip_found(), wina_bearer_identifier(), wml_charsets(), wsp_encoding_string_to_version(), xidris_parse_reply(), xidris_receive_sms(), xidris_send_sms(), xml_error(), and xmlrpc_fault_print().

282 {
283  Octstr *os;
284  long i, index;
285  unsigned char *data;
286 
288  gw_assert(cstr != NULL);
289 
290  index = CSTR_TO_LONG(cstr) % MAX_IMMUTABLES;
291  data = (unsigned char *) cstr;
292 
294  i = index;
295  for (; ; ) {
296  if (immutables[i] == NULL || immutables[i]->data == data)
297  break;
298  i = (i + 1) % MAX_IMMUTABLES;
299  if (i == index)
300  panic(0, "Too many immutable strings.");
301  }
302  os = immutables[i];
303  if (os == NULL) {
304  /*
305  * Can't use octstr_create() because it copies the string,
306  * which would break our hashing.
307  */
308  os = gw_malloc(sizeof(*os));
309  os->data = data;
310  os->len = strlen(data);
311  os->size = os->len + 1;
312  os->immutable = 1;
313  immutables[i] = os;
314  seems_valid(os);
315  }
317 
318  return os;
319 }
#define mutex_unlock(m)
Definition: thread.h:136
#define MAX_IMMUTABLES
Definition: octstr.c:131
static Mutex immutables_mutex
Definition: octstr.c:134
static Octstr * immutables[MAX_IMMUTABLES]
Definition: octstr.c:133
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
static int immutables_init
Definition: octstr.c:135
#define CSTR_TO_LONG(ptr)
Definition: octstr.c:145
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
#define panic
Definition: log.h:87
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
#define mutex_lock(m)
Definition: thread.h:130
void octstr_init ( void  )

Definition at line 216 of file octstr.c.

References immutables_init, mutex_init_static, and urlcode_init().

Referenced by gwlib_init().

217 {
218  urlcode_init();
220  immutables_init = 1;
221 }
static Mutex immutables_mutex
Definition: octstr.c:134
#define mutex_init_static(mutex)
Definition: thread.h:115
static int immutables_init
Definition: octstr.c:135
static void urlcode_init(void)
Definition: octstr.c:205
void octstr_insert ( Octstr ostr1,
const Octstr ostr2,
long  pos 
)

Definition at line 1301 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, octstr_grow(), and seems_valid.

Referenced by accept_escaped(), add_crs(), append_string(), cgw_decode_msg(), cgw_encode_msg(), decode_binary_data(), escape_data(), flag_date_length(), http_add_basic_auth(), init_smsbox_routes(), main(), msg_to_pdu(), octstr_append(), octstr_binary_to_base64(), octstr_replace(), octstr_replace_first(), output_octet_string(), output_st_octet_string(), pack_challenge(), packet_add_parm(), parse_entities(), parse_inline_string(), parse_st_octet_string(), prefix_allowed(), prepend_char(), prepend_crlf(), proxy_add_authentication(), radius_authenticate_pdu(), radius_pdu_pack(), recover_absolute_uri(), replace_octstr_char(), smasi_pdu_pack(), smpp_pdu_pack(), sms_split(), string_table_apply(), string_table_output(), unpack_parameter(), wml_binary_output(), and xmlrpc_doc_print().

1302 {
1303  if (ostr2 == NULL)
1304  return;
1305 
1306  seems_valid(ostr1);
1307  seems_valid(ostr2);
1308  gw_assert(pos <= ostr1->len);
1309  gw_assert(!ostr1->immutable);
1310 
1311  if (ostr2->len == 0)
1312  return;
1313 
1314  octstr_grow(ostr1, ostr1->len + ostr2->len);
1315  memmove(ostr1->data + pos + ostr2->len, ostr1->data + pos,
1316  ostr1->len - pos);
1317  memcpy(ostr1->data + pos, ostr2->data, ostr2->len);
1318  ostr1->len += ostr2->len;
1319  ostr1->data[ostr1->len] = '\0';
1320 
1321  seems_valid(ostr1);
1322 }
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_insert_char ( Octstr ostr,
long  pos,
const char  c 
)

Definition at line 1479 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, octstr_grow(), and seems_valid.

Referenced by convert_addr_from_pdu(), init_smsbox_routes(), and octstr_convert_from_html_entities().

1480 {
1481  seems_valid(ostr);
1482  gw_assert(!ostr->immutable);
1483  gw_assert(pos <= ostr->len);
1484 
1485  octstr_grow(ostr, ostr->len + 1);
1486  if (ostr->len > pos)
1487  memmove(ostr->data + pos + 1, ostr->data + pos, ostr->len - pos);
1488  memcpy(ostr->data + pos, &c, 1);
1489  ostr->len += 1;
1490  ostr->data[ostr->len] = '\0';
1491 
1492  seems_valid(ostr);
1493 }
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_insert_data ( Octstr ostr,
long  pos,
const char *  data,
long  len 
)

Definition at line 1459 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, octstr_grow(), and seems_valid.

Referenced by bb_smscconn_send_failed(), bb_smscconn_sent(), cgw_encode_msg(), charset_latin1_to_gsm(), compare_octstr_sequence(), convert(), convert_gsm_to_cimd2(), http_header_split_auth_value(), line_append_hex_IA5(), msg_to_emimsg(), normalize_number(), octstr_append_char(), octstr_append_cstr(), octstr_append_data(), octstr_read_file(), octstr_symbolize(), pack_into_push_datagram(), pack_into_result_datagram(), packet_add_parm(), packet_set_checksum(), sema_encode_msg(), sema_msg_session_mt(), unescape_data(), unpack_credentials(), unpack_warning_value(), write_msg(), and wsp_pack_long_integer().

1460 {
1461  seems_valid(ostr);
1462  gw_assert(!ostr->immutable);
1463  gw_assert(pos <= ostr->len);
1464 
1465  if (len == 0)
1466  return;
1467 
1468  octstr_grow(ostr, ostr->len + len);
1469  if (ostr->len > pos) { /* only if neccessary*/
1470  memmove(ostr->data + pos + len, ostr->data + pos, ostr->len - pos);
1471  }
1472  memcpy(ostr->data + pos, data, len);
1473  ostr->len += len;
1474  ostr->data[ostr->len] = '\0';
1475 
1476  seems_valid(ostr);
1477 }
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_is_all_hex ( Octstr os)

Definition at line 2715 of file octstr.c.

References gw_isxdigit(), octstr_get_char(), octstr_len(), and seems_valid.

Referenced by main(), and push_content_create().

2716 {
2717  long len, i;
2718  int ch;
2719 
2720  seems_valid(os);
2721  len = octstr_len(os);
2722  for (i = 0; i < len; ++i) {
2723  ch = octstr_get_char(os, i);
2724  if (!gw_isxdigit(ch))
2725  return 0;
2726  }
2727 
2728  return 1;
2729 }
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
int gw_isxdigit(int c)
Definition: utils.c:994
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
int octstr_isnum ( Octstr ostr1)

Definition at line 2632 of file octstr.c.

References octstr_get_char(), octstr_len(), seems_valid, and start.

2633 {
2634  int start = 0;
2635  char c;
2636 
2637  seems_valid(ostr1);
2638  while (start < octstr_len(ostr1)) {
2639  c = octstr_get_char(ostr1, start);
2640  if (!isdigit(c) && (c!='+'))
2641  return 0;
2642  start++;
2643  }
2644  return 1;
2645 }
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
static int start
int octstr_item_case_match ( void *  item,
void *  pattern 
)

Definition at line 1665 of file octstr.c.

References octstr_case_compare().

Referenced by client_is_persistent().

1666 {
1667  return octstr_case_compare(item, pattern) == 0;
1668 }
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:901
int octstr_item_match ( void *  item,
void *  pattern 
)

Definition at line 1659 of file octstr.c.

References octstr_compare().

Referenced by at2_detect_modem_type(), at2_init_device(), cfg_read(), check_allowed_translation(), smsbox_req_handle(), and smscconn_usable().

1660 {
1661  return octstr_compare(item, pattern) == 0;
1662 }
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
long octstr_len ( const Octstr ostr)

Definition at line 340 of file octstr.c.

References Octstr::len, and seems_valid.

Referenced by add_crs(), add_msisdn(), add_network_info(), add_wsp_get(), append_string(), at2_check_sms_memory(), at2_convertpdu(), at2_decode7bituncompressed(), at2_detect_modem_type(), at2_encode7bituncompressed(), at2_encode8bituncompressed(), at2_extract_line(), at2_format_address_field(), at2_init_device(), at2_login_device(), at2_pdu_decode_deliver_sm(), at2_pdu_encode(), at2_pdu_extract(), at2_read_modems(), at2_scan_for_telnet_escapes(), at2_send_one_message(), at2_write_line(), bb_alog_sms(), begin_sar_result(), brunet_parse_body(), brunet_send_sms(), calculate_checksum(), cfg_read(), cgw_encode_msg(), cgw_read_op(), charset_convert(), charset_from_utf8(), charset_gsm_to_latin1(), charset_gsm_to_nrc_iso_21_german(), charset_gsm_to_utf8(), charset_gsm_truncate(), charset_latin1_to_gsm(), charset_nrc_iso_21_german_to_gsm(), charset_to_utf8(), charset_utf8_to_gsm(), check_data_content_type_header(), check_data_x_wap_application_id_header(), check_variable_syntax(), cid_matches(), cimd2_accept_message(), cimd_submit_msg(), clickatell_receive_sms(), clickatell_send_sms(), client_session(), compare_octstr_sequence(), concat_handling_check_and_handle(), conn_read_line(), conn_read_packet(), conn_write_withlen(), convert(), convert_addr_from_pdu(), convert_cimd2_to_gsm(), convert_content(), convert_gsm_to_cimd2(), convert_wmlscript_to_wmlscriptc(), copy_until_assign(), count_occurences(), data_sm_to_msg(), date_parse_http(), date_parse_iso(), decode_binary_data(), decode_integer(), deconvert_content(), deliver_after_test_cleared(), deliver_before_test_cleared(), dlr_add(), dlr_find(), dlr_mem_entry_match(), dlr_spool_add(), eat_checksum(), eat_int_parm(), eat_string_parm(), emi2_handle_smscreq(), emimsg_tostring(), encode_binary_data(), error_from_network_error_code(), escape_data(), escape_fragment(), expand_file(), extract_msgdata_part(), extract_msgdata_part_by_coding(), fields_to_dcs(), fill_message(), find_charset_encoding(), find_translation(), fix_boundary_element(), flag_date_length(), generic_receive_sms(), get_fields(), get_header_value(), get_mime_boundary(), get_msg_filename(), get_pattern(), get_start_param(), get_variable(), get_x_kannel_from_xml(), gsm2number(), handle_dlr(), handle_operation(), handle_pdu(), html_to_sms(), http_get_header_parameter(), http_header_add_element(), http_header_find_first_real(), http_header_get(), http_header_get_content_type(), http_header_mark_transformation(), http_header_pack(), http_header_quoted_string_len(), http_header_split_auth_value(), http_header_split_value(), http_header_value(), http_send_reply(), http_use_proxy(), httpd_remove_message(), httpd_serve(), init_bearerbox(), init_smsbox_routes(), is_allowed_ip(), is_default_cap(), is_token(), kannel_receive_sms(), kannel_send_sms(), line_append_hex_IA5(), main(), main_loop(), make_emi31(), md5(), meta_data_merge(), meta_data_pack(), meta_data_unpack(), mime_decompile(), mime_entity_dump_real(), mime_parse(), mime_something_to_entity(), msg_to_cgwop(), msg_to_emimsg(), msg_to_pdu(), normalize_charset(), normalize_number(), numhash_get_key(), obey_request(), obey_request_thread(), octstr_convert_to_html_entities(), octstr_delete_matching(), octstr_drop_trailing_zeros(), octstr_dump_debug(), octstr_hash_key(), octstr_is_all_hex(), octstr_isnum(), octstr_read_file(), octstr_replace(), octstr_replace_first(), octstr_search_chars(), octstr_shrink_blanks(), octstr_split(), octstr_strip_blanks(), octstr_strip_char(), octstr_strip_crlfs(), octstr_strip_nonalphanums(), ois_adjust_sm_text(), ois_append_msisdn(), ois_append_sm_text(), ois_append_submission_options(), oisd_accept_message(), oisd_expand_gsm7(), oisd_expand_gsm7_to_bits(), oisd_send_delivery_request(), oisd_shrink_gsm7(), open_send_connection(), ota_compile(), ota_pack_push_headers(), our_hash_func(), output_octet_string(), output_st_octet_string(), pack_7bit(), pack_cache_control(), pack_challenge(), pack_content_range(), pack_credentials(), pack_known_header(), pack_md5(), pack_parameter(), pack_quoted_string(), pack_range(), pack_server_address(), pack_tpis(), pack_warning(), packet_add_address_parm(), packet_add_parm(), packet_check(), packet_check_header(), packet_encode_message(), packet_extract(), packet_set_checksum(), packet_set_data_size(), pap_compile(), pap_request_thread(), parm_parse(), parm_valid_address(), parse_address(), parse_appid_header(), parse_array_element(), parse_attr_value(), parse_attribute(), parse_cgivars(), parse_charset(), parse_close_delimiter(), parse_constant(), parse_context_create(), parse_data(), parse_data_element(), parse_document(), parse_element(), parse_epilogue(), parse_fault_element(), parse_field_name(), parse_field_value(), parse_get_seperated_block(), parse_http_version(), parse_integer(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_msg_to_rawmessage(), parse_ota_syncsettings(), parse_param_element(), parse_params_element(), parse_st_octet_string(), parse_struct_element(), parse_tail(), parse_text(), parse_url(), parse_url_value(), parse_value(), parse_value_element(), parse_variable(), parse_xml_tag(), pass_data_headers(), pass_field_name(), pass_field_value(), pass_optional_header(), pattern_matches_ip(), pdu_to_msg(), prepend_catenation_udh(), radius_authenticate_pdu(), radius_pdu_pack(), radius_pdu_unpack(), read_line(), read_mime_headers(), read_msg(), read_some_headers(), receive_push_reply(), remove_crs(), remove_prefix(), replace_octstr_char(), response(), return_reply(), route_incoming_to_boxc(), sanitize_capabilities(), sema_encode_msg(), sema_msg_session_mt(), sema_receive_msg(), sema_submit_msg(), send_bad_message_response(), send_file(), send_message(), send_packet(), send_post(), send_request(), set_charset(), set_dlr_mask(), set_zero(), si_compile(), simple_binary_output(), skip_html_comment(), skip_html_tag(), skip_tail(), sl_compile(), smpp_pdu_pack(), smpp_pdu_unpack(), sms_charset_processing(), sms_msgdata_len(), sms_split(), sms_to_client(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_req_sendsms(), smsbox_sendota_post(), smsbox_sendsms_post(), smsc_at2_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_smpp_create(), soap_fetch_xml_data(), soap_format_xml(), soap_o2o_msgdata_attribute(), soap_read_date(), split_headers(), start_fetch(), start_push(), store_file_init(), store_file_load(), store_spool_save(), string_table_add(), string_table_add_many(), string_table_apply(), string_table_collect_strings(), string_table_output(), strip_prefix_and_suffix(), tokenize_date(), truncated_datagram(), udp_get_ip(), udp_get_port(), udp_sendto(), unescape_data(), unlocked_inbuf_len(), unlocked_outbuf_len(), unlocked_write(), unpack_broken_parameters(), unpack_credentials(), unpack_datagram(), unpack_new_headers(), unpack_parameter(), unpack_warning_value(), url_result_thread(), urltrans_fill_escape_codes(), urltrans_get_pattern(), wap_map_url(), wap_msg_recv(), wml_binary_output(), wml_compile(), write_data(), write_msg(), wsp_cap_pack_list(), wsp_cap_unpack_list(), wsp_headers_unpack(), wsp_pack_integer_string(), wsp_pack_list(), wsp_pack_long_integer(), wsp_pack_value(), wsp_pack_version_value(), wsp_strip_parameters(), wsp_unpack_well_known_field(), wtp_unpack_wdp_datagram(), xidris_send_sms(), and xmlrpc_doc_parse().

341 {
342  if (ostr == NULL)
343  return 0;
344  seems_valid(ostr);
345  return ostr->len;
346 }
#define seems_valid(ostr)
Definition: octstr.c:169
long len
Definition: octstr.c:121
int octstr_ncompare ( const Octstr ostr1,
const Octstr ostr2,
long  n 
)

Definition at line 950 of file octstr.c.

References Octstr::data, Octstr::len, and seems_valid.

Referenced by compare_octstr_sequence(), get_msg_filename(), http_header_get_content_type(), kannel_parse_reply(), pack_content_range(), pack_range(), packet_encode_message(), parse_attribute(), parse_close_delimiter(), parse_http_version(), remove_prefix(), and response().

951 {
952  long len;
953 
954  seems_valid(ostr1);
955  seems_valid(ostr2);
956 
957  if ((ostr1->len < ostr2->len) && (ostr1->len < n))
958  len = ostr1->len;
959  else if ((ostr2->len < ostr1->len) && (ostr2->len < n))
960  len = ostr2->len;
961  else
962  len = n;
963 
964  if (len == 0)
965  return 0;
966 
967  return memcmp(ostr1->data, ostr2->data, len);
968 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
long octstr_parse_double ( double *  number,
Octstr ostr,
long  pos 
)

Definition at line 780 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, number, and seems_valid.

Referenced by parse_value_element(), and smscconn_create().

781 {
782  /* strtod wants a char *, and we have to compare the result to
783  * an unsigned char *. The easiest way to avoid warnings without
784  * introducing typecasts is to use two variables. */
785  char *endptr;
786  unsigned char *endpos;
787  double number;
788 
789  seems_valid(ostr);
790  gw_assert(nump != NULL);
791 
792  if (pos >= ostr->len) {
793  errno = EINVAL;
794  return -1;
795  }
796 
797  errno = 0;
798  number = strtod(ostr->data + pos, &endptr);
799  endpos = endptr;
800  if (errno == ERANGE)
801  return -1;
802  if (endpos == ostr->data + pos) {
803  errno = EINVAL;
804  return -1;
805  }
806 
807  *nump = number;
808  return endpos - ostr->data;
809 }
int number
Definition: smsc_cimd2.c:213
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
long octstr_parse_long ( long *  number,
Octstr ostr,
long  pos,
int  base 
)

Definition at line 747 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, number, and seems_valid.

Referenced by at2_check_sms_memory(), at2_pdu_extract(), at2_read_pending_incoming_messages(), at2_wait_modem_command(), cfg_get_integer(), cgw_handle_op(), client_read_status(), convert_html_entity(), date_item_compare(), date_parse_http(), deduce_body_state(), eat_number(), eq_round_trip_time(), get_fields(), handle_operation(), init_bearerbox(), init_smsbox(), init_wapbox(), main(), pack_content_range(), pack_parameter(), pack_range_value(), pack_warning(), packet_check_parameter(), packet_get_int_parm(), packet_get_parm(), packet_parse_header(), parse_code(), parse_date(), parse_url(), parse_value_element(), pdu_to_msg(), read_chunked_body_len(), remove_long(), set_dlr_mask(), smsc_open(), soap_read_date(), wap_push_ppg_pushuser_authenticate(), and wsp_pack_version_value().

748 {
749  /* strtol wants a char *, and we have to compare the result to
750  * an unsigned char *. The easiest way to avoid warnings without
751  * introducing typecasts is to use two variables. */
752  char *endptr;
753  unsigned char *endpos;
754  long number;
755 
756  seems_valid(ostr);
757  gw_assert(nump != NULL);
758  gw_assert(base == 0 || (base >= 2 && base <= 36));
759 
760  if (pos >= ostr->len) {
761  errno = EINVAL;
762  return -1;
763  }
764 
765  errno = 0;
766  number = strtol(ostr->data + pos, &endptr, base);
767  endpos = endptr;
768  if (errno == ERANGE)
769  return -1;
770  if (endpos == ostr->data + pos) {
771  errno = EINVAL;
772  return -1;
773  }
774 
775  *nump = number;
776  return endpos - ostr->data;
777 }
int number
Definition: smsc_cimd2.c:213
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_pretty_print ( FILE *  f,
Octstr ostr 
)

Definition at line 1204 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by main().

1205 {
1206  unsigned char *p;
1207  long i;
1208 
1209  gw_assert(f != NULL);
1210  seems_valid(ostr);
1211 
1212  p = ostr->data;
1213  for (i = 0; i < ostr->len; ++i, ++p) {
1214  if (isprint(*p))
1215  fprintf(f, "%c", *p);
1216  else
1217  fprintf(f, "\\x%02x", *p);
1218  }
1219  if (ferror(f))
1220  return -1;
1221  return 0;
1222 }
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_print ( FILE *  f,
Octstr ostr 
)

Definition at line 1189 of file octstr.c.

References Octstr::data, error(), gw_assert(), Octstr::len, and seems_valid.

Referenced by client_thread(), main(), and write_msg().

1190 {
1191  gw_assert(f != NULL);
1192  seems_valid(ostr);
1193 
1194  if (ostr->len == 0)
1195  return 0;
1196  if (fwrite(ostr->data, ostr->len, 1, f) != 1) {
1197  error(errno, "Couldn't write all of octet string to file.");
1198  return -1;
1199  }
1200  return 0;
1201 }
void error(int err, const char *fmt,...)
Definition: log.c:612
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
Octstr* octstr_read_file ( const char *  filename)

Definition at line 1546 of file octstr.c.

References error(), gw_assert(), octstr_create, octstr_destroy(), octstr_insert_data(), and octstr_len().

Referenced by check_reversible(), dispatch(), expand_file(), get_msg_surrogate(), init_batch(), main(), obey_request(), post_content_create(), push_content_create(), send_file(), smsc_soap_create(), status_cb(), and store_file_load().

1547 {
1548  FILE *f;
1549  Octstr *os;
1550  char buf[4096];
1551  long n;
1552 
1553  gw_assert(filename != NULL);
1554 
1555  f = fopen(filename, "r");
1556  if (f == NULL) {
1557  error(errno, "fopen failed: couldn't open `%s'", filename);
1558  return NULL;
1559  }
1560 
1561  os = octstr_create("");
1562  if (os == NULL)
1563  goto error;
1564 
1565  while ((n = fread(buf, 1, sizeof(buf), f)) > 0)
1566  octstr_insert_data(os, octstr_len(os), buf, n);
1567 
1568  (void) fclose(f);
1569  return os;
1570 
1571 error:
1572  (void) fclose(f);
1573  octstr_destroy(os);
1574  return NULL;
1575 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1459
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
char filename[FILENAME_MAX+1]
Definition: log.c:135
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
Octstr* octstr_read_pipe ( FILE *  f)

Definition at line 1578 of file octstr.c.

References error(), gw_assert(), octstr_append_data(), octstr_create, and octstr_destroy().

Referenced by obey_request().

1579 {
1580  Octstr *os;
1581  char buf[4096];
1582 
1583  gw_assert(f != NULL);
1584 
1585  os = octstr_create("");
1586  if (os == NULL)
1587  goto error;
1588 
1589  while (fgets(buf, sizeof(buf), f) != NULL)
1590  octstr_append_data(os, buf, strlen(buf));
1591 
1592  return os;
1593 
1594 error:
1595  octstr_destroy(os);
1596  return NULL;
1597 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void octstr_append_data(Octstr *ostr, const char *data, long len)
Definition: octstr.c:1495
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
gw_assert(wtls_machine->packet_to_send!=NULL)
Definition: octstr.c:118
int octstr_recode ( Octstr tocode,
Octstr fromcode,
Octstr orig 
)

Definition at line 2574 of file octstr.c.

References charset_from_utf8(), charset_to_utf8(), octstr_append(), octstr_case_compare(), octstr_destroy(), octstr_duplicate, octstr_imm(), and octstr_truncate().

Referenced by obey_request_thread().

2575 {
2576  Octstr *octstr_utf8 = NULL;
2577  Octstr *octstr_final = NULL;
2578  int resultcode = 0;
2579 
2580  if (octstr_case_compare(tocode, fromcode) == 0) {
2581  goto cleanup_and_exit;
2582  }
2583 
2584  if ((octstr_case_compare(fromcode, octstr_imm ("UTF-8")) != 0) &&
2585  (octstr_case_compare(fromcode, octstr_imm ("UTF8")) != 0)) {
2586  if (charset_to_utf8(orig, &octstr_utf8, fromcode) < 0) {
2587  resultcode = -1;
2588  goto cleanup_and_exit;
2589  }
2590  } else {
2591  octstr_utf8 = octstr_duplicate(orig);
2592  }
2593 
2594  if ((octstr_case_compare(tocode, octstr_imm ("UTF-8")) != 0) &&
2595  (octstr_case_compare(tocode, octstr_imm ("UTF8")) != 0)) {
2596  if (charset_from_utf8(octstr_utf8, &octstr_final, tocode) < 0) {
2597  resultcode = -1;
2598  goto cleanup_and_exit;
2599  }
2600  } else {
2601  octstr_final = octstr_duplicate(octstr_utf8);
2602  }
2603 
2604  octstr_truncate(orig, 0);
2605  octstr_append(orig, octstr_final);
2606 
2607  cleanup_and_exit:
2608  octstr_destroy (octstr_utf8);
2609  octstr_destroy (octstr_final);
2610 
2611  return resultcode;
2612 }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1502
int charset_to_utf8(Octstr *from, Octstr **to, Octstr *charset_from)
Definition: charset.c:526
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
#define octstr_duplicate(ostr)
Definition: octstr.h:187
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:901
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
Definition: octstr.c:118
int charset_from_utf8(Octstr *utf8, Octstr **to, Octstr *charset_to)
Definition: charset.c:558
void octstr_truncate(Octstr *ostr, int new_len)
Definition: octstr.c:1325
void octstr_replace ( Octstr haystack,
Octstr needle,
Octstr repl 
)

Definition at line 2647 of file octstr.c.

References octstr_delete(), octstr_insert(), octstr_len(), and octstr_search().

Referenced by brunet_send_sms(), clickatell_send_sms(), main(), msg_to_pdu(), and xml_error().

2648 {
2649  int p = 0;
2650  long len, repl_len;
2651 
2652  len = octstr_len(needle);
2653  repl_len = octstr_len(repl);
2654 
2655  while ((p = octstr_search(haystack, needle, p)) != -1) {
2656  octstr_delete(haystack, p, len);
2657  octstr_insert(haystack, repl, p);
2658  p += repl_len;
2659  }
2660 }
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1068
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1301
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
void octstr_replace_first ( Octstr haystack,
Octstr needle,
Octstr repl 
)

Definition at line 2662 of file octstr.c.

References octstr_delete(), octstr_insert(), octstr_len(), and octstr_search().

2663 {
2664  int p = 0;
2665  long len, repl_len;
2666 
2667  len = octstr_len(needle);
2668  repl_len = octstr_len(repl);
2669 
2670  p = octstr_search(haystack, needle, p);
2671  if (p != -1) {
2672  octstr_delete(haystack, p, len);
2673  octstr_insert(haystack, repl, p);
2674  }
2675 }
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1068
void octstr_insert(Octstr *ostr1, const Octstr *ostr2, long pos)
Definition: octstr.c:1301
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
long octstr_rsearch_char ( const Octstr ostr,
int  ch,
long  pos 
)

Definition at line 1029 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

1030 {
1031  long i;
1032 
1033  seems_valid(ostr);
1034  gw_assert(ch >= 0);
1035  gw_assert(ch <= UCHAR_MAX);
1036  gw_assert(pos >= 0);
1037 
1038  if (pos >= ostr->len)
1039  return -1;
1040 
1041  for (i = pos; i >= 0; i--) {
1042  if (ostr->data[i] == ch)
1043  return i;
1044  }
1045 
1046  return -1;
1047 }
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
long octstr_search ( const Octstr haystack,
const Octstr needle,
long  pos 
)

Definition at line 1068 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, octstr_search_char(), and seems_valid.

Referenced by at2_check_sms_memory(), at2_detect_modem_type(), at2_extract_line(), at2_pdu_extract(), at2_wait_modem_command(), brunet_send_sms(), cfg_read(), cgw_decode_msg(), check_control_content_type_header(), check_data_content_type_header(), check_data_x_wap_application_id_header(), convert_addr_from_pdu(), count_occurences(), dlr_mem_entry_match(), drop_optional_header(), eat_string_parm(), find_charset_encoding(), get_msg_filename(), handle_dlr(), hash_cmp(), httpd_serve(), octstr_delete_matching(), octstr_replace(), octstr_replace_first(), octstr_split(), parse_appid_header(), parse_attr_value(), parse_body_part(), parse_entities(), parse_get_seperated_block(), parse_preamble(), parse_url_value(), parse_xml_tag(), pass_extension_headers(), pass_optional_header(), return_reply(), set_charset(), skip_html_comment(), string_table_apply(), and wap_push_ppg_pushuser_search_ip_from_wildcarded_list().

1069 {
1070  int first;
1071 
1072  seems_valid(haystack);
1073  seems_valid(needle);
1074  gw_assert(pos >= 0);
1075 
1076  /* Always "find" an empty string */
1077  if (needle->len == 0)
1078  return 0;
1079 
1080  if (needle->len == 1)
1081  return octstr_search_char(haystack, needle->data[0], pos);
1082 
1083  /* For each occurrence of needle's first character in ostr,
1084  * check if the rest of needle follows. Stop if there are no
1085  * more occurrences, or if the rest of needle can't possibly
1086  * fit in the haystack. */
1087  first = needle->data[0];
1088  pos = octstr_search_char(haystack, first, pos);
1089  while (pos >= 0 && haystack->len - pos >= needle->len) {
1090  if (memcmp(haystack->data + pos,
1091  needle->data, needle->len) == 0)
1092  return pos;
1093  pos = octstr_search_char(haystack, first, pos + 1);
1094  }
1095 
1096  return -1;
1097 }
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1010
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
long octstr_search_char ( const Octstr ostr,
int  ch,
long  pos 
)

Definition at line 1010 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, and seems_valid.

Referenced by at2_detect_modem_type(), at2_extract_line(), at2_init_device(), at2_read_pending_incoming_messages(), at2_scan_for_telnet_escapes(), cfg_read(), cgw_encode_msg(), cgw_read_op(), check_reversible(), check_variable_syntax(), client_read_status(), conn_read_line(), conn_read_packet(), copy_until_assign(), copy_until_coma(), copy_until_nul(), date_parse_http(), date_parse_iso(), decode_type(), eat_string_parm(), emi2_handle_smscreq(), extract_msgdata_part(), find_translation(), generic_init(), get_fields(), get_header_value(), get_variable(), handle_dlr(), header_is_called(), http_get_header_parameter(), http_header_get(), http_header_get_content_type(), http_header_value(), httpd_serve(), msg_to_bb(), octstr_convert_from_html_entities(), octstr_search(), octstr_search_chars(), octstr_str_search(), pack_credentials(), packet_check(), packet_extract(), packet_get_parm(), pap_compile(), parm_parse(), parse_address(), parse_attr_value(), parse_cgivars(), parse_charset(), parse_data(), parse_element(), parse_get_line(), parse_get_nul_string(), parse_st_octet_string(), parse_url(), read_line(), set_charset(), skip_html_tag(), skip_tail(), skip_until_after_colon(), soap_parse_dlr(), soap_parse_mo(), urltrans_fill_escape_codes(), wap_push_ppg_pushuser_search_ip_from_wildcarded_list(), wml_compile(), wrapper_sender(), wsp_cap_pack_list(), wsp_cap_unpack_list(), and wsp_strip_parameters().

1011 {
1012  unsigned char *p;
1013 
1014  seems_valid(ostr);
1015  gw_assert(ch >= 0);
1016  gw_assert(ch <= UCHAR_MAX);
1017  gw_assert(pos >= 0);
1018 
1019  if (pos >= ostr->len)
1020  return -1;
1021 
1022  p = memchr(ostr->data + pos, ch, ostr->len - pos);
1023  if (!p)
1024  return -1;
1025  return p - ostr->data;
1026 }
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
long octstr_search_chars ( const Octstr ostr,
const Octstr chars,
long  pos 
)

Definition at line 1050 of file octstr.c.

References gw_assert(), octstr_get_char(), octstr_len(), octstr_search_char(), and seems_valid.

Referenced by smsbox_req_handle().

1051 {
1052  long i, j;
1053 
1054  seems_valid(ostr);
1055  seems_valid(chars);
1056  gw_assert(pos >= 0);
1057 
1058  for (i = 0; i < octstr_len(chars); i++) {
1059  j = octstr_search_char(ostr, octstr_get_char(chars, i), pos);
1060  if (j != -1)
1061  return j;
1062  }
1063 
1064  return -1;
1065 }
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1010
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
void octstr_set_bits ( Octstr ostr,
long  bitpos,
int  numbits,
unsigned long  value 
)

Definition at line 1847 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, maxlen, octstr_grow(), and seems_valid.

Referenced by pack_server_address(), pack_tpis(), sanitize_capabilities(), set_user_ack(), tokenize_date(), and wtp_pack_set_rid().

1849 {
1850  long pos;
1851  unsigned long mask;
1852  int shiftwidth;
1853  int bits;
1854  int maxlen;
1855  int c;
1856 
1857  seems_valid(ostr);
1858  gw_assert(!ostr->immutable);
1859  gw_assert(bitpos >= 0);
1860  gw_assert(numbits <= 32);
1861  gw_assert(numbits >= 0);
1862 
1863  maxlen = (bitpos + numbits + 7) / 8;
1864  if (maxlen > ostr->len) {
1865  octstr_grow(ostr, maxlen);
1866  /* Make sure the new octets start out with value 0 */
1867  for (pos = ostr->len; pos < maxlen; pos++) {
1868  ostr->data[pos] = 0;
1869  }
1870  ostr->len = maxlen;
1871  ostr->data[maxlen] = 0;
1872  }
1873 
1874  mask = (1 << numbits) - 1;
1875  /* mask is also the largest value that fits */
1876  gw_assert(value <= mask);
1877 
1878  pos = bitpos / 8;
1879  bitpos = bitpos % 8;
1880 
1881  /* Does the range fit in one octet? */
1882  if (bitpos + numbits <= 8) {
1883  /* shiftwidth is the number of bits to ignore on the right.
1884  * bitpos 0 is the leftmost bit. */
1885  shiftwidth = 8 - (bitpos + numbits);
1886  /* Extract the bits we don't want to affect */
1887  c = ostr->data[pos] & ~(mask << shiftwidth);
1888  c |= value << shiftwidth;
1889  gw_assert(pos < ostr->len);
1890  ostr->data[pos] = c;
1891  return;
1892  }
1893 
1894  /* Otherwise... */
1895  /* If speed is a problem here, we could have separate cases for
1896  * the first octet (which may have bitpos > 0), and the rest,
1897  * which don't. */
1898  while (bitpos + numbits > 8) {
1899  /* We want this many bits from the value */
1900  bits = 8 - bitpos;
1901  /* There are this many bits to their right in the value */
1902  shiftwidth = numbits - bits;
1903  /* Construct a mask for "bits" bits on the far right */
1904  mask = (1 << bits) - 1;
1905  /* Get the bits we want */
1906  c = (value >> shiftwidth) & mask;
1907  /* Merge them with the bits that are already there */
1908  gw_assert(pos < ostr->len);
1909  ostr->data[pos] = (ostr->data[pos] & ~mask) | c;
1910  numbits -= (8 - bitpos);
1911  bitpos = 0;
1912  pos++;
1913  }
1914 
1915  gw_assert(bitpos == 0);
1916  gw_assert(pos < ostr->len);
1917  /* Set remaining bits. This is just like the single-octet case
1918  * before the loop, except that we know bitpos is 0. */
1919  mask = (1 << numbits) - 1;
1920  shiftwidth = 8 - numbits;
1921  c = ostr->data[pos] & ~(mask << shiftwidth);
1922  c |= value << shiftwidth;
1923  ostr->data[pos] = c;
1924 
1925  seems_valid(ostr);
1926 }
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
int maxlen
Definition: smsc_cimd2.c:214
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_set_char ( Octstr ostr,
long  pos,
int  ch 
)
void octstr_shrink_blanks ( Octstr ostr)

Definition at line 1431 of file octstr.c.

References gw_assert(), Octstr::immutable, octstr_delete(), octstr_get_char(), octstr_len(), octstr_set_char(), and seems_valid.

Referenced by html_to_sms(), ota_compile(), parse_text(), string_table_collect_strings(), and xmlrpc_doc_parse().

1432 {
1433  int i, j, end;
1434 
1435  seems_valid(text);
1436  gw_assert(!text->immutable);
1437 
1438  end = octstr_len(text);
1439 
1440  /* Shrink white spaces to one */
1441  for (i = 0; i < end; i++) {
1442  if (isspace(octstr_get_char(text, i))) {
1443  /* Change the remaining space into single space. */
1444  if (octstr_get_char(text, i) != ' ')
1445  octstr_set_char(text, i, ' ');
1446 
1447  j = i = i + 1;
1448  while (isspace(octstr_get_char(text, j)))
1449  j ++;
1450  if (j - i > 1)
1451  octstr_delete(text, i, j - i);
1452  }
1453  }
1454 
1455  seems_valid(text);
1456 }
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
char * text
Definition: smsc_cimd2.c:921
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
void octstr_set_char(Octstr *ostr, long pos, int ch)
Definition: octstr.c:413
void octstr_shutdown ( void  )

Definition at line 224 of file octstr.c.

References debug(), MAX_IMMUTABLES, and mutex_destroy().

Referenced by gwlib_shutdown().

225 {
226  long i, n;
227 
228  n = 0;
229  for (i = 0; i < MAX_IMMUTABLES; ++i) {
230  if (immutables[i] != NULL) {
231  gw_free(immutables[i]);
232  ++n;
233  }
234  }
235  if(n>0)
236  debug("gwlib.octstr", 0, "Immutable octet strings: %ld.", n);
238 }
#define MAX_IMMUTABLES
Definition: octstr.c:131
static Mutex immutables_mutex
Definition: octstr.c:134
static Octstr * immutables[MAX_IMMUTABLES]
Definition: octstr.c:133
void mutex_destroy(Mutex *mutex)
Definition: thread.c:97
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
List* octstr_split ( const Octstr os,
const Octstr sep 
)

Definition at line 1638 of file octstr.c.

References gwlist_append(), gwlist_create, octstr_copy, octstr_len(), and octstr_search().

Referenced by at2_detect_modem_type(), at2_init_device(), brunet_parse_body(), client_is_persistent(), create_onetrans(), expand_file(), init_batch(), init_reroute(), init_smsbox_routes(), main(), pattern_list_matches_ip(), prefix_allowed(), response(), smpp_pdu_init(), smsc_soap_create(), soap_create_map(), soap_fetch_xml_data(), soap_map_xml_data(), soap_release_dependences(), udp_start(), wap_push_ppg_pushuser_search_ip_from_wildcarded_list(), and wildcarded_ip_found().

1639 {
1640  List *list;
1641  long next, pos, seplen;
1642 
1643  list = gwlist_create();
1644  pos = 0;
1645  seplen = octstr_len(sep);
1646 
1647  while ((next = octstr_search(os, sep, pos)) >= 0) {
1648  gwlist_append(list, octstr_copy(os, pos, next - pos));
1649  pos = next + seplen;
1650  }
1651 
1652  if (pos < octstr_len(os))
1653  gwlist_append(list, octstr_copy(os, pos, octstr_len(os)));
1654 
1655  return list;
1656 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1068
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define gwlist_create()
Definition: list.h:136
Definition: list.c:102
List* octstr_split_words ( const Octstr ostr)

Definition at line 1600 of file octstr.c.

References Octstr::data, gwlist_append(), gwlist_create, octstr_create_from_data, seems_valid, and start.

Referenced by brunet_parse_body(), cfg_get_list(), clickatell_parse_body(), find_translation(), get_pattern(), parse_request_line(), randomize(), smsbox_req_handle(), soap_create_map(), soap_release_dependences(), string_table_collect_words(), urltrans_fill_escape_codes(), and wrapper_sender().

1601 {
1602  unsigned char *p;
1603  List *list;
1604  Octstr *word;
1605  long i, start, end;
1606 
1607  seems_valid(ostr);
1608 
1609  list = gwlist_create();
1610 
1611  p = ostr->data;
1612  i = 0;
1613  for (; ; ) {
1614  while (i < ostr->len && isspace(*p)) {
1615  ++p;
1616  ++i;
1617  }
1618  start = i;
1619 
1620  while (i < ostr->len && !isspace(*p)) {
1621  ++p;
1622  ++i;
1623  }
1624  end = i;
1625 
1626  if (start == end)
1627  break;
1628 
1629  word = octstr_create_from_data(ostr->data + start,
1630  end - start);
1631  gwlist_append(list, word);
1632  }
1633 
1634  return list;
1635 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
Definition: octstr.c:118
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
#define gwlist_create()
Definition: list.h:136
#define octstr_create_from_data(data, len)
Definition: octstr.h:134
Definition: list.c:102
static int start
int octstr_str_case_compare ( const Octstr ostr1,
const char *  str 
)

Definition at line 984 of file octstr.c.

References Octstr::data, and seems_valid.

Referenced by convert_addr_from_pdu(), get_x_kannel_from_xml(), meta_data_get_value(), meta_data_get_values(), meta_data_set_value(), meta_data_set_values(), msg_to_pdu(), and smpp_pdu_init().

985 {
986  seems_valid(ostr);
987 
988  if (str == NULL)
989  return -1;
990  if (ostr->data == NULL)
991  return strcasecmp("", str);
992 
993  return strcasecmp(ostr->data, str);
994 }
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_str_compare ( const Octstr ostr1,
const char *  str 
)
int octstr_str_ncompare ( const Octstr ostr,
const char *  str,
long  n 
)

Definition at line 997 of file octstr.c.

References Octstr::data, and seems_valid.

Referenced by cid_matches().

998 {
999  seems_valid(ostr);
1000 
1001  if (str == NULL)
1002  return -1;
1003  if (ostr->data == NULL)
1004  return 1; /* str grater */
1005 
1006  return strncmp(ostr->data, str, n);
1007 }
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long octstr_str_search ( const Octstr haystack,
const char *  needle,
long  pos 
)

Definition at line 1155 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::len, octstr_search_char(), and seems_valid.

1156 {
1157  int first;
1158  int needle_len;
1159 
1160  seems_valid(haystack);
1161  gw_assert(pos >= 0);
1162 
1163  /* Always "find" an empty string */
1164  if (needle == NULL || needle[0] == '\0')
1165  return 0;
1166 
1167  needle_len = strlen(needle);
1168 
1169  if (needle_len == 1)
1170  return octstr_search_char(haystack, needle[0], pos);
1171 
1172  /* For each occurrence of needle's first character in ostr,
1173  * check if the rest of needle follows. Stop if there are no
1174  * more occurrences, or if the rest of needle can't possibly
1175  * fit in the haystack. */
1176  first = needle[0];
1177  pos = octstr_search_char(haystack, first, pos);
1178  while (pos >= 0 && haystack->len - pos >= needle_len) {
1179  if (memcmp(haystack->data + pos,
1180  needle, needle_len) == 0)
1181  return pos;
1182  pos = octstr_search_char(haystack, first, pos + 1);
1183  }
1184 
1185  return -1;
1186 }
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1010
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_strip_blanks ( Octstr ostr)

Definition at line 1344 of file octstr.c.

References gw_assert(), Octstr::immutable, octstr_delete(), octstr_get_char(), octstr_len(), seems_valid, and start.

Referenced by at2_extract_line(), at2_format_address_field(), cfg_read(), deduce_body_state(), find_charset_encoding(), get_header_value(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), handle_dlr(), handle_transaction(), html_to_sms(), http_add_basic_auth(), http_get_header_parameter(), http_header_add_element(), http_header_find_first_real(), http_header_get(), http_header_get_content_type(), http_header_value(), init_reroute(), init_smsbox_routes(), ota_compile(), pack_challenge(), pack_credentials(), pack_known_header(), pap_compile(), parm_parse(), parse_text(), parse_value(), parse_xml_tag(), proxy_add_authentication(), response(), si_compile(), sl_compile(), smsbox_sendota_post(), smsbox_sendsms_post(), soap_map_xml_data(), soap_release_dependences(), string_table_collect_strings(), transform_message(), url_result_thread(), wml_compile(), wsp_pack_separate_content_type(), wsp_strip_parameters(), and xmlrpc_doc_parse().

1345 {
1346  int start = 0, end, len = 0;
1347 
1348  seems_valid(text);
1349  gw_assert(!text->immutable);
1350 
1351  /* Remove white space from the beginning of the text */
1352  while (isspace(octstr_get_char(text, start)) &&
1353  start <= octstr_len(text))
1354  start ++;
1355 
1356  if (start > 0)
1357  octstr_delete(text, 0, start);
1358 
1359  /* and from the end. */
1360 
1361  if ((len = octstr_len(text)) > 0) {
1362  end = len = len - 1;
1363  while (isspace(octstr_get_char(text, end)) && end >= 0)
1364  end--;
1365  octstr_delete(text, end + 1, len - end);
1366  }
1367 
1368  seems_valid(text);
1369 }
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
char * text
Definition: smsc_cimd2.c:921
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
static int start
void octstr_strip_char ( Octstr text,
char  ch 
)

Definition at line 2614 of file octstr.c.

References gw_assert(), Octstr::immutable, octstr_delete(), octstr_get_char(), octstr_len(), seems_valid, and start.

2615 {
2616  int start = 0;
2617 
2618  seems_valid(text);
2619  gw_assert(!text->immutable);
2620 
2621  /* Remove char from the beginning of the text */
2622  while ((ch == octstr_get_char(text, start)) &&
2623  start <= octstr_len(text))
2624  start ++;
2625 
2626  if (start > 0)
2627  octstr_delete(text, 0, start);
2628 
2629  seems_valid(text);
2630 }
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
static int start
void octstr_strip_crlfs ( Octstr ostr)

Definition at line 1376 of file octstr.c.

References gw_assert(), Octstr::immutable, iscrlf(), octstr_delete(), octstr_get_char(), octstr_len(), seems_valid, and start.

Referenced by init_batch(), main(), parse_get_line(), parse_xml_tag(), and soap_release_dependences().

1377 {
1378  int start = 0, end, len = 0;
1379 
1380  seems_valid(text);
1381  gw_assert(!text->immutable);
1382 
1383  /* Remove white space from the beginning of the text */
1384  while (iscrlf(octstr_get_char(text, start)) &&
1385  start <= octstr_len(text))
1386  start ++;
1387 
1388  if (start > 0)
1389  octstr_delete(text, 0, start);
1390 
1391  /* and from the end. */
1392 
1393  if ((len = octstr_len(text)) > 0) {
1394  end = len = len - 1;
1395  while (iscrlf(octstr_get_char(text, end)) && end >= 0)
1396  end--;
1397  octstr_delete(text, end + 1, len - end);
1398  }
1399 
1400  seems_valid(text);
1401 }
static int iscrlf(unsigned char c)
Definition: octstr.c:1371
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
char * text
Definition: smsc_cimd2.c:921
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
static int start
void octstr_strip_nonalphanums ( Octstr ostr)

Definition at line 1403 of file octstr.c.

References gw_assert(), Octstr::immutable, octstr_delete(), octstr_get_char(), octstr_len(), seems_valid, and start.

Referenced by string_table_collect_strings().

1404 {
1405  int start = 0, end, len = 0;
1406 
1407  seems_valid(text);
1408  gw_assert(!text->immutable);
1409 
1410  /* Remove white space from the beginning of the text */
1411  while (!isalnum(octstr_get_char(text, start)) &&
1412  start <= octstr_len(text))
1413  start ++;
1414 
1415  if (start > 0)
1416  octstr_delete(text, 0, start);
1417 
1418  /* and from the end. */
1419 
1420  if ((len = octstr_len(text)) > 0) {
1421  end = len = len - 1;
1422  while (!isalnum(octstr_get_char(text, end)) && end >= 0)
1423  end--;
1424  octstr_delete(text, end + 1, len - end);
1425  }
1426 
1427  seems_valid(text);
1428 }
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
char * text
Definition: smsc_cimd2.c:921
gw_assert(wtls_machine->packet_to_send!=NULL)
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
#define seems_valid(ostr)
Definition: octstr.c:169
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
static int start
int octstr_symbolize ( Octstr ostr)

Definition at line 2677 of file octstr.c.

References gw_assert(), gw_isxdigit(), Octstr::immutable, Octstr::len, octstr_check_range(), octstr_grow(), octstr_insert_data(), and seems_valid.

2678 {
2679  long len, i;
2680 
2681  seems_valid(ostr);
2682  gw_assert(!ostr->immutable);
2683 
2684  if (ostr->len == 0)
2685  return 0;
2686 
2687  /* Check if it's in the right format */
2688  if (!octstr_check_range(ostr, 0, ostr->len, gw_isxdigit))
2689  return -1;
2690 
2691  len = ostr->len + (ostr->len/2);
2692  octstr_grow(ostr, ostr->len * 2);
2693 
2694  for (i = 0; i < len; i += 3)
2695  octstr_insert_data(ostr, i, "%", 1);
2696 
2697  return 1;
2698 }
int octstr_check_range(Octstr *ostr, long pos, long len, octstr_func_t filter)
Definition: octstr.c:812
void octstr_insert_data(Octstr *ostr, long pos, const char *data, long len)
Definition: octstr.c:1459
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
static void octstr_grow(Octstr *ostr, long size)
Definition: octstr.c:181
#define seems_valid(ostr)
Definition: octstr.c:169
long len
Definition: octstr.c:121
int gw_isxdigit(int c)
Definition: utils.c:994
void octstr_truncate ( Octstr ostr,
int  new_len 
)

Definition at line 1325 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, Octstr::len, and seems_valid.

Referenced by at2_detect_modem_type(), at2_init_device(), at2_pdu_extract(), charset_convert(), charset_gsm_to_utf8(), charset_gsm_truncate(), charset_utf8_to_gsm(), check_variable_syntax(), client_read_status(), convert(), emi2_handle_smscreq(), get_x_kannel_from_xml(), http_header_get_content_type(), msg_to_emimsg(), octstr_recode(), packet_encode_message(), parse_cgivars(), parse_charset(), parse_st_octet_string(), parse_value(), parse_variable(), send_file(), smsc_cimd2_create(), string_table_apply(), and strip_prefix_and_suffix().

1326 {
1327  if (ostr == NULL)
1328  return;
1329 
1330  seems_valid(ostr);
1331  gw_assert(!ostr->immutable);
1332  gw_assert(new_len >= 0);
1333 
1334  if (new_len >= ostr->len)
1335  return;
1336 
1337  ostr->len = new_len;
1338  ostr->data[new_len] = '\0';
1339 
1340  seems_valid(ostr);
1341 }
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_url_decode ( Octstr ostr)

Definition at line 1744 of file octstr.c.

References code, Octstr::data, gw_assert(), H2B, Octstr::immutable, Octstr::len, seems_valid, and warning().

Referenced by brunet_send_sms(), get_x_kannel_from_headers(), get_x_kannel_from_xml(), meta_data_unpack(), msg_to_bb(), parse_cgivars(), soap_parse_dlr(), soap_parse_mo(), start_request(), and xidris_send_sms().

1745 {
1746  unsigned char *string;
1747  unsigned char *dptr;
1748  int code, code2, ret = 0;
1749 
1750  if (ostr == NULL)
1751  return 0;
1752 
1753  seems_valid(ostr);
1754  gw_assert(!ostr->immutable);
1755 
1756  if (ostr->len == 0)
1757  return 0;
1758 
1759  string = ostr->data;
1760  dptr = ostr->data;
1761 
1762  do {
1763  if (*string == '%') {
1764  if (*(string + 1) == '\0' || *(string + 2) == '\0') {
1765  warning(0, "octstr_url_decode: corrupted end-of-string <%s>", string);
1766  ret = -1;
1767  break;
1768  }
1769 
1770  code = H2B(*(string + 1));
1771  code2 = H2B(*(string + 2));
1772 
1773  if (code == -1 || code2 == -1) {
1774  warning(0, "octstr_url_decode: garbage detected (%c%c%c) skipping.",
1775  *string, *(string + 1), *(string + 2));
1776  *dptr++ = *string++;
1777  *dptr++ = *string++;
1778  *dptr++ = *string++;
1779  ret = -1;
1780  continue;
1781  }
1782 
1783  *dptr++ = code << 4 | code2;
1784  string += 3;
1785  }
1786  else if (*string == '+') {
1787  *dptr++ = ' ';
1788  string++;
1789  } else
1790  *dptr++ = *string++;
1791  } while (*string); /* we stop here because it terimates encoded string */
1792 
1793  *dptr = '\0';
1794  ostr->len = (dptr - ostr->data);
1795 
1796  seems_valid(ostr);
1797  return ret;
1798 }
#define H2B(a)
Definition: octstr.c:151
int code
Definition: smsc_cimd2.c:346
void warning(int err, const char *fmt,...)
Definition: log.c:624
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
void octstr_url_encode ( Octstr ostr)

Definition at line 1671 of file octstr.c.

References Octstr::data, gw_assert(), Octstr::immutable, is_safe, Octstr::len, seems_valid, and Octstr::size.

Referenced by convert(), main(), obey_request(), sms_to_client(), and urltrans_fill_escape_codes().

1672 {
1673  long i, n, len = 0;
1674  int all_safe;
1675  unsigned char c, *str, *str2, *res, *hexits;
1676 
1677  if (ostr == NULL)
1678  return;
1679 
1680  seems_valid(ostr);
1681  gw_assert(!ostr->immutable);
1682 
1683  if (ostr->len == 0)
1684  return;
1685 
1686  /* calculate new length */
1687  for (i = n = 0, str = ostr->data, all_safe = 1; i < ostr->len; i++) {
1688  c = *str++;
1689 
1690  if (c == ' ') {
1691  all_safe = 0;
1692  continue;
1693  }
1694 
1695  if (!is_safe[c]) {
1696  n++;
1697  all_safe = 0;
1698  }
1699  }
1700 
1701  if (all_safe) /* we are done, all chars are safe */
1702  return;
1703 
1704  hexits = "0123456789ABCDEF";
1705 
1706  /*
1707  * no need to reallocate if n == 0, so we make replace in place.
1708  * NOTE: we don't do if (xxx) ... else ... because conditional jump
1709  * is not so fast as just compare (alex).
1710  */
1711  res = str2 = (n ? gw_malloc((len = ostr->len + 2 * n + 1)) : ostr->data);
1712 
1713  for (i = 0, str = ostr->data; i < ostr->len; i++) {
1714  c = *str++;
1715 
1716  if (c == ' ') {
1717  *str2++ = '+';
1718  continue;
1719  }
1720 
1721  if (!is_safe[c]) {
1722  *str2++ = '%';
1723  *str2++ = hexits[c >> 4 & 0xf];
1724  *str2++ = hexits[c & 0xf];
1725  continue;
1726  }
1727 
1728  *str2++ = c;
1729  }
1730  *str2 = 0;
1731 
1732  /* we made replace in place */
1733  if (n) {
1734  gw_free(ostr->data);
1735  ostr->data = res;
1736  ostr->size = len;
1737  ostr->len = len - 1;
1738  }
1739 
1740  seems_valid(ostr);
1741 }
static char is_safe[UCHAR_MAX+1]
Definition: octstr.c:137
long size
Definition: octstr.c:122
int immutable
Definition: octstr.c:123
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
long octstr_write_data ( Octstr ostr,
int  fd,
long  from 
)

Definition at line 1253 of file octstr.c.

References Octstr::data, error(), gw_assert(), Octstr::len, and seems_valid.

Referenced by unlocked_write().

1254 {
1255  long ret;
1256 
1257  gw_assert(fd >= 0);
1258  gw_assert(from >= 0);
1259  seems_valid(ostr);
1260 
1261  if (from >= ostr->len)
1262  return 0;
1263 
1264  ret = write(fd, ostr->data + from, ostr->len - from);
1265 
1266  if (ret < 0) {
1267  if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
1268  return 0;
1269  error(errno, "Error writing %ld octets to fd %d:",
1270  ostr->len - from, fd);
1271  return -1;
1272  }
1273 
1274  return ret;
1275 }
void error(int err, const char *fmt,...)
Definition: log.c:612
static Octstr * from
Definition: mtbatch.c:95
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
int octstr_write_to_socket ( int  socket,
Octstr ostr 
)

Definition at line 1225 of file octstr.c.

References Octstr::data, error(), gw_assert(), Octstr::len, and seems_valid.

Referenced by cimd2_request(), cimd2_send_response(), oisd_request(), and oisd_send_response().

1226 {
1227  long len;
1228  unsigned char *data;
1229  int ret;
1230 
1231  gw_assert(socket >= 0);
1232  seems_valid(ostr);
1233 
1234  data = ostr->data;
1235  len = ostr->len;
1236  while (len > 0) {
1237  ret = write(socket, data, len);
1238  if (ret == -1) {
1239  if (errno != EINTR) {
1240  error(errno, "Writing to socket failed");
1241  return -1;
1242  }
1243  } else {
1244  /* ret may be less than len */
1245  len -= ret;
1246  data += ret;
1247  }
1248  }
1249  return 0;
1250 }
void error(int err, const char *fmt,...)
Definition: log.c:612
gw_assert(wtls_machine->packet_to_send!=NULL)
#define seems_valid(ostr)
Definition: octstr.c:169
unsigned char * data
Definition: octstr.c:120
long len
Definition: octstr.c:121
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.