Mercurial > hg > freeDiameter
comparison include/freeDiameter/libfdproto.h @ 1093:44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 06 May 2013 16:33:22 +0800 |
parents | 1d1a20a0779d |
children | 4d2dcb54d9a6 |
comparison
equal
deleted
inserted
replaced
1092:e40374ddfeef | 1093:44f3e48dfe27 |
---|---|
219 * int : Success or failure | 219 * int : Success or failure |
220 */ | 220 */ |
221 int fd_log_handler_unregister ( void ); | 221 int fd_log_handler_unregister ( void ); |
222 | 222 |
223 | 223 |
224 /* Helper functions for the *dump functions that add into a buffer */ | 224 /* All dump functions follow this same prototype: |
225 char * fd_dump_extend(char ** buf, size_t *len, size_t *offset, const char * format, ... ) _ATTRIBUTE_PRINTFLIKE_(4,5); | 225 * PARAMETERS: |
226 char * fd_dump_extend_hexdump(char ** buf, size_t *len, size_t *offset, uint8_t *data, size_t datalen, size_t trunc, size_t wrap ); | 226 * buf : *buf can be NULL on entry, it will be malloc'd. Otherwise it is realloc'd if needed. |
227 | |
228 /* All dump functions follow the same prototype: | |
229 * PARAMETERS: | |
230 * buf : *buf can be NULL on entry, it will be malloc'd. Otherwise it can be realloc'd if needed. | |
231 * len : the current size of the buffer (in/out) | 227 * len : the current size of the buffer (in/out) |
232 * offset: (optional) if provided, starts writing dump at offset in the buffer, and updated upon exit. if NULL, starts at offset O. | 228 * offset: (optional) if provided, starts writing dump at offset in the buffer, and updated upon exit. if NULL, starts at offset O. |
233 * | 229 * |
234 * RETURN VALUE: | 230 * RETURN VALUE: |
235 * *buf upon success, NULL upon failure. | 231 * *buf upon success, NULL upon failure. |
236 * After the buffer has been used, it should be freed. | 232 * |
233 * REMARKS: | |
234 * - After the buffer has been used, it should be freed. | |
235 * - Depending on the function, the created string may be multi-line. However, it should never be terminated with a '\n'. | |
237 */ | 236 */ |
238 #define DECLARE_FD_DUMP_PROTOTYPE( function_name, args... ) \ | 237 #define DECLARE_FD_DUMP_PROTOTYPE( function_name, args... ) \ |
239 char * function_name(char ** buf, size_t *len, size_t *offset, ##args) | 238 char * function_name(char ** buf, size_t *len, size_t *offset, ##args) |
240 | 239 |
240 | |
241 /* Helper functions for the *dump functions that add into a buffer */ | |
242 DECLARE_FD_DUMP_PROTOTYPE( fd_dump_extend, const char * format, ... ) _ATTRIBUTE_PRINTFLIKE_(4,5); | |
243 DECLARE_FD_DUMP_PROTOTYPE( fd_dump_extend_hexdump, uint8_t *data, size_t datalen, size_t trunc, size_t wrap ); | |
244 | |
245 | |
246 /* Some helpers macro for writing such *_dump routine */ | |
241 #define FD_DUMP_STD_PARAMS buf, len, offset | 247 #define FD_DUMP_STD_PARAMS buf, len, offset |
248 #define FD_DUMP_HANDLE_OFFSET() size_t o = 0; if (!offset) offset = &o | |
249 #define FD_DUMP_HANDLE_TRAIL() while ((*buf) && (*offset > 0) && ((*buf)[*offset - 1] == '\n')) { *offset -= 1; (*buf)[*offset] = '\0'; } | |
250 | |
242 | 251 |
243 | 252 |
244 /*============================================================*/ | 253 /*============================================================*/ |
245 /* DEBUG MACROS */ | 254 /* DEBUG MACROS */ |
246 /*============================================================*/ | 255 /*============================================================*/ |
1013 | 1022 |
1014 /* The criteria for searching a vendor object in the dictionary */ | 1023 /* The criteria for searching a vendor object in the dictionary */ |
1015 enum { | 1024 enum { |
1016 VENDOR_BY_ID = 10, /* "what" points to a vendor_id_t */ | 1025 VENDOR_BY_ID = 10, /* "what" points to a vendor_id_t */ |
1017 VENDOR_BY_NAME, /* "what" points to a char * */ | 1026 VENDOR_BY_NAME, /* "what" points to a char * */ |
1018 VENDOR_OF_APPLICATION /* "what" points to a struct dict_object containing an application (see below) */ | 1027 VENDOR_OF_APPLICATION, /* "what" points to a struct dict_object containing an application (see below) */ |
1028 VENDOR_OF_AVP, /* "what" points to a struct dict_object containing an avp (see below) */ | |
1019 }; | 1029 }; |
1020 | 1030 |
1021 /*** | 1031 /*** |
1022 * API usage : | 1032 * API usage : |
1023 | 1033 |
1402 #define AVP_FLAG_RESERVED6 0x04 | 1412 #define AVP_FLAG_RESERVED6 0x04 |
1403 #define AVP_FLAG_RESERVED7 0x02 | 1413 #define AVP_FLAG_RESERVED7 0x02 |
1404 #define AVP_FLAG_RESERVED8 0x01 | 1414 #define AVP_FLAG_RESERVED8 0x01 |
1405 | 1415 |
1406 /* For dumping flags and values */ | 1416 /* For dumping flags and values */ |
1407 #define DUMP_AVPFL_str "%c%c" | 1417 #define DUMP_AVPFL_str "%c%c%s%s%s%s%s%s" |
1408 #define DUMP_AVPFL_val(_val) (_val & AVP_FLAG_VENDOR)?'V':'-' , (_val & AVP_FLAG_MANDATORY)?'M':'-' | 1418 #define DUMP_AVPFL_val(_val) (_val & AVP_FLAG_VENDOR)?'V':'-' , (_val & AVP_FLAG_MANDATORY)?'M':'-', \ |
1419 (_val & AVP_FLAG_RESERVED3)?"3":"", (_val & AVP_FLAG_RESERVED4)?"4":"", \ | |
1420 (_val & AVP_FLAG_RESERVED5)?"5":"", (_val & AVP_FLAG_RESERVED6)?"6":"", (_val & AVP_FLAG_RESERVED7)?"7":"", (_val & AVP_FLAG_RESERVED8)?"8":"" | |
1409 | 1421 |
1410 /* Type to hold data associated to an avp */ | 1422 /* Type to hold data associated to an avp */ |
1411 struct dict_avp_data { | 1423 struct dict_avp_data { |
1412 avp_code_t avp_code; /* Code of the avp */ | 1424 avp_code_t avp_code; /* Code of the avp */ |
1413 vendor_id_t avp_vendor; /* Vendor of the AVP, or 0 */ | 1425 vendor_id_t avp_vendor; /* Vendor of the AVP, or 0 */ |
1552 #define CMD_FLAG_RESERVED6 0x04 | 1564 #define CMD_FLAG_RESERVED6 0x04 |
1553 #define CMD_FLAG_RESERVED7 0x02 | 1565 #define CMD_FLAG_RESERVED7 0x02 |
1554 #define CMD_FLAG_RESERVED8 0x01 | 1566 #define CMD_FLAG_RESERVED8 0x01 |
1555 | 1567 |
1556 /* For dumping flags and values */ | 1568 /* For dumping flags and values */ |
1557 #define DUMP_CMDFL_str "%c%c%c%c" | 1569 #define DUMP_CMDFL_str "%c%c%c%c%s%s%s%s" |
1558 #define DUMP_CMDFL_val(_val) (_val & CMD_FLAG_REQUEST)?'R':'-' , (_val & CMD_FLAG_PROXIABLE)?'P':'-' , (_val & CMD_FLAG_ERROR)?'E':'-' , (_val & CMD_FLAG_RETRANSMIT)?'T':'-' | 1570 #define DUMP_CMDFL_val(_val) (_val & CMD_FLAG_REQUEST)?'R':'-' , (_val & CMD_FLAG_PROXIABLE)?'P':'-' , (_val & CMD_FLAG_ERROR)?'E':'-' , (_val & CMD_FLAG_RETRANSMIT)?'T':'-', \ |
1571 (_val & CMD_FLAG_RESERVED5)?"5":"", (_val & CMD_FLAG_RESERVED6)?"6":"", (_val & CMD_FLAG_RESERVED7)?"7":"", (_val & CMD_FLAG_RESERVED8)?"8":"" | |
1559 | 1572 |
1560 /* Type to hold data associated to a command */ | 1573 /* Type to hold data associated to a command */ |
1561 struct dict_cmd_data { | 1574 struct dict_cmd_data { |
1562 command_code_t cmd_code; /* code of the command */ | 1575 command_code_t cmd_code; /* code of the command */ |
1563 char * cmd_name; /* Name of the command */ | 1576 char * cmd_name; /* Name of the command */ |