RTS API Documentation
1.10.11
|
#include <switch.h>
Go to the source code of this file.
Data Structures | |
struct | et_info |
struct | sgMprintf |
Macros | |
#define | LONGDOUBLE_TYPE long double |
#define | etRADIX 1 /* Integer types. %d, %x, %o, and so forth */ |
#define | etFLOAT 2 /* Floating point. %f */ |
#define | etEXP 3 /* Exponentional notation. %e and %E */ |
#define | etGENERIC 4 /* Floating or exponential, depending on exponent. %g */ |
#define | etSIZE 5 /* Return number of characters processed so far. %n */ |
#define | etSTRING 6 /* Strings. %s */ |
#define | etDYNSTRING 7 /* Dynamically allocated strings. %z */ |
#define | etPERCENT 8 /* Percent symbol. %% */ |
#define | etCHARX 9 /* Characters. %c */ |
#define | etCHARLIT 10 /* Literal characters. %' */ |
#define | etSQLESCAPE 11 /* Strings with '\'' doubled. %q */ |
#define | etSQLESCAPE2 |
#define | etPOINTER 15 /* The %p conversion */ |
#define | etSQLESCAPE3 16 |
#define | etSQLESCAPE4 17 |
#define | FLAG_SIGNED 1 /* True if the value to convert is signed */ |
#define | FLAG_INTERN 2 /* True if for internal use only */ |
#define | FLAG_STRING 4 /* Allow infinity precision */ |
#define | etNINFO (sizeof(fmtinfo)/sizeof(fmtinfo[0])) |
#define | SWITCH_PRINT_BUF_SIZE 350 |
#define | etBUFSIZE SWITCH_PRINT_BUF_SIZE /* Size of the output buffer */ |
#define | etSPACESIZE (sizeof(spaces)-1) |
Typedefs | |
typedef unsigned char | etByte |
typedef struct et_info | et_info |
Functions | |
static int | et_getdigit (LONGDOUBLE_TYPE *val, int *cnt) |
static int | vxprintf (void(*func)(void *, const char *, int), void *arg, int useExtended, const char *fmt, va_list ap) |
static void | mout (void *arg, const char *zNewText, int nNewChar) |
static char * | base_vprintf (void *(*xRealloc)(void *, int), int useInternal, char *zInitBuf, int nInitBuf, const char *zFormat, va_list ap) |
static void * | printf_realloc (void *old, int size) |
char * | switch_vmprintf (const char *zFormat, va_list ap) |
char * | switch_mprintf (const char *zFormat,...) |
char * | switch_snprintfv (char *zBuf, int n, const char *zFormat,...) |
Variables | |
static const char | aDigits [] = "0123456789ABCDEF0123456789abcdef" |
static const char | aPrefix [] = "-x0\000X0" |
static const et_info | fmtinfo [] |
#define etBUFSIZE SWITCH_PRINT_BUF_SIZE /* Size of the output buffer */ |
Definition at line 195 of file switch_mprintf.c.
Referenced by vxprintf().
#define etCHARLIT 10 /* Literal characters. %' */ |
Definition at line 79 of file switch_mprintf.c.
Referenced by vxprintf().
#define etCHARX 9 /* Characters. %c */ |
Definition at line 77 of file switch_mprintf.c.
Referenced by vxprintf().
#define etDYNSTRING 7 /* Dynamically allocated strings. %z */ |
Definition at line 75 of file switch_mprintf.c.
Referenced by vxprintf().
#define etEXP 3 /* Exponentional notation. %e and %E */ |
Definition at line 71 of file switch_mprintf.c.
Referenced by vxprintf().
#define etFLOAT 2 /* Floating point. %f */ |
Definition at line 70 of file switch_mprintf.c.
Referenced by vxprintf().
#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */ |
Definition at line 72 of file switch_mprintf.c.
Referenced by vxprintf().
Definition at line 153 of file switch_mprintf.c.
Referenced by vxprintf().
#define etPERCENT 8 /* Percent symbol. %% */ |
Definition at line 76 of file switch_mprintf.c.
Referenced by vxprintf().
#define etPOINTER 15 /* The %p conversion */ |
Definition at line 87 of file switch_mprintf.c.
Referenced by vxprintf().
#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */ |
Definition at line 69 of file switch_mprintf.c.
Referenced by vxprintf().
#define etSIZE 5 /* Return number of characters processed so far. %n */ |
Definition at line 73 of file switch_mprintf.c.
Referenced by vxprintf().
#define etSPACESIZE (sizeof(spaces)-1) |
Referenced by vxprintf().
#define etSQLESCAPE 11 /* Strings with '\'' doubled. %q */ |
Definition at line 80 of file switch_mprintf.c.
Referenced by vxprintf().
#define etSQLESCAPE2 |
Definition at line 81 of file switch_mprintf.c.
Referenced by vxprintf().
#define etSQLESCAPE3 16 |
Definition at line 88 of file switch_mprintf.c.
Referenced by vxprintf().
#define etSQLESCAPE4 17 |
Definition at line 89 of file switch_mprintf.c.
Referenced by vxprintf().
#define etSTRING 6 /* Strings. %s */ |
Definition at line 74 of file switch_mprintf.c.
Referenced by vxprintf().
#define FLAG_INTERN 2 /* True if for internal use only */ |
Definition at line 113 of file switch_mprintf.c.
Referenced by vxprintf().
Definition at line 112 of file switch_mprintf.c.
Referenced by vxprintf().
#define FLAG_STRING 4 /* Allow infinity precision */ |
Definition at line 114 of file switch_mprintf.c.
Referenced by vxprintf().
#define LONGDOUBLE_TYPE long double |
Definition at line 63 of file switch_mprintf.c.
Referenced by et_getdigit(), and vxprintf().
#define SWITCH_PRINT_BUF_SIZE 350 |
Definition at line 193 of file switch_mprintf.c.
Referenced by switch_mprintf(), and switch_vmprintf().
typedef unsigned char etByte |
Definition at line 94 of file switch_mprintf.c.
|
static |
Definition at line 847 of file switch_mprintf.c.
References mout(), sgMprintf::nAlloc, sgMprintf::nChar, sgMprintf::nTotal, vxprintf(), sgMprintf::xRealloc, sgMprintf::zBase, and sgMprintf::zText.
Referenced by switch_mprintf(), switch_snprintfv(), and switch_vmprintf().
|
static |
Definition at line 173 of file switch_mprintf.c.
References LONGDOUBLE_TYPE.
Referenced by vxprintf().
|
static |
Definition at line 811 of file switch_mprintf.c.
References sgMprintf::nAlloc, sgMprintf::nChar, sgMprintf::nTotal, sgMprintf::xRealloc, sgMprintf::zBase, and sgMprintf::zText.
Referenced by base_vprintf().
|
static |
Definition at line 880 of file switch_mprintf.c.
Referenced by switch_mprintf(), and switch_vmprintf().
char* switch_mprintf | ( | const char * | zFormat, |
... | |||
) |
This routine is a variant of the "sprintf()" from the standard C library. The resulting string is written into memory obtained from malloc() so that there is never a possiblity of buffer overflow. This routine also implement some additional formatting options that are useful for constructing SQL statements.
The strings returned by this routine should be freed by calling free().
All of the usual printf formatting options apply. In addition, there is a "%q" option. q works like s in that it substitutes a null-terminated string from the argument list. But q also doubles every '\'' character. q is designed for use inside a string literal. By doubling each '\'' character it escapes that character and allows it to be inserted into the string.
For example, so some string variable contains text as follows:
char *zText = "It's a happy day!";
We can use this text in an SQL statement as follows:
char *z = switch_mprintf("INSERT INTO TABLES('%q')", zText); switch_core_db_exec(db, z, callback1, 0, 0); free(z);
Because the q format string is used, the '\'' character in zText is escaped and the SQL generated is as follows:
INSERT INTO table1 VALUES('It''s a happy day!')
This is correct. Had we used s instead of q, the generated SQL would have looked like this:
INSERT INTO table1 VALUES('It's a happy day!');
This second example is an SQL syntax error. As a general rule you should always use q instead of s when inserting text into a string literal.
Definition at line 897 of file switch_mprintf.c.
References base_vprintf(), printf_realloc(), SWITCH_PRINT_BUF_SIZE, and sgMprintf::zBase.
Referenced by core_event_handler(), fst_init_core_and_modload(), load_mime_types(), msrp_msg_serialize(), preprocess_glob(), Event::serialize(), setup_ringback(), switch_channel_export_variable_var_check(), switch_console_complete(), switch_console_expand_alias(), switch_console_list_uuid(), switch_console_save_history(), switch_console_set_alias(), switch_core_add_registration(), switch_core_cert_gen_fingerprint(), switch_core_check_dtls_pem(), switch_core_del_registration(), switch_core_expire_registration(), switch_core_file_close(), switch_core_gen_certs(), switch_core_media_negotiate_sdp(), switch_core_recovery_flush(), switch_core_recovery_recover(), switch_core_recovery_track(), switch_core_recovery_untrack(), switch_core_session_exec(), switch_format_number(), switch_ivr_parse_event(), switch_ivr_wait_for_answer(), switch_jwt_sign(), switch_load_network_lists(), switch_loadable_module_enumerate_available(), switch_loadable_module_load_file(), switch_log_node_to_json(), switch_network_port_range_to_string(), switch_odbc_handle_get_error(), switch_play_and_get_digits(), switch_process_import(), switch_simple_email(), switch_stream_write_file_contents(), switch_xml_parse_file(), and tone_detect_set_total_time().
char* switch_snprintfv | ( | char * | zBuf, |
int | n, | ||
const char * | zFormat, | ||
... | |||
) |
Definition at line 914 of file switch_mprintf.c.
References base_vprintf().
Referenced by do_trans(), parse_presence_data_cols(), switch_cache_db_execute_sql_callback(), switch_cache_db_execute_sql_callback_err(), switch_cache_db_execute_sql_event_callback(), switch_cache_db_execute_sql_event_callback_err(), switch_cache_db_persistant_execute_trans_full(), switch_cache_db_test_reactive_ex(), and switch_core_sqldb_start().
char* switch_vmprintf | ( | const char * | zFormat, |
va_list | ap | ||
) |
Definition at line 888 of file switch_mprintf.c.
References base_vprintf(), printf_realloc(), SWITCH_PRINT_BUF_SIZE, and sgMprintf::zBase.
Referenced by cJSON_CreateStringPrintf(), and switch_console_stream_write().
|
static |
Definition at line 224 of file switch_mprintf.c.
References aDigits, aPrefix, et_info::base, buf, et_info::charset, count, et_getdigit(), etBUFSIZE, etCHARLIT, etCHARX, etDYNSTRING, etEXP, etFLOAT, etGENERIC, etNINFO, etPERCENT, etPOINTER, etRADIX, etSIZE, etSPACESIZE, etSQLESCAPE, etSQLESCAPE2, etSQLESCAPE3, etSQLESCAPE4, etSTRING, FLAG_INTERN, FLAG_SIGNED, FLAG_STRING, et_info::flags, fmt, et_info::fmttype, if(), length, LONGDOUBLE_TYPE, et_info::prefix, and et_info::type.
Referenced by base_vprintf().
|
static |
Definition at line 121 of file switch_mprintf.c.
Referenced by vxprintf().
|
static |
Definition at line 122 of file switch_mprintf.c.
Referenced by vxprintf().
|
static |
Definition at line 123 of file switch_mprintf.c.