mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[quickjs] localstorage const
This commit is contained in:
parent
9d01a943b3
commit
348d2ac490
@ -36,7 +36,7 @@ db_prepare_structure(char *db_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
db_delete_from(char *db_name, char *key)
|
db_delete_from(char *db_name, const char *key)
|
||||||
{
|
{
|
||||||
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
@ -65,7 +65,7 @@ db_delete_from(char *db_name, char *key)
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
db_insert_into(char *db_name, char *key, char *value)
|
db_insert_into(char *db_name, const char *key, const char *value)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
@ -92,7 +92,7 @@ db_insert_into(char *db_name, char *key, char *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
db_update_set(char *db_name, char *key, char *value)
|
db_update_set(char *db_name, const char *key, const char *value)
|
||||||
{
|
{
|
||||||
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
@ -120,7 +120,7 @@ db_update_set(char *db_name, char *key, char *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
db_query_by_value(char *db_name, char *value)
|
db_query_by_value(char *db_name, const char *value)
|
||||||
{
|
{
|
||||||
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
@ -140,7 +140,7 @@ db_query_by_value(char *db_name, char *value)
|
|||||||
rc=sqlite3_prepare_v2(db, "SELECT key FROM storage WHERE value = ? LIMIT 1;", -1, &stmt, NULL);
|
rc=sqlite3_prepare_v2(db, "SELECT key FROM storage WHERE value = ? LIMIT 1;", -1, &stmt, NULL);
|
||||||
rc=sqlite3_bind_text(stmt, 1, value, strlen(value), SQLITE_STATIC);
|
rc=sqlite3_bind_text(stmt, 1, value, strlen(value), SQLITE_STATIC);
|
||||||
|
|
||||||
if ((const char*) sqlite3_column_text(stmt,1)!= NULL) {
|
if (sqlite3_column_text(stmt,1)!= NULL) {
|
||||||
result=stracpy((const char *)sqlite3_column_text(stmt, 1));
|
result=stracpy((const char *)sqlite3_column_text(stmt, 1));
|
||||||
} else {
|
} else {
|
||||||
result=stracpy("");
|
result=stracpy("");
|
||||||
@ -152,7 +152,7 @@ db_query_by_value(char *db_name, char *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
db_query_by_key(char *db_name, char *key)
|
db_query_by_key(char *db_name, const char *key)
|
||||||
{
|
{
|
||||||
|
|
||||||
sqlite3_stmt *stmt;
|
sqlite3_stmt *stmt;
|
||||||
@ -172,8 +172,8 @@ db_query_by_key(char *db_name, char *key)
|
|||||||
rc=sqlite3_prepare_v2(db, "SELECT * FROM storage WHERE key = ? LIMIT 1;", -1, &stmt, NULL);
|
rc=sqlite3_prepare_v2(db, "SELECT * FROM storage WHERE key = ? LIMIT 1;", -1, &stmt, NULL);
|
||||||
rc=sqlite3_bind_text(stmt, 1, key, strlen(key), SQLITE_STATIC);
|
rc=sqlite3_bind_text(stmt, 1, key, strlen(key), SQLITE_STATIC);
|
||||||
rc=sqlite3_step(stmt);
|
rc=sqlite3_step(stmt);
|
||||||
if ((const char*) sqlite3_column_text(stmt,1)!= NULL) {
|
if (sqlite3_column_text(stmt,1)!= NULL) {
|
||||||
result=stracpy((const unsigned char *)sqlite3_column_text(stmt, 1));
|
result=stracpy((const char *)sqlite3_column_text(stmt, 1));
|
||||||
} else {
|
} else {
|
||||||
result = nullptr;
|
result = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int db_prepare_structure(char *db_name);
|
int db_prepare_structure(char *db_name);
|
||||||
int db_delete_from(char *db_name, char *key);
|
int db_delete_from(char *db_name, const char *key);
|
||||||
int db_insert_into(char *db_name, char *key, char *value);
|
int db_insert_into(char *db_name, const char *key, const char *value);
|
||||||
int db_update_set(char *db_name, char *key, char *value);
|
int db_update_set(char *db_name, const char *key, const char *value);
|
||||||
char * db_query_by_key(char *db_name, char *key);
|
char * db_query_by_key(char *db_name, const char *key);
|
||||||
char * db_qry_by_value(char *db_name, char *val);
|
char * db_qry_by_value(char *db_name, const char *val);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,11 +54,11 @@
|
|||||||
static JSClassID js_localstorage_class_id;
|
static JSClassID js_localstorage_class_id;
|
||||||
|
|
||||||
/* IMPLEMENTS READ FROM STORAGE USING SQLITE DATABASE */
|
/* IMPLEMENTS READ FROM STORAGE USING SQLITE DATABASE */
|
||||||
static unsigned char *
|
static char *
|
||||||
readFromStorage(const unsigned char *key)
|
readFromStorage(const char *key)
|
||||||
{
|
{
|
||||||
|
|
||||||
char * val;
|
char *val;
|
||||||
|
|
||||||
if (local_storage_ready==0)
|
if (local_storage_ready==0)
|
||||||
{
|
{
|
||||||
@ -70,11 +70,11 @@ readFromStorage(const unsigned char *key)
|
|||||||
|
|
||||||
//DBG("Read: %s %s %s",local_storage_filename, key, val);
|
//DBG("Read: %s %s %s",local_storage_filename, key, val);
|
||||||
|
|
||||||
return (val);
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
removeFromStorage(const unsigned char *key)
|
removeFromStorage(const char *key)
|
||||||
{
|
{
|
||||||
if (local_storage_ready==0)
|
if (local_storage_ready==0)
|
||||||
{
|
{
|
||||||
@ -86,7 +86,7 @@ removeFromStorage(const unsigned char *key)
|
|||||||
|
|
||||||
/* IMPLEMENTS SAVE TO STORAGE USING SQLITE DATABASE */
|
/* IMPLEMENTS SAVE TO STORAGE USING SQLITE DATABASE */
|
||||||
static void
|
static void
|
||||||
saveToStorage(const unsigned char *key, const unsigned char *val)
|
saveToStorage(const char *key, const char *val)
|
||||||
{
|
{
|
||||||
if (local_storage_ready==0) {
|
if (local_storage_ready==0) {
|
||||||
db_prepare_structure(local_storage_filename);
|
db_prepare_structure(local_storage_filename);
|
||||||
@ -125,7 +125,7 @@ js_localstorage_getitem(JSContext *ctx, JSValueConst this_val, int argc, JSValue
|
|||||||
return JS_EXCEPTION;
|
return JS_EXCEPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *val = readFromStorage(key);
|
char *val = readFromStorage(key);
|
||||||
JS_FreeCString(ctx, key);
|
JS_FreeCString(ctx, key);
|
||||||
|
|
||||||
if (!val) {
|
if (!val) {
|
||||||
@ -224,31 +224,6 @@ static JSClassDef js_localstorage_class = {
|
|||||||
"localStorage",
|
"localStorage",
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSValue
|
|
||||||
js_localstorage_ctor(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv)
|
|
||||||
{
|
|
||||||
JSValue obj = JS_UNDEFINED;
|
|
||||||
JSValue proto;
|
|
||||||
/* using new_target to get the prototype is necessary when the
|
|
||||||
class is extended. */
|
|
||||||
proto = JS_GetPropertyStr(ctx, new_target, "prototype");
|
|
||||||
|
|
||||||
if (JS_IsException(proto)) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
obj = JS_NewObjectProtoClass(ctx, proto, js_localstorage_class_id);
|
|
||||||
JS_FreeValue(ctx, proto);
|
|
||||||
|
|
||||||
if (JS_IsException(obj)) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
RETURN_JS(obj);
|
|
||||||
|
|
||||||
fail:
|
|
||||||
JS_FreeValue(ctx, obj);
|
|
||||||
return JS_EXCEPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
js_localstorage_init(JSContext *ctx)
|
js_localstorage_init(JSContext *ctx)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user