Defines | Functions

ut.h File Reference

various general purpose/helper functions. More...

#include "comp_defs.h"
#include <sys/types.h>
#include <sys/select.h>
#include <sys/time.h>
#include <limits.h>
#include <time.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "compiler_opt.h"
#include "config.h"
#include "dprint.h"
#include "str.h"
#include "mem/mem.h"
#include "mem/shm_mem.h"
#include "config.h"
Include dependency graph for ut.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

Functions


Detailed Description

Definition in file ut.h.


Function Documentation

char* get_abs_pathname ( str base,
str file 
)

This function returns the full pathname of a file in parameter. If the file pathname does not start with / then it will be converted into an absolute pathname. The function gets the absolute directory pathname from base and appends file to it. The first parameter can be NULL, in this case the function will use the location of the main SER configuration file as reference.

Parameters:
base filename to be used as reference when file is relative. It must be absolute. The location of the SER configuration file will be used as reference if you set the value of this parameter to NULL.
file A pathname to be converted to absolute.
Returns:
A string containing absolute pathname, the string must be freed with free. NULL on error.

Converts relative pathnames to absolute pathnames.

Parameters:
base - base file, used to extract the absolute path prefix. Might be NULL, in which case the path of the ser.cfg is used.
file - file path to be transformed. If it's already absolute (starts with '/') is left alone. If not the result will be `dirname base`/file.
Returns:
pkg allocated asciiz string or 0 on error.

Definition at line 218 of file ut.c.

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

Referenced by cfg_parser_init(), fix_initial_pathname(), fix_rel_pathname(), and fix_shm_pathname().

Here is the caller graph for this function:

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

This version uses a static buffer (shared with sint2str()). WARNING: other function calls might overwrite the static buffer, so either always save the result immediately or use int2strbuf(...).

Parameters:
l - unsigned long to be converted/printed.
*len - will be filled with the final length (without the terminating 0).
Returns:
a pointer to a static buffer containing l in asciiz & sets len.

Definition at line 335 of file ut.h.

References int2strbuf().

Referenced by build_contact(), build_fault_reply(), create_via(), db_postgres_new_connection(), gen_cmd_name(), get_marker(), get_str_fparam(), http_xmlrpc2sip(), internal_mi_print_dlg(), mi_add_aor_node(), mi_get_profile(), mi_usrloc_dump(), print_value(), pv_get_dlg_lifetime(), pv_get_dlg_status(), pv_get_uintval(), pv_set_mcd_value(), sst_dialog_mi_context_CB(), tls_domain_str(), tr_eval_line(), tr_eval_nameaddr(), tr_eval_paramlist(), and tr_eval_string().

Here is the call graph for this function:

Here is the caller graph for this function:

static char* int2strbuf ( unsigned long  l,
char *  r,
int  r_size,
int *  len 
) [inline, static]

Converts/prints an unsigned long to a string. The result buffer must be provided and its length must be at least INT2STR_MAX_LEN.

Parameters:
l - unsigned long to be converted
r - pointer to result buffer
r_size - result buffer size, must be at least INT2STR_MAX_LEN.
*len - length of the written string, _without_ the terminating 0.
Returns:
pointer _inside_ r, to the converted string (note: the string is written from the end of the buffer and not from the start and hence the returned pointer will most likely not be equal to r). In case of error it returns 0 (the only error being insufficient provided buffer size).

Definition at line 302 of file ut.h.

Referenced by int2str(), and sint2strbuf().

Here is the caller graph for this function:

static int pkg_str_dup ( str dst,
const str src 
) [inline, static]
Parameters:
dst destination
src source
Returns:
0 on success, -1 on failure

Definition at line 718 of file ut.h.

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

Referenced by pv_get_mcd_value().

Here is the caller graph for this function:

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

This version uses a static buffer, shared with int2str(). WARNING: other function calls might overwrite the static buffer, so either always save the result immediately or use sint2strbuf(...).

Parameters:
l - long to be converted/printed.
*len - will be filled with the final length (without the terminating 0).
Returns:
a pointer to a static buffer containing l in asciiz & sets len.

Definition at line 385 of file ut.h.

References sint2strbuf().

Referenced by get_string(), print_value(), and pv_get_sintval().

Here is the call graph for this function:

Here is the caller graph for this function:

static char* sint2strbuf ( long  l,
char *  r,
int  r_size,
int *  len 
) [inline, static]

Converts a long to a signed string. The result buffer must be provided and its length must be at least INT2STR_MAX_LEN.

Parameters:
l - long to be converted
r - pointer to result buffer
r_size - result buffer size, must be at least INT2STR_MAX_LEN.
*len - length of the written string, _without_ the terminating 0.
Returns:
pointer _inside_ r, to the converted string (note: the string is written from the end of the buffer and not from the start and hence the returned pointer will most likely not be equal to r). In case of error it returns 0 (the only error being insufficient provided buffer size).

Definition at line 354 of file ut.h.

References int2strbuf().

Referenced by rval_get_tmp_str(), and sint2str().

Here is the call graph for this function:

Here is the caller graph for this function:

char* str_search ( str text,
str needle 
)

search for needle in text

Returns:
pointer to start of needle in text or NULL if the needle is not found

Definition at line 284 of file ut.c.

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

static int str_strcasecmp ( const str str1,
const str str2 
) [inline, static]
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 760 of file ut.h.

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

Referenced by get_fifo_opts(), and load_config().

Here is the caller graph for this function:

static int str_strcmp ( const str str1,
const str str2 
) [inline, static]
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 738 of file ut.h.

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

Referenced by map_name2id(), and set_next_domain_on_rule().

Here is the caller graph for this function: