Index: cel/cel_adaptive_odbc.c =================================================================== --- cel/cel_adaptive_odbc.c (revision 202004) +++ cel/cel_adaptive_odbc.c (working copy) @@ -352,43 +352,15 @@ char colbuf[1024], *colptr; SQLHSTMT stmt = NULL; SQLLEN rows = 0; - enum ast_cel_event_type eventtype; - const char *userdefname = 0; - struct timeval eventtime = {0}; - const char *cid_ani, *cid_rdnis, *cid_name, *cid_num, *cid_dnid; - const char *exten, *context, *channame, *appname, *appdata, *accountcode, *peeraccount, *uniqueid, *linkedid, *userfield, *peer; - unsigned int amaflag; + struct ast_cel_event_record *record = ast_cel_fill_record(event); - if (!sql || !sql2) { + if (!sql || !sql2 || !record) { if (sql) ast_free(sql); if (sql2) ast_free(sql2); return; } - eventtype = ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TYPE); - eventtime.tv_sec = ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME); - eventtime.tv_usec = ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC); - if (eventtype == AST_CEL_USER_DEFINED) { - userdefname = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_USEREVENT_NAME); - } - cid_name = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CIDNAME); - cid_num = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CIDNUM); - cid_ani = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CIDANI); - cid_rdnis = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CIDRDNIS); - cid_dnid = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CIDDNID); - exten = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_EXTEN); - context = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CONTEXT); - channame = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CHANNAME); - appname = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_APPNAME); - appdata = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_APPDATA); - accountcode = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_ACCTCODE); - peeraccount = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_ACCTCODE); - uniqueid = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_UNIQUEID); - linkedid = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_LINKEDID); - amaflag = ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_AMAFLAGS); - userfield = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_USERFIELD); - peer = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_PEER); if (AST_RWLIST_RDLOCK(&odbc_tables)) { ast_log(LOG_ERROR, "Unable to lock table list. Insert CEL(s) failed.\n"); @@ -418,48 +390,48 @@ if (entry->staticvalue) { colptr = ast_strdupa(entry->staticvalue); } else if (datefield) { - struct timeval date_tv = eventtime; + struct timeval date_tv = record->event_time; struct ast_tm tm = { 0, }; ast_localtime(&date_tv, &tm, tableptr->usegmtime ? "UTC" : NULL); ast_strftime(colbuf, sizeof(colbuf), "%Y-%m-%d %H:%M:%S", &tm); colptr = colbuf; } else { if (strcmp(entry->celname, "userdeftype") == 0) { - strncpy(colbuf, userdefname, sizeof(colbuf)); + strncpy(colbuf, record->user_defined_name, sizeof(colbuf)); } else if (strcmp(entry->celname, "cid_name") == 0) { - strncpy(colbuf, cid_name, sizeof(colbuf)); + strncpy(colbuf, record->caller_id_name, sizeof(colbuf)); } else if (strcmp(entry->celname, "cid_num") == 0) { - strncpy(colbuf, cid_num, sizeof(colbuf)); + strncpy(colbuf, record->caller_id_num, sizeof(colbuf)); } else if (strcmp(entry->celname, "cid_ani") == 0) { - strncpy(colbuf, cid_ani, sizeof(colbuf)); + strncpy(colbuf, record->caller_id_ani, sizeof(colbuf)); } else if (strcmp(entry->celname, "cid_rdnis") == 0) { - strncpy(colbuf, cid_rdnis, sizeof(colbuf)); + strncpy(colbuf, record->caller_id_rdnis, sizeof(colbuf)); } else if (strcmp(entry->celname, "cid_dnid") == 0) { - strncpy(colbuf, cid_dnid, sizeof(colbuf)); + strncpy(colbuf, record->caller_id_dnid, sizeof(colbuf)); } else if (strcmp(entry->celname, "exten") == 0) { - strncpy(colbuf, exten, sizeof(colbuf)); + strncpy(colbuf, record->extension, sizeof(colbuf)); } else if (strcmp(entry->celname, "context") == 0) { - strncpy(colbuf, context, sizeof(colbuf)); + strncpy(colbuf, record->context, sizeof(colbuf)); } else if (strcmp(entry->celname, "channame") == 0) { - strncpy(colbuf, channame, sizeof(colbuf)); + strncpy(colbuf, record->channel_name, sizeof(colbuf)); } else if (strcmp(entry->celname, "appname") == 0) { - strncpy(colbuf, appname, sizeof(colbuf)); + strncpy(colbuf, record->application_name, sizeof(colbuf)); } else if (strcmp(entry->celname, "appdata") == 0) { - strncpy(colbuf, appdata, sizeof(colbuf)); + strncpy(colbuf, record->application_data, sizeof(colbuf)); } else if (strcmp(entry->celname, "accountcode") == 0) { - strncpy(colbuf, accountcode, sizeof(colbuf)); + strncpy(colbuf, record->account_code, sizeof(colbuf)); } else if (strcmp(entry->celname, "peeraccount") == 0) { - strncpy(colbuf, peeraccount, sizeof(colbuf)); + strncpy(colbuf, record->peer_account, sizeof(colbuf)); } else if (strcmp(entry->celname, "uniqueid") == 0) { - strncpy(colbuf, uniqueid, sizeof(colbuf)); + strncpy(colbuf, record->unique_id, sizeof(colbuf)); } else if (strcmp(entry->celname, "linkedid") == 0) { - strncpy(colbuf, linkedid, sizeof(colbuf)); + strncpy(colbuf, record->linked_id, sizeof(colbuf)); } else if (strcmp(entry->celname, "userfield") == 0) { - strncpy(colbuf, userfield, sizeof(colbuf)); + strncpy(colbuf, record->user_field, sizeof(colbuf)); } else if (strcmp(entry->celname, "peer") == 0) { - strncpy(colbuf, peer, sizeof(colbuf)); + strncpy(colbuf, record->peer, sizeof(colbuf)); } else if (strcmp(entry->celname, "amaflags") == 0) { - snprintf(colbuf, sizeof(colbuf), "%d", amaflag); + snprintf(colbuf, sizeof(colbuf), "%d", record->amaflag); } else { colbuf[0] = 0; } @@ -496,7 +468,8 @@ * form (but only when we're dealing with a character-based field). */ if (strcasecmp(entry->name, "eventtype") == 0) { - snprintf(colbuf, sizeof(colbuf), "%s", ast_cel_get_type_name(eventtype)); + snprintf(colbuf, sizeof(colbuf), "%s", + ast_cel_get_type_name(record->event_type)); } /* Truncate too-long fields */ @@ -591,7 +564,7 @@ { int integer = 0; if (strcasecmp(entry->name, "eventtype") == 0) { - integer = (int)eventtype; + integer = (int) record->event_type; } else if (sscanf(colptr, "%d", &integer) != 1) { ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); continue; @@ -606,7 +579,7 @@ { long long integer = 0; if (strcasecmp(entry->name, "eventtype") == 0) { - integer = (long long)eventtype; + integer = (long long) record->event_type; } else if (sscanf(colptr, "%lld", &integer) != 1) { ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); continue; @@ -621,7 +594,7 @@ { short integer = 0; if (strcasecmp(entry->name, "eventtype") == 0) { - integer = (short)eventtype; + integer = (short) record->event_type; } else if (sscanf(colptr, "%hd", &integer) != 1) { ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); continue; @@ -636,7 +609,7 @@ { char integer = 0; if (strcasecmp(entry->name, "eventtype") == 0) { - integer = (char)eventtype; + integer = (char) record->event_type; } else if (sscanf(colptr, "%hhd", &integer) != 1) { ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); continue; @@ -651,7 +624,7 @@ { char integer = 0; if (strcasecmp(entry->name, "eventtype") == 0) { - integer = (char)eventtype; + integer = (char) record->event_type; } else if (sscanf(colptr, "%hhd", &integer) != 1) { ast_log(LOG_WARNING, "CEL variable %s is not an integer.\n", entry->name); continue; @@ -669,7 +642,7 @@ { double number = 0.0; if (strcasecmp(entry->name, "eventtype") == 0) { - number = (double)eventtype; + number = (double)record->event_type; } else if (sscanf(colptr, "%lf", &number) != 1) { ast_log(LOG_WARNING, "CEL variable %s is not an numeric type.\n", entry->name); continue; @@ -686,7 +659,7 @@ { double number = 0.0; if (strcasecmp(entry->name, "eventtype") == 0) { - number = (double)eventtype; + number = (double)record->event_type; } else if (sscanf(colptr, "%lf", &number) != 1) { ast_log(LOG_WARNING, "CEL variable %s is not an numeric type.\n", entry->name); continue; Index: include/asterisk/cel.h =================================================================== --- include/asterisk/cel.h (revision 202004) +++ include/asterisk/cel.h (working copy) @@ -169,6 +169,31 @@ char *userdefevname, const char *extra, const struct ast_channel *peer2); +struct ast_cel_event_record { + enum ast_cel_event_type event_type; + struct timeval event_time; + const char *user_defined_name; + const char *caller_id_name; + const char *caller_id_num; + const char *caller_id_ani; + const char *caller_id_rdnis; + const char *caller_id_dnid; + const char *extension; + const char *context; + const char *channel_name; + const char *application_name; + const char *application_data; + const char *account_code; + const char *peer_account; + const char *unique_id; + const char *linked_id; + uint amaflag; + const char *user_field; + const char *peer; +}; + +struct ast_cel_event_record *ast_cel_fill_record(const struct ast_event *event); + #if defined(__cplusplus) || defined(c_plusplus) } #endif Index: main/cel.c =================================================================== --- main/cel.c (revision 202004) +++ main/cel.c (working copy) @@ -590,7 +590,43 @@ } } +struct ast_cel_event_record *ast_cel_fill_record(const struct ast_event *e) +{ + struct ast_cel_event_record *r = ast_calloc(1, sizeof(*r)); + if (!r) + return NULL; + + r->event_type = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TYPE); + + r->event_time.tv_sec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME); + r->event_time.tv_usec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME_USEC); + + if (r->event_type == AST_CEL_USER_DEFINED) { + r->user_defined_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USEREVENT_NAME); + } + + r->caller_id_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNAME); + r->caller_id_num = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNUM); + r->caller_id_ani = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDANI); + r->caller_id_rdnis = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDRDNIS); + r->caller_id_dnid = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDDNID); + r->extension = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTEN); + r->context = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CONTEXT); + r->channel_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CHANNAME); + r->application_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPNAME); + r->application_data = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPDATA); + r->account_code = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE); + r->peer_account = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE); + r->unique_id = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_UNIQUEID); + r->linked_id = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_LINKEDID); + r->amaflag = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_AMAFLAGS); + r->user_field = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USERFIELD); + r->peer = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_PEER); + + return r; +} + int ast_cel_engine_init(void) { int res;