📄 su_taglist.c
字号:
{ if (!src) return dst; else if (dst) { return t_dup(dst, src, bb); } else { dst = (tagi_t *)((char *)dst + t_len(src)); *bb = (char *)*bb + t_xtra(src, (size_t)*bb); return dst; }} tag_class_t any_tag_class[1] = {{ sizeof(any_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ NULL, /* tc_filter */ t_any_filter, /* tc_ref_set */ NULL, /* tc_scan */ NULL, }};/** Any tag - match any tag when filtering. */tag_typedef_t tag_any = TAG_TYPEDEF(tag_any, any);/* ====================================================================== *//* ns tag - match to any tag with same namespace when filtering */statictagi_t *t_ns_filter(tagi_t *dst, tagi_t const filter[], tagi_t const *src, void **bb){ char const *match, *ns; if (!src) return dst; assert(filter); match = TAG_TYPE_OF(filter)->tt_ns; ns = TAG_TYPE_OF(src)->tt_ns; if (match == NULL) /* everything matches with this */; else if (match == ns) /* namespaces matche */; else if (ns == NULL) /* no match */ return dst; else if (strcmp(match, ns)) /* no match */ return dst; if (dst) { return t_dup(dst, src, bb); } else { dst = (tagi_t *)((char *)dst + t_len(src)); *bb = (char *)*bb + t_xtra(src, (size_t)*bb); return dst; }}/** Namespace filtering class */ tag_class_t ns_tag_class[1] = {{ sizeof(ns_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ NULL, /* tc_filter */ t_ns_filter, /* tc_ref_set */ NULL, /* tc_scan */ NULL, }};/* ====================================================================== *//* int tag - pass integer value */int t_int_snprintf(tagi_t const *t, char b[], size_t size){ return snprintf(b, size, "%i", (int)t->t_value);}int t_int_ref_set(tag_type_t tt, void *ref, tagi_t const value[]){ *(int *)ref = (int)value->t_value; return 1;}int t_int_scan(tag_type_t tt, su_home_t *home, char const *s, tag_value_t *return_value){ int value; char *rest; value = strtol(s, &rest, 0); if (s != rest) { *return_value = (tag_value_t)value; return 1; } else { *return_value = (tag_value_t)0; return -1; }}tag_class_t int_tag_class[1] = {{ sizeof(int_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_int_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_int_ref_set, /* tc_scan */ t_int_scan, }};/* ====================================================================== *//* uint tag - pass unsigned integer value */int t_uint_snprintf(tagi_t const *t, char b[], size_t size){ return snprintf(b, size, "%u", (unsigned)t->t_value);}int t_uint_ref_set(tag_type_t tt, void *ref, tagi_t const value[]){ *(unsigned *)ref = (unsigned)value->t_value; return 1;}int t_uint_scan(tag_type_t tt, su_home_t *home, char const *s, tag_value_t *return_value){ unsigned value; char *rest; value = strtoul(s, &rest, 0); if (s != rest) { *return_value = (tag_value_t)value; return 1; } else { *return_value = (tag_value_t)0; return -1; }}tag_class_t uint_tag_class[1] = {{ sizeof(int_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_uint_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_uint_ref_set, /* tc_scan */ t_uint_scan, }};/* ====================================================================== *//* size tag - pass size_t value @NEW_1_12_5 */staticint t_size_snprintf(tagi_t const *t, char b[], size_t size){ return snprintf(b, size, MOD_ZU, (size_t)t->t_value);}staticint t_size_ref_set(tag_type_t tt, void *ref, tagi_t const value[]){ *(size_t *)ref = (size_t)value->t_value; return 1;}staticint t_size_scan(tag_type_t tt, su_home_t *home, char const *s, tag_value_t *return_value){ unsigned longlong value; char *rest; value = strtoull(s, &rest, 0); if (s != rest && value <= SIZE_MAX) { *return_value = (tag_value_t)value; return 1; } else { *return_value = (tag_value_t)0; return -1; }}/** Tag class for tags with size_t value. @NEW_1_12_5. */tag_class_t size_tag_class[1] = {{ sizeof(int_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_size_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_size_ref_set, /* tc_scan */ t_size_scan, }};/* ====================================================================== *//* usize tag - pass usize_t value */staticint t_usize_ref_set(tag_type_t tt, void *ref, tagi_t const value[]){ *(usize_t *)ref = (usize_t)value->t_value; return 1;}staticint t_usize_scan(tag_type_t tt, su_home_t *home, char const *s, tag_value_t *return_value){ unsigned longlong value; char *rest; value = strtoull(s, &rest, 0); if (s != rest && value <= USIZE_MAX) { *return_value = (tag_value_t)value; return 1; } else { *return_value = (tag_value_t)0; return -1; }}/** Tag class for tags with usize_t value. @NEW_1_12_5. */tag_class_t usize_tag_class[1] = {{ sizeof(int_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_size_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_usize_ref_set, /* tc_scan */ t_usize_scan, }};/* ====================================================================== *//* bool tag - pass boolean value */int t_bool_snprintf(tagi_t const *t, char b[], size_t size){ return snprintf(b, size, "%s", t->t_value ? "true" : "false");}int t_bool_ref_set(tag_type_t tt, void *ref, tagi_t const value[]){ *(int *)ref = (value->t_value != 0); return 1;}int t_bool_scan(tag_type_t tt, su_home_t *home, char const *s, tag_value_t *return_value){ int retval; int value = 0; if (strncasecmp(s, "true", 4) == 0 && strlen(s + 4) == strspn(s + 4, " \t\r\n")) { value = 1, retval = 1; } else if (strncasecmp(s, "false", 5) == 0 && strlen(s + 5) == strspn(s + 5, " \t\r\n")) { value = 0, retval = 1; } else { retval = t_int_scan(tt, home, s, return_value); value = *return_value != 0; } if (retval == 1) *return_value = (tag_value_t)value; else *return_value = (tag_value_t)0; return retval;}tag_class_t bool_tag_class[1] = {{ sizeof(bool_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_bool_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_bool_ref_set, /* tc_scan */ t_bool_scan, }};/* ====================================================================== *//* ptr tag - pass pointer value */int t_ptr_snprintf(tagi_t const *t, char b[], size_t size){ return snprintf(b, size, "%p", (void *)t->t_value);}int t_ptr_ref_set(tag_type_t tt, void *ref, tagi_t const value[]){ *(void **)ref = (void *)value->t_value; return 1;}/* This is not usually very safe, so it is not used */int t_ptr_scan(tag_type_t tt, su_home_t *home, char const *s, tag_value_t *return_value){ int retval; void *ptr; retval = sscanf(s, "%p", &ptr); if (retval == 1) *return_value = (tag_value_t)ptr; else *return_value = (tag_value_t)NULL; return retval;}tag_class_t ptr_tag_class[1] = {{ sizeof(ptr_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_ptr_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_ptr_ref_set, /* tc_scan */ NULL, }};/* ====================================================================== *//* socket tag - pass socket */#include <sofia-sip/su.h>int t_socket_snprintf(tagi_t const *t, char b[], size_t size){ /* socket can be int or DWORD (or QWORD on win64?) */ return snprintf(b, size, LLI, (longlong)t->t_value);}int t_socket_ref_set(tag_type_t tt, void *ref, tagi_t const value[]){ *(su_socket_t *)ref = (su_socket_t)value->t_value; return 1;}tag_class_t socket_tag_class[1] = {{ sizeof(socket_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_socket_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_socket_ref_set, /* tc_scan */ NULL, }};/* ====================================================================== *//* str tag - pass string value */int t_str_snprintf(tagi_t const *t, char b[], size_t size){ if (t->t_value) return snprintf(b, size, "\"%s\"", (char const *)t->t_value); else return snprintf(b, size, "<null>");}int t_str_scan(tag_type_t tt, su_home_t *home, char const *s, tag_value_t *return_value){ int retval; s = su_strdup(home, s); if (s) *return_value = (tag_value_t)s, retval = 1; else *return_value = (tag_value_t)NULL, retval = -1; return retval;}tagi_t *t_str_dup(tagi_t *dst, tagi_t const *src, void **bb){ dst->t_tag = src->t_tag; if (src->t_value) { char const *s = (char const *)src->t_value; size_t len = strlen(s) + 1; dst->t_value = (tag_value_t)strcpy(*bb, s); *bb = (char *)*bb + len; } else dst->t_value = (tag_value_t)0; return dst + 1;}size_t t_str_xtra(tagi_t const *t, size_t offset){ return t->t_value ? strlen((char *)t->t_value) + 1 : 0;}tag_class_t str_tag_class[1] = {{ sizeof(str_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ t_str_xtra, /* tc_dup */ t_str_dup, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_str_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_ptr_ref_set, /* tc_scan */ t_str_scan, }};/* ====================================================================== *//* cstr tag - pass constant string value (no need to dup) *//** Tag class for constant strings */tag_class_t cstr_tag_class[1] = {{ sizeof(cstr_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_str_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_ptr_ref_set, /* tc_scan */ t_str_scan, }};/* ====================================================================== *//* ref tag - pass reference */tag_class_t ref_tag_class[1] = {{ sizeof(ref_tag_class), /* tc_next */ NULL, /* tc_len */ NULL, /* tc_move */ NULL, /* tc_xtra */ NULL, /* tc_dup */ NULL, /* tc_free */ NULL, /* tc_find */ NULL, /* tc_snprintf */ t_ptr_snprintf, /* tc_filter */ NULL, /* tc_ref_set */ t_ptr_ref_set, /* tc_scan */ NULL, }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -