Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"en-US,en;q\u003d0.5", "gen_ut":1660502833, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"33941dbcb893d3dab425714c571191b9", "oid":{ "oid": "e3ed2ba6901c385b44acace6a4e91fac2b165f40", "alias": [ "refs/heads/main"]},"blobname": "lib/misc/lws-struct-sqlite.c", "blob": "/*\n * libwebsockets - small server side websockets and web server implementation\n *\n * Copyright (C) 2010 - 2020 Andy Green \u003candy@warmcat.com\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \u0022AS IS\u0022, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\n#include \u003clibwebsockets.h\u003e\n#include \u003cprivate-lib-core.h\u003e\n\n#include \u003csqlite3.h\u003e\n\n/*\n * we get one of these per matching result from the query\n */\n\nstatic int\nlws_struct_sq3_deser_cb(void *priv, int cols, char **cv, char **cn)\n{\n\tlws_struct_args_t *a \u003d (lws_struct_args_t *)priv;\n\tchar *u \u003d lwsac_use_zero(\u0026a-\u003eac, a-\u003edest_len, a-\u003eac_block_size);\n\tlws_dll2_owner_t *o \u003d (lws_dll2_owner_t *)a-\u003ecb_arg;\n\tconst lws_struct_map_t *map \u003d a-\u003emap_st[0];\n\tint n, mems \u003d (int)(ssize_t)a-\u003emap_entries_st[0];\n\tlong long li;\n\tsize_t lim;\n\tchar **pp;\n\tchar *s;\n\n\tif (!u) {\n\t\tlwsl_err(\u0022OOM\u005cn\u0022);\n\n\t\treturn 1;\n\t}\n\n\tlws_dll2_add_tail((lws_dll2_t *)((char *)u + a-\u003etoplevel_dll2_ofs), o);\n\n\twhile (mems--) {\n\t\tfor (n \u003d 0; n \u003c cols; n++) {\n\t\t\tif (!cv[n] || strcmp(cn[n], map-\u003ecolname))\n\t\t\t\tcontinue;\n\n\t\t\tswitch (map-\u003etype) {\n\t\t\tcase LSMT_SIGNED:\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(signed char)) {\n\t\t\t\t\tsigned char *pc;\n\t\t\t\t\tpc \u003d (signed char *)(u + map-\u003eofs);\n\t\t\t\t\t*pc \u003d (signed char)atoi(cv[n]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(short)) {\n\t\t\t\t\tshort *ps;\n\t\t\t\t\tps \u003d (short *)(u + map-\u003eofs);\n\t\t\t\t\t*ps \u003d (short)atoi(cv[n]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(int)) {\n\t\t\t\t\tint *pi;\n\t\t\t\t\tpi \u003d (int *)(u + map-\u003eofs);\n\t\t\t\t\t*pi \u003d (int)atoll(cv[n]); /* 32-bit OS */\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(long)) {\n\t\t\t\t\tlong *pl;\n\t\t\t\t\tpl \u003d (long *)(u + map-\u003eofs);\n\t\t\t\t\t*pl \u003d (long)atoll(cv[n]); /* 32-bit OS */\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tlong long *pll;\n\t\t\t\t\tpll \u003d (long long *)(u + map-\u003eofs);\n\t\t\t\t\t*pll \u003d atoll(cv[n]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase LSMT_UNSIGNED:\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(unsigned char)) {\n\t\t\t\t\tunsigned char *pc;\n\t\t\t\t\tpc \u003d (unsigned char *)(u + map-\u003eofs);\n\t\t\t\t\t*pc \u003d (unsigned char)(unsigned int)atoi(cv[n]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(unsigned short)) {\n\t\t\t\t\tunsigned short *ps;\n\t\t\t\t\tps \u003d (unsigned short *)(u + map-\u003eofs);\n\t\t\t\t\t*ps \u003d (unsigned short)atoi(cv[n]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(unsigned int)) {\n\t\t\t\t\tunsigned int *pi;\n\t\t\t\t\tpi \u003d (unsigned int *)(u + map-\u003eofs);\n\t\t\t\t\t*pi \u003d (unsigned int)atoi(cv[n]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(unsigned long)) {\n\t\t\t\t\tunsigned long *pl;\n\t\t\t\t\tpl \u003d (unsigned long *)(u + map-\u003eofs);\n\t\t\t\t\t*pl \u003d (unsigned long)atol(cv[n]);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t{\n\t\t\t\t\tunsigned long long *pll;\n\t\t\t\t\tpll \u003d (unsigned long long *)(u + map-\u003eofs);\n\t\t\t\t\t*pll \u003d (unsigned long long)atoll(cv[n]);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase LSMT_BOOLEAN:\n\t\t\t\tli \u003d 0;\n\t\t\t\tif (!strcmp(cv[n], \u0022true\u0022) ||\n\t\t\t\t !strcmp(cv[n], \u0022TRUE\u0022) || cv[n][0] \u003d\u003d '1')\n\t\t\t\t\tli \u003d 1;\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(char)) {\n\t\t\t\t\tchar *pc;\n\t\t\t\t\tpc \u003d (char *)(u + map-\u003eofs);\n\t\t\t\t\t*pc \u003d (char)li;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tif (map-\u003eaux \u003d\u003d sizeof(int)) {\n\t\t\t\t\tint *pi;\n\t\t\t\t\tpi \u003d (int *)(u + map-\u003eofs);\n\t\t\t\t\t*pi \u003d (int)li;\n\t\t\t\t} else {\n\t\t\t\t\tuint64_t *p64;\n\t\t\t\t\tp64 \u003d (uint64_t *)(u + map-\u003eofs);\n\t\t\t\t\t*p64 \u003d (uint64_t)li;\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase LSMT_STRING_CHAR_ARRAY:\n\t\t\t\ts \u003d (char *)(u + map-\u003eofs);\n\t\t\t\tlim \u003d map-\u003eaux;\n\t\t\t\tlws_strncpy(s, cv[n], lim);\n\t\t\t\tbreak;\n\n\t\t\tcase LSMT_STRING_PTR:\n\t\t\t\tpp \u003d (char **)(u + map-\u003eofs);\n\t\t\t\tlim \u003d strlen(cv[n]);\n\t\t\t\ts \u003d lwsac_use(\u0026a-\u003eac, lim + 1, a-\u003eac_block_size);\n\t\t\t\tif (!s)\n\t\t\t\t\treturn 1;\n\t\t\t\t*pp \u003d s;\n\t\t\t\tmemcpy(s, cv[n], lim);\n\t\t\t\ts[lim] \u003d '\u005c0';\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tmap++;\n\t}\n\n\treturn 0;\n}\n\n/*\n * Call this with an LSM_SCHEMA map, its colname is the table name and its\n * type information describes the toplevel type. Schema is dereferenced and\n * put in args before the actual sq3 query, which is given the child map.\n */\n\nint\nlws_struct_sq3_deserialize(sqlite3 *pdb, const char *filter, const char *order,\n\t\t\t const lws_struct_map_t *schema, lws_dll2_owner_t *o,\n\t\t\t struct lwsac **ac, int start, int _limit)\n{\n\tint limit \u003d _limit \u003c 0 ? -_limit : _limit;\n\tchar s[768], results[512], where[250];\n\tlws_struct_args_t a;\n\tint n, m;\n\n\tif (!order)\n\t\torder \u003d \u0022_lws_idx\u0022;\n\n\tmemset(\u0026a, 0, sizeof(a));\n\ta.ac \u003d *ac;\n\ta.cb_arg \u003d o; /* lws_dll2_owner tracking query result objects */\n\ta.map_st[0] \u003d schema-\u003echild_map;\n\ta.map_entries_st[0] \u003d schema-\u003echild_map_size;\n\ta.dest_len \u003d schema-\u003eaux; /* size of toplevel object to allocate */\n\ta.toplevel_dll2_ofs \u003d schema-\u003eofs;\n\n\tlws_dll2_owner_clear(o);\n\n\t/*\n\t * Explicitly list the columns instead of use *, so we can skip blobs\n\t */\n\n\tm \u003d 0;\n\tfor (n \u003d 0; n \u003c (int)schema-\u003echild_map_size; n++)\n\t\tm +\u003d lws_snprintf(\u0026results[m], sizeof(results) - (unsigned int)n - 1,\n\t\t\t\t \u0022%s%c\u0022, schema-\u003echild_map[n].colname,\n\t\t\t\t n + 1 \u003d\u003d (int)schema-\u003echild_map_size ? ' ' : ',');\n\n\twhere[0] \u003d '\u005c0';\n\tlws_snprintf(where, sizeof(where), \u0022 where _lws_idx \u003e\u003d %llu %s\u0022,\n\t\t\t (unsigned long long)start, filter ? filter : \u0022\u0022);\n\n\tlws_snprintf(s, sizeof(s) - 1, \u0022select %s \u0022\n\t\t \u0022from %s %s order by %s %slimit %d;\u0022, results,\n\t\t schema-\u003ecolname, where, order,\n\t\t\t\t _limit \u003c 0 ? \u0022desc \u0022 : \u0022\u0022, limit);\n\n\n\n\tif (sqlite3_exec(pdb, s, lws_struct_sq3_deser_cb, \u0026a, NULL) !\u003d SQLITE_OK) {\n\t\tlwsl_err(\u0022%s: %s: fail %s\u005cn\u0022, __func__, sqlite3_errmsg(pdb), s);\n\t\tlwsac_free(\u0026a.ac);\n\t\treturn -1;\n\t}\n\n\t*ac \u003d a.ac;\n\n\treturn 0;\n}\n\n/*\n * This takes a struct and turns it into an sqlite3 UPDATE, using the given\n * schema... which has one LSM_SCHEMA_DLL2 entry wrapping the actual schema\n */\n\nstatic int\n_lws_struct_sq3_ser_one(sqlite3 *pdb, const lws_struct_map_t *schema,\n\t\t\tuint32_t idx, void *st)\n{\n\tconst lws_struct_map_t *map \u003d schema-\u003echild_map;\n\tint n, m, pk \u003d 0, nentries \u003d (int)(ssize_t)schema-\u003echild_map_size, nef \u003d 0, did;\n\tsize_t sql_est \u003d 46 + strlen(schema-\u003ecolname) + 1;\n\t\t/* \u0022insert into (_lws_idx, ) values (00000001,);\u0022 ...\n\t\t * plus the table name */\n\tuint8_t *stb \u003d (uint8_t *)st;\n\tconst char *p;\n\tchar *sql;\n\n\t/*\n\t * Figure out effective number of columns, exluding BLOB.\n\t *\n\t * The first UNSIGNED is a hidden index. Blobs are not handled by\n\t * lws_struct except to create the column in the schema.\n\t */\n\n\tpk \u003d 0;\n\tnef \u003d 0;\n\tfor (n \u003d 0; n \u003c nentries; n++) {\n\t\tif (!pk \u0026\u0026 map[n].type \u003d\u003d LSMT_UNSIGNED) {\n\t\t\tpk \u003d 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (map[n].type \u003d\u003d LSMT_BLOB_PTR)\n\t\t\tcontinue;\n\n\t\tnef++;\n\t}\n\n\t/*\n\t * Figure out an estimate for the length of the populated sqlite\n\t * command, and then malloc it up\n\t */\n\n\tfor (n \u003d 0; n \u003c nentries; n++) {\n\t\tsql_est +\u003d strlen(map[n].colname) + 2;\n\t\tswitch (map[n].type) {\n\t\tcase LSMT_SIGNED:\n\t\tcase LSMT_UNSIGNED:\n\t\tcase LSMT_BOOLEAN:\n\n\t\t\tswitch (map[n].aux) {\n\t\t\tcase 1:\n\t\t\t\tsql_est +\u003d 3 + 2;\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tsql_est +\u003d 5 + 2;\n\t\t\t\tbreak;\n\t\t\tcase 4:\n\t\t\t\tsql_est +\u003d 10 + 2;\n\t\t\t\tbreak;\n\t\t\tcase 8:\n\t\t\t\tsql_est +\u003d 20 + 2;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tif (map[n].type \u003d\u003d LSMT_SIGNED)\n\t\t\t\tsql_est++; /* minus sign */\n\n\t\t\tbreak;\n\t\tcase LSMT_STRING_CHAR_ARRAY:\n\t\t\tsql_est +\u003d (unsigned int)lws_sql_purify_len((const char *)st +\n\t\t\t\t\t\t\tmap[n].ofs) + 2;\n\t\t\tbreak;\n\n\t\tcase LSMT_STRING_PTR:\n\t\t\tp \u003d *((const char * const *)\u0026stb[map[n].ofs]);\n\t\t\tsql_est +\u003d (unsigned int)((p ? lws_sql_purify_len(p) : 0) + 2);\n\t\t\tbreak;\n\n\t\tcase LSMT_BLOB_PTR:\n\t\t\t/* we don't deal with blobs actually */\n\t\t\tsql_est -\u003d strlen(map[n].colname) + 2;\n\t\t\tbreak;\n\n\t\tdefault:\n\t\t\tlwsl_err(\u0022%s: unsupported type\u005cn\u0022, __func__);\n\t\t\tassert(0);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tsql \u003d malloc(sql_est);\n\tif (!sql)\n\t\treturn -1;\n\n\tm \u003d lws_snprintf(sql, sql_est, \u0022insert into %s(_lws_idx, \u0022,\n\t\t\t schema-\u003ecolname);\n\n\t/*\n\t * First explicit integer type is primary key autoincrement, should\n\t * not be specified\n\t */\n\n\tpk \u003d 0;\n\tdid \u003d 0;\n\tfor (n \u003d 0; n \u003c nentries; n++) {\n\t\tif (!pk \u0026\u0026 map[n].type \u003d\u003d LSMT_UNSIGNED) {\n\t\t\tpk \u003d 1;\n\t\t\tcontinue;\n\t\t}\n\t\tif (map[n].type \u003d\u003d LSMT_BLOB_PTR)\n\t\t\tcontinue;\n\n\t\tdid++;\n\t\tm +\u003d lws_snprintf(sql + m, sql_est - (unsigned int)m,\n\t\t\t\t did \u003d\u003d nef ? \u0022%s\u0022 : \u0022%s, \u0022,\n\t\t\t\t map[n].colname);\n\t}\n\n\tm +\u003d lws_snprintf(sql + m, sql_est - (unsigned int)m, \u0022) values(%u, \u0022, idx);\n\n\tpk \u003d 0;\n\tdid \u003d 0;\n\tfor (n \u003d 0; n \u003c nentries; n++) {\n\t\tuint64_t uu64;\n\t\tsize_t q;\n\n\t\tif (!pk \u0026\u0026 map[n].type \u003d\u003d LSMT_UNSIGNED) {\n\t\t\tpk \u003d 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tswitch (map[n].type) {\n\t\tcase LSMT_SIGNED:\n\t\tcase LSMT_UNSIGNED:\n\t\tcase LSMT_BOOLEAN:\n\n\t\t\tuu64 \u003d 0;\n\t\t\tfor (q \u003d 0; q \u003c map[n].aux; q++)\n\t\t\t\tuu64 |\u003d ((uint64_t)stb[map[n].ofs + q] \u003c\u003c\n\t\t\t\t\t\t\t\t(q \u003c\u003c 3));\n\n\t\t\tif (map[n].type \u003d\u003d LSMT_SIGNED)\n\t\t\t\tm +\u003d lws_snprintf(sql + m, sql_est - (unsigned int)m, \u0022%lld\u0022,\n\t\t\t\t\t\t (long long)(int64_t)uu64);\n\t\t\telse\n\t\t\t\tm +\u003d lws_snprintf(sql + m, sql_est - (unsigned int)m, \u0022%llu\u0022,\n\t\t\t\t\t\t (unsigned long long)uu64);\n\t\t\tbreak;\n\n\t\tcase LSMT_STRING_CHAR_ARRAY:\n\t\t\tsql[m++] \u003d '\u005c'';\n\t\t\tlws_sql_purify(sql + m, (const char *)\u0026stb[map[n].ofs],\n\t\t\t\t sql_est - (size_t)(ssize_t)m - 4);\n\t\t\tm +\u003d (int)(ssize_t)strlen(sql + m);\n\t\t\tsql[m++] \u003d '\u005c'';\n\t\t\tbreak;\n\t\tcase LSMT_STRING_PTR:\n\t\t\tp \u003d *((const char * const *)\u0026stb[map[n].ofs]);\n\t\t\tsql[m++] \u003d '\u005c'';\n\t\t\tif (p) {\n\t\t\t\tlws_sql_purify(sql + m, p, sql_est - (unsigned int)m - 4);\n\t\t\t\tm +\u003d (int)(ssize_t)strlen(sql + m);\n\t\t\t}\n\t\t\tsql[m++] \u003d '\u005c'';\n\t\t\tbreak;\n\n\t\tcase LSMT_BLOB_PTR:\n\t\t\tcontinue;\n\n\t\tdefault:\n\t\t\tlwsl_err(\u0022%s: unsupported type\u005cn\u0022, __func__);\n\t\t\tassert(0);\n\t\t\tbreak;\n\t\t}\n\n\t\tdid++;\n\t\tif (did !\u003d nef) {\n\t\t\tif (sql_est - (unsigned int)m \u003c 6)\n\t\t\t\treturn -1;\n\t\t\tsql[m++] \u003d ',';\n\t\t\tsql[m++] \u003d ' ';\n\t\t}\n\t}\n\n\tlws_snprintf(sql + m, sql_est - (unsigned int)m, \u0022);\u0022);\n\n\tn \u003d sqlite3_exec(pdb, sql, NULL, NULL, NULL);\n\tif (n !\u003d SQLITE_OK) {\n\t\tlwsl_err(\u0022%s\u005cn\u0022, sql);\n\t\tfree(sql);\n\t\tlwsl_err(\u0022%s: %s: fail\u005cn\u0022, __func__, sqlite3_errmsg(pdb));\n\t\treturn -1;\n\t}\n\tfree(sql);\n\n\treturn 0;\n}\n\nint\nlws_struct_sq3_serialize(sqlite3 *pdb, const lws_struct_map_t *schema,\n\t\t\t lws_dll2_owner_t *owner, uint32_t manual_idx)\n{\n\tuint32_t idx \u003d manual_idx;\n\n\tlws_start_foreach_dll(struct lws_dll2 *, p, owner-\u003ehead) {\n\t\tvoid *item \u003d (void *)((uint8_t *)p - schema-\u003eofs_clist);\n\t\tif (_lws_struct_sq3_ser_one(pdb, schema, idx++, item))\n\t\t\treturn 1;\n\n\t} lws_end_foreach_dll(p);\n\n\treturn 0;\n}\n\nint\nlws_struct_sq3_create_table(sqlite3 *pdb, const lws_struct_map_t *schema)\n{\n\tconst lws_struct_map_t *map \u003d schema-\u003echild_map;\n\tint map_size \u003d (int)(ssize_t)schema-\u003echild_map_size, subsequent \u003d 0;\n\tchar s[2048], *p \u003d s, *end \u003d \u0026s[sizeof(s) - 1],\n\t *pri \u003d \u0022 primary key autoincrement\u0022, *use;\n\n\tp +\u003d lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p),\n\t\t\t \u0022create table if not exists %s (_lws_idx integer, \u0022,\n\t\t\t schema-\u003ecolname);\n\n\twhile (map_size--) {\n\t\tif (map-\u003etype \u003e LSMT_STRING_PTR \u0026\u0026 map-\u003etype !\u003d LSMT_BLOB_PTR) {\n\t\t\tmap++;\n\t\t\tcontinue;\n\t\t}\n\t\tif (subsequent \u0026\u0026 (end - p) \u003e 4) {\n\t\t\t*p++ \u003d ',';\n\t\t\t*p++ \u003d ' ';\n\t\t}\n\t\tsubsequent \u003d 1;\n\t\tif (map-\u003etype \u003d\u003d LSMT_BLOB_PTR) {\n\n\t\t\tp +\u003d lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), \u0022%s blob\u0022, map-\u003ecolname);\n\n\t\t} else {\n\t\t\tif (map-\u003etype \u003c LSMT_STRING_CHAR_ARRAY) {\n\t\t\t\tuse \u003d \u0022\u0022;\n\t\t\t\tif (map-\u003ecolname[0] !\u003d '_') /* _lws_idx is not primary key */\n\t\t\t\t\tuse \u003d pri;\n\t\t\t\tp +\u003d lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), \u0022%s integer%s\u0022,\n\t\t\t\t\t\tmap-\u003ecolname, use);\n\t\t\t\tif (map-\u003ecolname[0] !\u003d '_')\n\t\t\t\t\tpri \u003d \u0022\u0022;\n\t\t\t} else\n\t\t\t\tp +\u003d lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), \u0022%s varchar\u0022,\n\t\t\t\t\t\tmap-\u003ecolname);\n\t\t}\n\n\t\tmap++;\n\t}\n\n\tp +\u003d lws_snprintf(p, (unsigned int)lws_ptr_diff(end, p), \u0022);\u0022);\n\n\tif (sqlite3_exec(pdb, s, NULL, NULL, NULL) !\u003d SQLITE_OK) {\n\t\tlwsl_err(\u0022%s: %s: fail\u005cn\u0022, __func__, sqlite3_errmsg(pdb));\n\n\t\treturn -1;\n\t}\n\n\treturn 0;\n}\n\nint\nlws_struct_sq3_open(struct lws_context *context, const char *sqlite3_path,\n\t\t char create_if_missing, sqlite3 **pdb)\n{\n#if !defined(WIN32)\n\tuid_t uid \u003d 0;\n\tgid_t gid \u003d 0;\n#endif\n\n\tif (sqlite3_open_v2(sqlite3_path, pdb,\n\t\t\t SQLITE_OPEN_READWRITE |\n\t\t\t (create_if_missing ? SQLITE_OPEN_CREATE : 0),\n\t\t\t NULL) !\u003d SQLITE_OK) {\n\t\tlwsl_info(\u0022%s: Unable to open db %s: %s\u005cn\u0022,\n\t\t\t __func__, sqlite3_path, sqlite3_errmsg(*pdb));\n\n\t\treturn 1;\n\t}\n\n#if !defined(WIN32)\n\tlws_get_effective_uid_gid(context, \u0026uid, \u0026gid);\n\tif (uid)\n\t\tif (chown(sqlite3_path, uid, gid))\n\t\t\tlwsl_err(\u0022%s: failed to chown %s\u005cn\u0022, __func__, sqlite3_path);\n\tchmod(sqlite3_path, 0600);\n\n\tlwsl_debug(\u0022%s: created %s owned by %u:%u mode 0600\u005cn\u0022, __func__,\n\t\t\tsqlite3_path, (unsigned int)uid, (unsigned int)gid);\n#else\n\tlwsl_debug(\u0022%s: created %s\u005cn\u0022, __func__, sqlite3_path);\n#endif\n\tsqlite3_extended_result_codes(*pdb, 1);\n\n\treturn 0;\n}\n\nint\nlws_struct_sq3_close(sqlite3 **pdb)\n{\n\tint n;\n\n\tif (!*pdb)\n\t\treturn 0;\n\n\tn \u003d sqlite3_close(*pdb);\n\tif (n !\u003d SQLITE_OK) {\n\t\t/*\n\t\t * trouble...\n\t\t */\n\t\tlwsl_err(\u0022%s: failed to close: %d\u005cn\u0022, __func__, n);\n\t\treturn 1;\n\t}\n\t*pdb \u003d NULL;\n\n\treturn 0;\n}\n","s":{"c":1660269965,"u": 708}} ],"g": 1276,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0