MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / insert_in_cachedb

Function insert_in_cachedb

modules/sql_cacher/sql_cacher.c:613–771  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

611}
612
613static int insert_in_cachedb(cache_entry_t *c_entry, db_handlers_t *db_hdls,
614 db_val_t *key, db_val_t *values, int reload_version, int nr_columns)
615{
616 unsigned int i, offset = 0, strs_offset = 0;
617 int int_val;
618 int int_key_len = 0, rc = 0;
619 char int_buf[4], int_enc_buf[INT_B64_ENC_LEN];
620 char *int_key_buf = NULL;
621 str str_val;
622 db_type_t val_type;
623 str str_key = STR_NULL;
624 str cdb_val;
625 str cdb_key = STR_NULL;
626
627 cdb_val.len = get_cdb_val_size(c_entry, values, nr_columns);
628 cdb_val.s = pkg_malloc(cdb_val.len);
629 if (!cdb_val.s) {
630 LM_ERR("No more pkg memory\n");
631 return -1;
632 }
633
634 /* store the reload version (base64 encoded) */
635 memcpy(int_buf, &reload_version, 4);
636 base64encode((unsigned char *)int_enc_buf, (unsigned char *)int_buf, 4);
637 memcpy(cdb_val.s, int_enc_buf, INT_B64_ENC_LEN);
638
639 offset += INT_B64_ENC_LEN;
640
641 /* store the integer values (base64 encoded) */
642 for (i = 0; i < nr_columns; i++) {
643 int_val = 0;
644 val_type = VAL_TYPE(values + i);
645
646 switch (val_type) {
647 case DB_INT:
648 int_val = VAL_INT(values + i);
649 break;
650 case DB_BIGINT:
651 if (!sql_cacher_bigint2str) {
652 int_val = (int)VAL_BIGINT(values + i);
653 break;
654 } else {
655 continue;
656 }
657 default: continue;
658 }
659 if (VAL_NULL(values + i))
660 memset(int_enc_buf, 0, INT_B64_ENC_LEN);
661 else {
662 memcpy(int_buf, &int_val, 4);
663 base64encode((unsigned char *)int_enc_buf, (unsigned char *)int_buf, 4);
664 }
665
666 memcpy(cdb_val.s + offset, int_enc_buf, INT_B64_ENC_LEN);
667
668 offset += INT_B64_ENC_LEN;
669 }
670

Callers 2

load_entire_tableFunction · 0.85
load_keyFunction · 0.85

Calls 5

get_cdb_val_sizeFunction · 0.85
base64encodeFunction · 0.85
double2strFunction · 0.85
bigint2strFunction · 0.85
sint2strFunction · 0.85

Tested by

no test coverage detected