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

Function get_user_script

modules/cpl_c/cpl_db.c:111–175  ·  view source on GitHub ↗

gets from database the cpl script in binary format; the returned script is * allocated in shared memory * Returns: 1 - success * -1 - error */

Source from the content-addressed store, hash-verified

109 * -1 - error
110 */
111int get_user_script(str *username, str *domain, str *script, str* key)
112{
113 db_key_t keys_cmp[2];
114 db_key_t keys_ret[1];
115 db_val_t vals[2];
116 db_res_t *res = NULL;
117 int n;
118
119 keys_cmp[0] = &cpl_username_col;
120 keys_cmp[1] = &cpl_domain_col;
121 keys_ret[0] = key;
122
123 LM_DBG("fetching script for user <%.*s>\n",
124 username->len,username->s);
125 vals[0].type = DB_STR;
126 vals[0].nul = 0;
127 vals[0].val.str_val = *username;
128 n = 1;
129 if (domain) {
130 vals[1].type = DB_STR;
131 vals[1].nul = 0;
132 vals[1].val.str_val = *domain;
133 n++;
134 }
135
136 if (cpl_dbf.query(db_hdl, keys_cmp, 0, vals, keys_ret, n, 1, NULL, &res)
137 < 0){
138 LM_ERR("db_query failed\n");
139 goto error;
140 }
141
142 if (res->n==0) {
143 LM_DBG("user <%.*s> not found in db -> probably "
144 "he has no script\n",username->len, username->s);
145 script->s = 0;
146 script->len = 0;
147 } else {
148 if (res->rows[0].values[0].nul) {
149 LM_DBG("user <%.*s> has a NULL script\n",
150 username->len, username->s);
151 script->s = 0;
152 script->len = 0;
153 } else {
154 LM_DBG("we got the script len=%d\n",
155 res->rows[0].values[0].val.blob_val.len);
156 script->len = res->rows[0].values[0].val.blob_val.len;
157 script->s = shm_malloc( script->len );
158 if (!script->s) {
159 LM_ERR("no free sh_mem\n");
160 goto error;
161 }
162 memcpy( script->s, res->rows[0].values[0].val.blob_val.s,
163 script->len);
164 }
165 }
166
167 cpl_dbf.free_result( db_hdl, res);
168 return 1;

Callers 3

cpl_invoke_scriptFunction · 0.85
do_script_downloadFunction · 0.85
mi_cpl_getFunction · 0.85

Calls 1

shm_mallocFunction · 0.85

Tested by

no test coverage detected