332{
337 char *tmp;
338 char colbuf[1024], *colptr;
339 SQLHSTMT stmt =
NULL;
340 int res;
343 };
344
346 return;
347 }
348
349 if (!sql || !sql2) {
350 if (sql)
352 if (sql2)
354 return;
355 }
356
361 return;
362 }
363
365 char *separator = "";
368
369
372 continue;
373 }
374
376 int datefield = 0;
378 if (strcasecmp(entry->
celname,
"eventtime") == 0) {
379 datefield = 1;
380 }
381
382
385 } else if (datefield) {
387 struct ast_tm tm = { 0, };
389
390
391
392
393
394
395
396
397
398
399 ast_strftime(colbuf,
sizeof(colbuf),
"%Y-%m-%d %H:%M:%S.%6q", &tm);
400 colptr = colbuf;
401 } else {
402 if (strcmp(entry->
celname,
"userdeftype") == 0) {
404 }
else if (strcmp(entry->
celname,
"cid_name") == 0) {
406 }
else if (strcmp(entry->
celname,
"cid_num") == 0) {
408 }
else if (strcmp(entry->
celname,
"cid_ani") == 0) {
410 }
else if (strcmp(entry->
celname,
"cid_rdnis") == 0) {
412 }
else if (strcmp(entry->
celname,
"cid_dnid") == 0) {
414 }
else if (strcmp(entry->
celname,
"exten") == 0) {
416 }
else if (strcmp(entry->
celname,
"context") == 0) {
418 }
else if (strcmp(entry->
celname,
"channame") == 0) {
420 }
else if (strcmp(entry->
celname,
"appname") == 0) {
422 }
else if (strcmp(entry->
celname,
"appdata") == 0) {
424 }
else if (strcmp(entry->
celname,
"accountcode") == 0) {
426 }
else if (strcmp(entry->
celname,
"peeraccount") == 0) {
428 }
else if (strcmp(entry->
celname,
"uniqueid") == 0) {
430 }
else if (strcmp(entry->
celname,
"linkedid") == 0) {
432 }
else if (strcmp(entry->
celname,
"userfield") == 0) {
434 }
else if (strcmp(entry->
celname,
"peer") == 0) {
436 }
else if (strcmp(entry->
celname,
"amaflags") == 0) {
437 snprintf(colbuf,
sizeof(colbuf),
"%u", record.
amaflag);
438 }
else if (strcmp(entry->
celname,
"extra") == 0) {
440 }
else if (strcmp(entry->
celname,
"eventtype") == 0) {
441 snprintf(colbuf,
sizeof(colbuf),
"%u", record.
event_type);
442 } else {
443 colbuf[0] = 0;
445 }
446 colptr = colbuf;
447 }
448
450
451
452
453
455 ast_verb(4,
"CEL column '%s' with value '%s' does not match filter of"
456 " '%s'. Cancelling this CEL.\n",
458 goto early_release;
459 }
460
461
463 continue;
464
466
467 switch (entry->
type) {
468 case SQL_CHAR:
469 case SQL_VARCHAR:
470 case SQL_LONGVARCHAR:
471#ifdef HAVE_ODBC_WCHAR
472 case SQL_WCHAR:
473 case SQL_WVARCHAR:
474 case SQL_WLONGVARCHAR:
475#endif
476 case SQL_BINARY:
477 case SQL_VARBINARY:
478 case SQL_LONGVARBINARY:
479 case SQL_GUID:
480
481
482
483 if (strcasecmp(entry->
name,
"eventtype") == 0) {
484 const char *event_name;
485
489 snprintf(colbuf, sizeof(colbuf), "%s", event_name);
490 }
491
492
493 if (entry->
type != SQL_GUID) {
494 if (strlen(colptr) > entry->
octetlen) {
496 }
497 }
498
501
502
504 for (tmp = colptr; *tmp; tmp++) {
505 if (*tmp == '\'') {
509 } else {
511 }
512 }
514 break;
515 case SQL_TYPE_DATE:
517 continue;
518 } else {
519 int year = 0, month = 0, day = 0;
520 if (strcasecmp(entry->
name,
"eventdate") == 0) {
526 } else {
527 if (sscanf(colptr, "%4d-%2d-%2d", &year, &month, &day) != 3 || year <= 0 ||
528 month <= 0 || month > 12 || day < 0 || day > 31 ||
529 ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) ||
530 (month == 2 && year % 400 == 0 && day > 29) ||
531 (month == 2 && year % 100 == 0 && day > 28) ||
532 (month == 2 && year % 4 == 0 && day > 29) ||
533 (month == 2 && year % 4 != 0 && day > 28)) {
535 continue;
536 }
537
538 if (year > 0 && year < 100) {
539 year += 2000;
540 }
541 }
542
545 ast_str_append(&sql2, 0,
"%s{d '%04d-%02d-%02d'}", separator, year, month, day);
546 }
547 break;
548 case SQL_TYPE_TIME:
550 continue;
551 } else {
552 int hour = 0, minute = 0, second = 0;
553 if (strcasecmp(entry->
name,
"eventdate") == 0) {
559 } else {
560 int count = sscanf(colptr, "%2d:%2d:%2d", &hour, &minute, &second);
561
562 if ((count != 2 && count != 3) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > (tableptr->
allowleapsec ? 60 : 59)) {
564 continue;
565 }
566 }
567
570 ast_str_append(&sql2, 0,
"%s{t '%02d:%02d:%02d'}", separator, hour, minute, second);
571 }
572 break;
573 case SQL_TYPE_TIMESTAMP:
574 case SQL_TIMESTAMP:
575 case SQL_DATETIME:
577 continue;
578 } else {
579 if (datefield) {
580
581
582
583
587 } else {
588 int year = 0, month = 0, day = 0, hour = 0, minute = 0;
589
590 double second = 0.0;
591 if (strcasecmp(entry->
name,
"eventdate") == 0) {
592
593
594
595
596
605 second += (tm.
tm_usec / 1000000.0);
606 } else {
607
608
609
610
611 int count = sscanf(colptr, "%4d-%2d-%2d %2d:%2d:%lf", &year, &month, &day, &hour, &minute, &second);
612
613 if ((count != 3 && count != 5 && count != 6) || year <= 0 ||
614 month <= 0 || month > 12 || day < 0 || day > 31 ||
615 ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) ||
616 (month == 2 && year % 400 == 0 && day > 29) ||
617 (month == 2 && year % 100 == 0 && day > 28) ||
618 (month == 2 && year % 4 == 0 && day > 29) ||
619 (month == 2 && year % 4 != 0 && day > 28) ||
620 hour > 23 || minute > 59 || ((
int)floor(second)) > (tableptr->
allowleapsec ? 60 : 59) ||
621 hour < 0 || minute < 0 || ((int)floor(second)) < 0) {
623 continue;
624 }
625
626 if (year > 0 && year < 100) {
627 year += 2000;
628 }
629 }
630
633 ast_str_append(&sql2, 0,
"%s{ts '%04d-%02d-%02d %02d:%02d:%09.6lf'}", separator, year, month, day, hour, minute, second);
634 }
635 }
636 break;
637 case SQL_INTEGER:
638 {
640 if (sscanf(colptr,
"%30d", &
integer) != 1) {
642 continue;
643 }
644
648 }
649 break;
650 case SQL_BIGINT:
651 {
653 int ret;
654 if ((ret = sscanf(colptr,
"%30lld", &
integer)) != 1) {
656 continue;
657 }
658
662 }
663 break;
664 case SQL_SMALLINT:
665 {
667 if (sscanf(colptr,
"%30hd", &
integer) != 1) {
669 continue;
670 }
671
675 }
676 break;
677 case SQL_TINYINT:
678 {
680 if (sscanf(colptr,
"%30hhd", &
integer) != 1) {
682 continue;
683 }
684
688 }
689 break;
690 case SQL_BIT:
691 {
693 if (sscanf(colptr,
"%30hhd", &
integer) != 1) {
695 continue;
696 }
699
703 }
704 break;
705 case SQL_NUMERIC:
706 case SQL_DECIMAL:
707 {
709 if (sscanf(colptr,
"%30lf", &
number) != 1) {
711 continue;
712 }
713
717 }
718 break;
719 case SQL_FLOAT:
720 case SQL_REAL:
721 case SQL_DOUBLE:
722 {
724 if (sscanf(colptr,
"%30lf", &
number) != 1) {
726 continue;
727 }
728
732 }
733 break;
734 default:
736 continue;
737 }
738 separator = ", ";
739 }
740 }
741
742
747
749
750
751
752 res = SQLAllocHandle(SQL_HANDLE_STMT, obj->
con, &stmt);
753 if (!SQL_SUCCEEDED(res)) {
756 goto early_release;
757 }
758
760 if (!SQL_SUCCEEDED(res)) {
762 }
763
764 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
765
766early_release:
768 }
770
771
774 }
777 }
778
781}
@ AST_CEL_USER_DEFINED
a user-defined event, the event name field should be set
int ast_cel_fill_record(const struct ast_event *event, struct ast_cel_event_record *r)
Fill in an ast_cel_event_record from a CEL event.
#define AST_CEL_EVENT_RECORD_VERSION
struct ABI version
#define LENGTHEN_BUF2(size)
#define LENGTHEN_BUF1(size)
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
int ast_odbc_backslash_is_escape(struct odbc_obj *obj)
Checks if the database natively supports backslash as an escape character.
SQLRETURN ast_odbc_execute_sql(struct odbc_obj *obj, SQLHSTMT *stmt, const char *sql)
Execute a unprepared SQL query.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Helper struct for getting the fields out of a CEL event.
const char * caller_id_dnid
const char * application_data
const char * account_code
const char * caller_id_rdnis
const char * caller_id_num
const char * channel_name
const char * peer_account
enum ast_cel_event_type event_type
const char * user_defined_name
const char * application_name
struct timeval event_time
uint32_t version
struct ABI version
const char * caller_id_ani
const char * caller_id_name
Support for dynamic strings.
static struct ast_codec unknown