ut.h File Reference

Various utility functions, mostly related to string handling. More...

#include <sys/types.h>
#include <sys/select.h>
#include <sys/time.h>
#include <limits.h>
#include <unistd.h>
#include <ctype.h>
#include <strings.h>
#include "config.h"
#include "dprint.h"
#include "str.h"
#include "mem/mem.h"
#include "mem/shm_mem.h"

Include dependency graph for ut.h:

Go to the source code of this file.

Defines

#define append_chr(_dest, _c)   *((_dest)++) = _c;
#define append_str(_dest, _src, _len)
#define INT2STR_MAX_LEN   (1+19+1+1)
#define MAX(a, b)   (a>b?a:b)
#define MIN(a, b)   (a<b?a:b)
#define str_init(_string)   {_string, sizeof(_string) - 1}
#define translate_pointer(_new_buf, _org_buf, _p)   ( (_p)?(_new_buf + (_p-_org_buf)):(0) )
#define trim_len(_len, _begin, _mystr)
#define trim_r(_mystr)
#define trim_spaces_lr(_s_)
#define via_len(_via)
#define ZSW(_c)   ((_c)?(_c):"")

Functions

int group2gid (int *gid, char *group)
 Converts a groupname into gid value.
static int hex2int (char hex_digit)
static int hexstr2int (char *c, int len, unsigned int *val)
static char * int2bstr (unsigned long l, char *s, int *len)
static int int2reverse_hex (char **c, int *size, int nr)
static char * int2str (unsigned long l, int *len)
static int pathmax (void)
static int pkg_str_dup (str *dst, const str *src)
static int reverse_hex2int (char *c, int len)
void seed_child (unsigned int seed)
static int shm_str_dup (str *dst, const str *src)
static char * sint2str (long l, int *len)
static void sleep_us (unsigned int nusecs)
static int str2int (str *_s, unsigned int *_r)
static unsigned short str2s (const char *s, unsigned int len, int *err)
 Converts a str to an unsigned short.
static int str2sint (str *_s, int *_r)
static int str_strcasecmp (const str *str1, const str *str2)
 Compare two str's case insensitive.
static int str_strcmp (const str *str1, const str *str2)
 Compare two str's case sensitive.
static int string2hex (unsigned char *str, int len, char *hex)
static void strlower (str *_s)
static int strno2int (str *val, unsigned int *mask)
static int un_escape (str *user, str *new_user)
int user2uid (int *uid, int *gid, char *user)
 Converts a username into uid and gid values.

Variables

static char fourbits2char [16]
char int2str_buf [INT2STR_MAX_LEN]


Detailed Description

Various utility functions, mostly related to string handling.

Definition in file ut.h.


Define Documentation

#define append_chr ( _dest,
_c   )     *((_dest)++) = _c;

append _c char to _dest string

Definition at line 113 of file ut.h.

Referenced by assemble_msg(), check_our_gws(), encode_avp_value(), encode_branch_info(), and generate_uris().

#define append_str ( _dest,
_src,
_len   ) 

#define INT2STR_MAX_LEN   (1+19+1+1)

#define MAX ( a,
 )     (a>b?a:b)

#define MIN ( a,
 )     (a<b?a:b)

#define str_init ( _string   )     {_string, sizeof(_string) - 1}

#define translate_pointer ( _new_buf,
_org_buf,
_p   )     ( (_p)?(_new_buf + (_p-_org_buf)):(0) )

Definition at line 95 of file ut.h.

Referenced by auth_body_cloner(), sip_msg_cloner(), uri_trans(), via_body_cloner(), and xlate_pointers().

#define trim_len ( _len,
_begin,
_mystr   ) 

returns string beginning and length without insignificant chars

Definition at line 62 of file ut.h.

Referenced by check_content_type(), extract_mediainfo(), extract_mediaip(), extract_rtcp(), get_sock_hdr(), is_maxfwd_present(), MD5StringArray(), run_language_switch(), run_priority_switch(), and run_string_switch().

#define trim_r ( _mystr   ) 

right space trimming

Definition at line 77 of file ut.h.

Referenced by get_hdr_field().

#define trim_spaces_lr ( _s_   ) 

Value:

