Browse Source

turn tag and termination texts into array lookups

pull/81/head
Richard Fuchs 11 years ago
parent
commit
fb667a8dba
4 changed files with 33 additions and 21 deletions
  1. +15
    -0
      daemon/aux.h
  2. +16
    -18
      daemon/call.c
  3. +1
    -1
      daemon/call.h
  4. +1
    -2
      daemon/cli.c

+ 15
- 0
daemon/aux.h View File

@ -605,4 +605,19 @@ INLINE void atomic64_local_copy_zero(atomic64 *dst, atomic64 *src) {
INLINE const char *__get_enum_array_text(const char * const *array, unsigned int idx,
unsigned int len, const char *deflt)
{
const char *ret;
if (idx >= len)
return deflt;
ret = array[idx];
return ret ? : deflt;
}
#define get_enum_array_text(array, idx, deflt) \
__get_enum_array_text(array, idx, G_N_ELEMENTS(array), deflt)
#endif

+ 16
- 18
daemon/call.c View File

@ -119,22 +119,22 @@ const struct transport_protocol transport_protocols[] = {
};
const int num_transport_protocols = G_N_ELEMENTS(transport_protocols);
const char * get_term_reason_text(char *buf, enum termination_reason t) {
if (t==TIMEOUT) { buf = "TIMEOUT"; return buf; }
if (t==REGULAR) { buf = "REGULAR"; return buf; }
if (t==FORCED) { buf = "FORCED"; return buf; }
if (t==SILENT_TIMEOUT) { buf = "SILENT_TIMEOUT"; return buf; }
static const char * const __term_reason_texts[] = {
[TIMEOUT] = "TIMEOUT",
[REGULAR] = "REGULAR",
[FORCED] = "FORCED",
[SILENT_TIMEOUT] = "SILENT_TIMEOUT",
};
static const char * const __tag_type_texts[] = {
[FROM_TAG] = "FROM_TAG",
[TO_TAG] = "TO_TAG",
};
buf = "UNKNOWN";
return buf;
static const char * get_term_reason_text(enum termination_reason t) {
return get_enum_array_text(__term_reason_texts, t, "UNKNOWN");
}
const char * get_tag_type_text(char *buf, enum tag_type t) {
if (t==FROM_TAG) { buf = "FROM_TAG"; return buf; }
if (t==TO_TAG) { buf = "TO_TAG"; return buf; }
buf = "UNKNOWN";
return buf;
const char * get_tag_type_text(enum tag_type t) {
return get_enum_array_text(__tag_type_texts, t, "UNKNOWN");
}
static void determine_handler(struct packet_stream *in, const struct packet_stream *out);
@ -2431,8 +2431,6 @@ void call_destroy(struct call *c) {
GList *k, *o;
struct timeval tim_result_duration;
static const int CDRBUFLENGTH = 4096*2;
char reasonbuf[16]; memset(&reasonbuf,0,16);
char tagtypebuf[16]; memset(&tagtypebuf,0,16);
char cdrbuffer[CDRBUFLENGTH]; memset(&cdrbuffer,0,CDRBUFLENGTH);
char* cdrbufcur = cdrbuffer;
int cdrlinecnt = 0;
@ -2474,9 +2472,9 @@ void call_destroy(struct call *c) {
cdrlinecnt, ml->started.tv_sec, ml->started.tv_usec,
cdrlinecnt, ml->terminated.tv_sec, ml->terminated.tv_usec,
cdrlinecnt, tim_result_duration.tv_sec, tim_result_duration.tv_usec,
cdrlinecnt, get_term_reason_text(reasonbuf,ml->term_reason),
cdrlinecnt, get_term_reason_text(ml->term_reason),
cdrlinecnt, ml->tag.s,
cdrlinecnt, get_tag_type_text(tagtypebuf,ml->tagtype),
cdrlinecnt, get_tag_type_text(ml->tagtype),
cdrlinecnt, ml->active_dialogue ? ml->active_dialogue->tag.s : "(none)");
}


+ 1
- 1
daemon/call.h View File

@ -534,6 +534,6 @@ INLINE struct packet_stream *packet_stream_sink(struct packet_stream *ps) {
return ret;
}
const char * get_tag_type_text(char *buf, enum tag_type t);
const char * get_tag_type_text(enum tag_type t);
#endif

+ 1
- 2
daemon/cli.c View File

@ -100,7 +100,6 @@ static void cli_incoming_list_callid(char* buffer, int len, struct callmaster* m
GSList *l;
GList *k, *o;
int printlen=0;
char tagtypebuf[16]; memset(&tagtypebuf,0,16);
struct timeval tim_result_duration; memset(&tim_result_duration,0,sizeof(struct timeval));
struct timeval now; memset(&now,0,sizeof(struct timeval));
@ -134,7 +133,7 @@ static void cli_incoming_list_callid(char* buffer, int len, struct callmaster* m
timeval_subtract(&tim_result_duration,&now,&ml->started);
printlen = snprintf(replybuffer,(outbufend-replybuffer), "--- Tag '"STR_FORMAT"' type: %s, callduration "
"%ld.%06ld , in dialogue with '"STR_FORMAT"'\n",
STR_FMT(&ml->tag), get_tag_type_text(tagtypebuf,ml->tagtype),
STR_FMT(&ml->tag), get_tag_type_text(ml->tagtype),
tim_result_duration.tv_sec,
tim_result_duration.tv_usec,
ml->active_dialogue ? ml->active_dialogue->tag.len : 6,


Loading…
Cancel
Save