do{\
      for(;(_s_).s[(_s_).len-1]==' ';(_s_).s[--(_s_).len]=0);\
      for(;(_s_).s[0]==' ';(_s_).s=(_s_).s+1,(_s_).len--);\
   }while(0);
right and left space trimming

Definition at line 87 of file ut.h.

Referenced by add_code_to_array(), and add_profile_definitions().

#define via_len ( _via   ) 

Value:

((_via)->bsize-((_via)->name.s-\
      ((_via)->hdr.s+(_via)->hdr.len)))
via length

Definition at line 100 of file ut.h.

Referenced by assemble_via(), build_dlg_ack(), build_local(), build_req_buf_from_sip_req(), build_res_buf_from_sip_res(), build_uac_cancel(), and via_builder().

#define ZSW ( _c   )     ((_c)?(_c):"")


Function Documentation

int group2gid ( int *  gid,
char *  group 
)

Converts a groupname into gid value.

Parameters:
gid group id
group group name
Returns:
-1 on error, 0 on success

Definition at line 80 of file ut.c.

Referenced by main(), and mi_mod_init().

static int hex2int ( char  hex_digit  )  [inline, static]

Definition at line 338 of file ut.h.

References LM_ERR.

Referenced by decode_mail_url(), and un_escape().

static int hexstr2int ( char *  c,
int  len,
unsigned int *  val 
) [inline, static]

Definition at line 266 of file ut.h.

Referenced by parse_intstr_value(), and strno2int().

static char* int2bstr ( unsigned long  l,
char *  s,
int *  len 
) [inline, static]

Definition at line 178 of file ut.h.

References INT2STR_MAX_LEN, and LM_CRIT.

Referenced by env_set_code_status(), int2str(), legs2strar(), print_content_length(), and print_cseq_num().

static int int2reverse_hex ( char **  c,
int *  size,
int  nr 
) [inline, static]

static char* int2str ( unsigned long  l,
int *  len 
) [inline, static]

Definition at line 200 of file ut.h.

References int2bstr(), and int2str_buf.

Referenced by add_mi_sdp_nodes(), add_mi_sdp_payload_nodes(), add_mi_session_nodes(), add_mi_stream_nodes(), add_retry_after(), assemble_msg(), bla_process_body(), build_contact(), build_res_buf_from_sip_req(), build_str_hdr(), check_our_gws(), clen_builder(), constr_rlmi_doc(), create_rcv_uri(), db_postgres_new_connection(), dbrow2avp(), dlg2hash(), do_load_gws(), do_uac_auth(), ds_print_mi_list(), encode_avp_value(), encode_branch_info(), fix_socket_list(), force_rtp_proxy(), get_name(), get_wi_notify_body(), imc_mi_list_members(), imc_mi_list_rooms(), init_acc_extra(), init_extra_engine(), int_str2db_val(), internal_mi_print_dlg(), mi_add_aor_node(), mi_datagram_write_tree(), mi_get_pipes(), mi_get_profile(), mi_get_queues(), mi_print_blacklists(), mi_print_gws(), mi_print_lcrs(), mi_ps(), mi_show_rtpproxies(), mi_stats(), mi_tm_hash(), mi_usrloc_dump(), mi_write_tree(), ops_copy_avp(), ops_pushto_avp(), parse_avp_db(), publ_build_hdr(), pv_get_dlg_count(), pv_get_dlg_lifetime(), pv_get_dlg_status(), pv_get_random_val(), pv_get_tm_branch_idx(), pv_get_tm_reply_code(), pv_get_uintval(), rl_timer(), rport_builder(), send_2XX_reply(), send_sip_options_request(), set_body_f(), sint2str(), sip_trace(), sst_dialog_mi_context_CB(), subs_build_hdr(), t_check_status(), timer_send_notify(), tlsops_bits(), tlsops_cert_version(), tlsops_sn(), trace_onreply_in(), trace_onreply_out(), trace_onreq_out(), trace_sl_onreply_out(), and use_media_proxy().

static int pathmax ( void   )  [inline, static]

Definition at line 324 of file ut.h.

References PATH_MAX_GUESS.

Referenced by get_name(), and mi_pwd().

static int pkg_str_dup ( str dst,
const str src 
) [inline, static]

Definition at line 515 of file ut.h.

References _str::len, LM_ERR, NULL, pkg_malloc, and _str::s.

Referenced by parse_avp_db().

static int reverse_hex2int ( char *  c,
int  len 
) [inline, static]

Definition at line 227 of file ut.h.

Referenced by forward_reply(), parse_dlg_rr_param(), and t_reply_matching().

void seed_child ( unsigned int  seed  ) 

utility function to give each children a unique seed

Definition at line 102 of file ut.c.

Referenced by internal_fork().

static int shm_str_dup ( str dst,
const str src 
) [inline, static]

static char* sint2str ( long  l,
int *  len 
) [inline, static]

Definition at line 208 of file ut.h.

References int2str().

Referenced by comp_strval(), mi_debug(), and pv_get_sintval().

static void sleep_us ( unsigned int  nusecs  )  [inline, static]

static int str2int ( str _s,
unsigned int *  _r 
) [inline, static]

static unsigned short str2s ( const char *  s,
unsigned int  len,
int *  err 
) [inline, static]

Converts a str to an unsigned short.

Returns:
the unsigned short, or zero on error, sets *err to 1 on error if err is != 0

Definition at line 134 of file ut.h.

References init(), and LM_DBG.

Referenced by avp2timer(), check_memory(), dp_trans_fixup(), fetchsms(), fixup_maxfwd_header(), fixup_set_id(), fixup_stat(), fixup_var_str_int(), get_nr_max(), is_maxfwd_present(), mi_translate(), parse_db_url(), parse_via(), seas_init(), set_modem_arg(), set_network_arg(), start_stats_server(), and update_sock_struct_from_via().

static int str2sint ( str _s,
int *  _r 
) [inline, static]

Definition at line 457 of file ut.h.

References _str::len, _str::s, and s.

Referenced by fixup_igp(), get_fifo_opts(), h350_call_preferences(), ldap_write_result(), mi_debug(), and parse_intstr_value().

static int str_strcasecmp ( const str str1,
const str str2 
) [inline, static]

Compare two str's case insensitive.

Parameters:
str1 first str
str2 second str
Returns:
0 if both are equal, positive if str1 is greater, negative if str2 is greater, -2 on errors

Definition at line 557 of file ut.h.

References _str::len, LM_ERR, NULL, and _str::s.

Referenced by get_fifo_opts(), and load_config().

static int str_strcmp ( const str str1,
const str str2 
) [inline, static]

Compare two str's case sensitive.

Parameters:
str1 first str
str2 second str
Returns:
0 if both are equal, positive if str1 is greater, negative if str2 is greater, -2 on errors

Definition at line 535 of file ut.h.

References _str::len, LM_ERR, NULL, and _str::s.

Referenced by carrier_data_fixup(), find_rule_by_host(), map_name2id(), pdt_add_to_tree(), pdt_get_domain(), pdt_get_tree(), and set_next_domain_on_rule().

static int string2hex ( unsigned char *  str,
int  len,
char *  hex 
) [inline, static]

Definition at line 287 of file ut.h.

References fourbits2char.

Referenced by calc_nonce(), compute_md5(), MD5File(), and MD5StringArray().

static void strlower ( str _s  )  [inline, static]

Definition at line 424 of file ut.h.

References _str::len, and _str::s.

Referenced by cpl_init(), extract_aor(), and mi_fix_aor().

static int strno2int ( str val,
unsigned int *  mask 
) [inline, static]

static int un_escape ( str user,
str new_user 
) [inline, static]

Definition at line 364 of file ut.h.

References hex2int(), _str::len, LM_CRIT, LM_ERR, and _str::s.

Referenced by authorize(), and extract_aor().

int user2uid ( int *  uid,
int *  gid,
char *  user 
)

Converts a username into uid and gid values.

Parameters:
uid user id
gid group id, set to null if you don't want this
user username
Returns:
-1 on error, 0 on success

Definition at line 51 of file ut.c.

Referenced by main(), and mi_mod_init().


Variable Documentation

char fourbits2char[16] [static]

Initial value:

 { '0', '1', '2', '3', '4', '5',
   '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }
char to hex conversion table

Definition at line 125 of file ut.h.

Referenced by string2hex().

char int2str_buf[INT2STR_MAX_LEN]

buffer for int2str

Definition at line 41 of file ut.c.

Referenced by int2str().


Generated on Thu May 24 22:00:46 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6