? gcc.linux.exe.debug
? gcc.linux.lib.debug
? gcc.linux.obj.debug
? gcc.linux.obj.debug-mt
? gtkchat/gcc.linux.exe.debug
? gtkchat/gcc.linux.obj.debug-mt
? gtkmonitor/gcc.linux.exe.debug
? gtkmonitor/gcc.linux.obj.debug-mt
? gtkuseredit/gcc.linux.exe.debug
? gtkuseredit/gcc.linux.obj.debug-mt
? gtkuserlist/gcc.linux.exe.debug
? gtkuserlist/gcc.linux.obj.debug-mt
? scfg/gcc.linux.exe.debug
? scfg/gcc.linux.lib.debug
? scfg/gcc.linux.obj.debug-mt
? syncview/gcc.linux.exe.debug
? syncview/gcc.linux.obj.debug-mt
? uedit/gcc.linux.exe.debug
? uedit/gcc.linux.obj.debug-mt
Index: GNUmakefile
===================================================================
RCS file: /cvsroot/sbbs/src/sbbs3/GNUmakefile,v
retrieving revision 1.211
diff -u -p -r1.211 GNUmakefile
--- GNUmakefile	15 Oct 2007 08:06:00 -0000	1.211
+++ GNUmakefile	5 May 2008 00:50:28 -0000
@@ -117,6 +117,8 @@ ifndef CRYPTLIBDIR
 endif
 LDFLAGS	+=	-L$(CRYPTLIBDIR)
 
+LDFLAGS +=  -L/usr/lib/libsqlite3 -lsqlite3 
+
 include sbbsdefs.mk
 MT_CFLAGS	+=	$(SBBSDEFS)
 
Index: js_global.c
===================================================================
RCS file: /cvsroot/sbbs/src/sbbs3/js_global.c,v
retrieving revision 1.218
diff -u -p -r1.218 js_global.c
--- js_global.c	24 Feb 2008 09:23:34 -0000	1.218
+++ js_global.c	5 May 2008 00:50:34 -0000
@@ -3672,6 +3672,10 @@ JSObject* DLLCALL js_CreateCommonObjects
 	if(js_CreateUserClass(js_cx, js_glob, cfg)==NULL) 
 		return(NULL);
 
+    /* Sqlite Class */ 
+    if(js_CreateSqliteClass(js_cx, js_glob)==NULL) 
+        return(NULL); 
+
 	/* Area Objects */
 	if(!js_CreateUserObjects(js_cx, js_glob, cfg, NULL, NULL, NULL)) 
 		return(NULL);
Index: js_sqlite.c
===================================================================
RCS file: js_sqlite.c
diff -N js_sqlite.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ js_sqlite.c	5 May 2008 00:50:34 -0000
@@ -0,0 +1,487 @@
+/* jsp_sqlite.c */
+
+/* Synchronet JavaScript "Sqlite" Object */
+
+/* $Id: js_sqlite.c,v 1.99 2006/07/21 04:26:17 deuce Exp $ */
+
+/****************************************************************************
+ * @format.tab-size 4		(Plain Text/Source Code File Header)			*
+ * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
+ *																			*
+ * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html		*
+ *																			*
+ * This program is free software; you can redistribute it and/or			*
+ * modify it under the terms of the GNU General Public License				*
+ * as published by the Free Software Foundation; either version 2			*
+ * of the License, or (at your option) any later version.					*
+ * See the GNU General Public License for more details: gpl.txt or			*
+ * http://www.fsf.org/copyleft/gpl.html										*
+ *																			*
+ * Anonymous FTP access to the most recent released source is available at	*
+ * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
+ *																			*
+ * Anonymous CVS access to the development source and modification history	*
+ * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
+ * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
+ *     (just hit return, no password is necessary)							*
+ * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
+ *																			*
+ * For Synchronet coding style and modification guidelines, see				*
+ * http://www.synchro.net/source.html										*
+ *																			*
+ * You are encouraged to submit any modifications (preferably in Unix diff	*
+ * format) via e-mail to mods@synchro.net									*
+ *																			*
+ * Note: If this box doesn't appear square, then you need to fix your tabs.	*
+ ****************************************************************************/
+
+#include "sbbs.h"
+#include "sqlite3.h"
+#ifdef JAVASCRIPT
+
+#include "jsdate.h"	/* Yes, I know this is a private header file */
+
+typedef struct
+{
+	sqlite3*	db; /* pointer to sqlite db */
+	char	name[MAX_PATH+1]; /* db filename */
+	char*	stmt; /* sql query */
+	BOOL	external;	/* externally created, don't close */
+	BOOL	debug; 
+    char*   errormsg; /* last error message */
+
+} private_t;
+
+static const char* getprivate_failure = "line %d %s JS_GetPrivate failed";
+
+static void dbprintf(BOOL error, private_t* p, char* fmt, ...)
+{
+	va_list argptr;
+	char sbuf[1024];
+
+	if(p==NULL || (!p->debug && !error))
+		return;
+
+    va_start(argptr,fmt);
+    vsnprintf(sbuf,sizeof(sbuf),fmt,argptr);
+	sbuf[sizeof(sbuf)-1]=0;
+    va_end(argptr);
+	lprintf(LOG_DEBUG,"Sqlite: %s" , sbuf);
+	//lprintf(LOG_DEBUG,"%04u File %s%s",p->fp ? fileno(p->fp) : 0,error ? "ERROR: ":"",sbuf);
+}
+
+
+/* Sqlite Object Methods */
+
+static JSBool
+js_open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+	int         rc;
+	jsint		bufsize=2*1024;
+	JSString*	str;
+	private_t*	p;
+
+	*rval = JSVAL_FALSE;
+
+	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
+		JS_ReportError(cx,getprivate_failure,WHERE);
+		return(JS_FALSE);
+	}
+
+	if(p->db!=NULL)  {
+        dbprintf(FALSE,p, "db already open");
+        *rval = JSVAL_TRUE;
+		return(JS_TRUE);
+    }
+    else {
+        dbprintf(FALSE, p , "triying open");
+        rc = sqlite3_open(p->name,&p->db);
+    
+        if( rc ) {
+            sqlite3_close(p->db);
+            *rval = JSVAL_FALSE;
+            p->errormsg = "can't open the database (path/permissions incorrect?)";
+            dbprintf(FALSE, p, "can't open: %s",p->name);
+            return (JS_TRUE);
+        }
+    }
+    dbprintf(FALSE,p , "opened!");
+    *rval = JSVAL_TRUE;
+	return(JS_TRUE);
+}
+
+
+static JSBool
+js_close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+	private_t*	p;
+
+	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
+		JS_ReportError(cx,getprivate_failure,WHERE);
+		return(JS_FALSE);
+	}
+
+	if(p->db==NULL) {
+        *rval = JSVAL_FALSE;
+		return(JS_TRUE);
+    }
+    sqlite3_close(p->db);
+    
+	dbprintf(FALSE, p, "closed: %s" , p->name);
+    
+	p->db=NULL; 
+    *rval = JSVAL_TRUE;
+	return(JS_TRUE);
+}
+static JSBool
+js_exec(JSContext *cx, JSObject *parent, uintN argc, jsval *argv, jsval *rval)
+{ 
+    int rc,i;
+	private_t*	    p;
+    JSString*       str;
+    JSObject*       Record; // record object
+    JSObject*       Result; // array of records
+    sqlite3_stmt    *ppStmt;
+	jsval           val;
+    jsuint          idx;
+    char*           column_name; // column name of Record
+    
+	if((p=(private_t*)JS_GetPrivate(cx,parent))==NULL) {
+		JS_ReportError(cx,getprivate_failure,WHERE);
+		return(JS_FALSE);
+	}
+    // use the parameter as query
+    if (argc > 0) {
+        dbprintf (FALSE, p, "exec has stmt");
+        str = JS_ValueToString(cx, argv[0]);
+        if( str != NULL) {
+            p->stmt = JS_GetStringBytes(str);
+            dbprintf (FALSE, p, "exec param: %s", p->stmt);
+        }
+    }
+	if(p->db==NULL) {
+        dbprintf(TRUE, p, "database is not opened");
+        *rval = JSVAL_FALSE;
+		return(JS_TRUE);
+    }
+
+    dbprintf(FALSE, p, "create Result object");
+   	if((Result=JS_NewArrayObject(cx, 0, NULL))==NULL) 
+		return(JS_FALSE);
+
+    if (p->stmt == NULL) {
+        dbprintf(FALSE, p, "empy statement");
+        p->errormsg = "empty statement";
+        *rval = JSVAL_FALSE;
+        return(JS_TRUE);
+    }
+        
+
+    dbprintf (FALSE,p, "prepare: %s",p->stmt);
+    rc = sqlite3_prepare(p->db, p->stmt, -1, &ppStmt, NULL);
+
+    if (rc == SQLITE_OK) {
+        while (sqlite3_step(ppStmt) == SQLITE_ROW) {
+            dbprintf(FALSE, p, "create record object");
+            if((Record=JS_NewObject(cx, NULL, NULL, NULL))==NULL) 
+                return(JS_FALSE);
+            
+            for (i=0; i<sqlite3_column_count(ppStmt); i++) {
+                
+                switch (sqlite3_column_type(ppStmt,i)) {
+                    case SQLITE_INTEGER:
+                        val = INT_TO_JSVAL(sqlite3_column_int(ppStmt,i)); 
+                        break;
+                    case SQLITE_TEXT:
+                        val = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, sqlite3_column_text(ppStmt,i)));
+                        break;
+                    case SQLITE_BLOB:
+                        break;
+                    }
+                
+                if(!JS_SetProperty(cx, Record, sqlite3_column_name(ppStmt,i), &val))
+                    return(JS_FALSE);
+            }
+            dbprintf (FALSE, p , "adding element to the Result");
+            val = OBJECT_TO_JSVAL(Record);
+            idx = -1 ;
+            
+   			if(!JS_GetArrayLength(cx, Result, &idx))
+				return(JS_FALSE);
+
+            if (!JS_SetElement(cx, Result, idx, &val))
+                return(JS_FALSE);
+        }
+        dbprintf(FALSE, p , "end prepare");
+        *rval = OBJECT_TO_JSVAL(Result);
+        return(JS_TRUE);
+    }
+    else {
+        p->errormsg = (char* ) sqlite3_errmsg(p->db);
+        *rval = JSVAL_FALSE;
+        dbprintf(FALSE, p , "prepare error: %s", sqlite3_errmsg(p->db));
+        return(JS_TRUE);
+    }
+}
+
+/* Sqlite Object Properites */
+enum {
+	 SQLITE_PROP_NAME		
+	,SQLITE_PROP_STMT
+    ,SQLITE_PROP_DEBUG
+    ,SQLITE_PROP_ERRORMSG
+};
+
+
+static JSBool js_sqlite_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+{
+    jsint       tiny;
+	private_t*	p;
+    int32       intval=0;
+    JSString*	js_str;
+    char*		strval=NULL;
+
+	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
+		JS_ReportError(cx,getprivate_failure,WHERE);
+		return(JS_FALSE);
+	}
+ 
+    tiny = JSVAL_TO_INT(id);
+
+	if(JSVAL_IS_NUM(*vp))
+		JS_ValueToInt32(cx, *vp, &intval);
+    else if (JSVAL_IS_BOOLEAN(*vp))
+        JS_ValueToBoolean(cx,*vp,&intval);
+	else if(JSVAL_IS_STRING(*vp)) {
+		if((js_str = JS_ValueToString(cx, *vp))==NULL)
+			return(JS_FALSE);
+		strval=JS_GetStringBytes(js_str);
+	}
+
+	dbprintf(FALSE, p, "setting property %d",tiny);
+    
+	switch(tiny) {
+        case SQLITE_PROP_NAME:
+            SAFECOPY(p->name, strval);
+            break;
+        case SQLITE_PROP_STMT:
+            p->stmt = strval;
+            break;
+		case SQLITE_PROP_DEBUG:
+            p->debug = intval;
+			break;
+	}
+
+	return(JS_TRUE);
+}
+
+static JSBool js_sqlite_get(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
+{
+	private_t*	p;
+    jsint       tiny;
+	JSString*	js_str=NULL;
+
+	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
+		JS_ReportError(cx,getprivate_failure,WHERE);
+		return(JS_FALSE);
+	}
+
+    tiny = JSVAL_TO_INT(id);
+
+	dbprintf(FALSE, p, "getting property %d",tiny);
+
+	switch(tiny) {
+		case SQLITE_PROP_NAME:
+			if((js_str=JS_NewStringCopyZ(cx, p->name))==NULL)
+				return(JS_FALSE);
+			*vp = STRING_TO_JSVAL(js_str);
+			break;
+		case SQLITE_PROP_STMT:
+			if((js_str=JS_NewStringCopyZ(cx, p->stmt))==NULL)
+				return(JS_FALSE);
+			*vp = STRING_TO_JSVAL(js_str);
+			break;
+		case SQLITE_PROP_DEBUG:
+			*vp = BOOLEAN_TO_JSVAL(p->debug);
+			break;
+		case SQLITE_PROP_ERRORMSG:
+			if((js_str=JS_NewStringCopyZ(cx, p->errormsg))==NULL)
+				return(JS_FALSE);
+			*vp = STRING_TO_JSVAL(js_str);
+			break;
+	}
+
+	return(JS_TRUE);
+}
+
+#define SQLITE_PROP_FLAGS JSPROP_ENUMERATE|JSPROP_READONLY
+
+static jsSyncPropertySpec js_sqlite_properties[] = {
+/*		 name				,tinyid					,flags,				ver	*/
+	{	"name"				,SQLITE_PROP_NAME			,JSPROP_ENUMERATE|JSPROP_READONLY,	310},
+    {	"stmt"				,SQLITE_PROP_STMT			,JSPROP_ENUMERATE,	310},
+	{	"debug"				,SQLITE_PROP_DEBUG	    	,JSPROP_ENUMERATE,	310},
+	{	"errormsg"			,SQLITE_PROP_ERRORMSG		,JSPROP_ENUMERATE|JSPROP_READONLY,	310},
+	{0}
+};
+
+#ifdef BUILD_JSDOCS
+static char* sqlite_prop_desc[] = {
+	 "filename specified in constructor - <small>READ ONLY</small>"
+    ,"string sql statement"
+	,"set to <i>true</i> to enable debug log output"
+	,"get the last error message - <small>READ ONLY</small>"
+	,NULL
+};
+#endif
+
+
+static jsSyncMethodSpec js_sqlite_functions[] = {
+	{"open",			js_open,			1,	JSTYPE_BOOLEAN,	JSDOCSTR("Open the database")
+	,JSDOCSTR("open the sqlite3 database"
+		)
+	,310
+	},		
+	{"close",			js_close,			0,	JSTYPE_VOID,	JSDOCSTR("")
+	,JSDOCSTR("close database")
+	,310
+	},		
+	{"exec",			js_exec,			0,	JSTYPE_BOOLEAN, JSDOCSTR("")
+	,JSDOCSTR("exec the sql query on database")
+	,310
+	},
+	{0}
+};
+
+/* File Destructor */
+
+static void js_finalize_sqlite(JSContext *cx, JSObject *obj)
+{
+	private_t* p;
+	
+	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
+		return;
+
+	if(p->external==JS_FALSE && p->db!=NULL)
+		sqlite3_close(p->db);
+    //sqlite3_free(p->errormsg);
+    
+	dbprintf(FALSE, p, "finalize Sqlite object");
+
+	free(p);
+
+	JS_SetPrivate(cx, obj, NULL);
+}
+
+static JSClass js_sqlite_class = {
+     "Sqlite"				/* name			*/
+    ,JSCLASS_HAS_PRIVATE	/* flags		*/
+	,JS_PropertyStub		/* addProperty	*/
+	,JS_PropertyStub		/* delProperty	*/
+	,js_sqlite_get			/* getProperty	*/
+	,js_sqlite_set			/* setProperty	*/
+	,JS_EnumerateStub		/* enumerate	*/
+	,JS_ResolveStub			/* resolve		*/
+	,JS_ConvertStub			/* convert		*/
+	,js_finalize_sqlite		/* finalize		*/
+};
+
+/* Sqlite Constructor (creates database object) */
+
+static JSBool
+js_sqlite_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
+{
+	JSString*	str;
+	private_t*	p;
+
+	if((str = JS_ValueToString(cx, argv[0]))==NULL) {
+		JS_ReportError(cx,"No filename specified");
+		return(JS_FALSE);
+	}
+
+	*rval = JSVAL_VOID;
+
+	if((p=(private_t*)calloc(1,sizeof(private_t)))==NULL) {
+		JS_ReportError(cx,"calloc failed");
+		return(JS_FALSE);
+	}
+
+	SAFECOPY(p->name,JS_GetStringBytes(str));
+
+	if(!JS_SetPrivate(cx, obj, p)) {
+		dbprintf(TRUE, p, "JS_SetPrivate failed\n");
+		return(JS_FALSE);
+	}
+
+	if(!js_DefineSyncProperties(cx, obj, js_sqlite_properties)) {
+		dbprintf(TRUE, p, "js_DefineSyncProperties failed\n");
+		return(JS_FALSE);
+	}
+
+	if(!js_DefineSyncMethods(cx, obj, js_sqlite_functions, FALSE)) {
+		dbprintf(TRUE, p, "js_DefineSyncMethods failed\n");
+		return(JS_FALSE);
+	}
+
+#ifdef BUILD_JSDOCS
+	js_DescribeSyncObject(cx,obj,"Can used to manipulate sqlite database"
+			,310
+			);
+	js_DescribeSyncConstructor(cx,obj,"To create a new Sqlite object: <tt>var f = new Sqlite(<i>filename</i>)</tt>");
+	js_CreateArrayOfStrings(cx, obj, "_property_desc_list", sqlite_prop_desc, JSPROP_READONLY);
+#endif
+
+	dbprintf(FALSE, p, "object constructed\n");
+	return(JS_TRUE);
+}
+
+JSObject* DLLCALL js_CreateSqliteClass(JSContext* cx, JSObject* parent)
+{
+	JSObject*	obj;
+
+	obj = JS_InitClass(cx, parent, NULL
+		,&js_sqlite_class
+		,js_sqlite_constructor
+		,1		/* number of constructor args */
+		,NULL	/* props, set in constructor */
+		,NULL	/* funcs, set in constructor */
+		,NULL,NULL);
+
+	return(obj);
+}
+
+JSObject* DLLCALL js_CreateSqliteObject(JSContext* cx, JSObject* parent, char *name, sqlite3* db)
+{
+	JSObject* obj;
+	private_t*	p;
+
+	obj = JS_DefineObject(cx, parent, name, &js_sqlite_class, NULL
+		,JSPROP_ENUMERATE|JSPROP_READONLY);
+
+	if(obj==NULL)
+		return(NULL);
+
+	if(!js_DefineSyncProperties(cx, obj, js_sqlite_properties))
+		return(NULL);
+
+	if (!js_DefineSyncMethods(cx, obj, js_sqlite_functions, FALSE)) 
+		return(NULL);
+
+	if((p=(private_t*)calloc(1,sizeof(private_t)))==NULL)
+		return(NULL);
+
+	p->db=db;
+	p->debug=JS_FALSE;
+	p->external=JS_TRUE;
+    p->errormsg = JS_FALSE;
+	if(!JS_SetPrivate(cx, obj, p)) {
+		dbprintf(TRUE, p, "JS_SetPrivate failed\n");
+		return(NULL);
+	}
+
+	dbprintf(FALSE, p, "object created\n");
+
+	return(obj);
+}
+
+#endif	/* JAVASCRIPT */
Index: objects.mk
===================================================================
RCS file: /cvsroot/sbbs/src/sbbs3/objects.mk,v
retrieving revision 1.46
diff -u -p -r1.46 objects.mk
--- objects.mk	14 Mar 2006 09:33:29 -0000	1.46
+++ objects.mk	5 May 2008 00:50:34 -0000
@@ -55,6 +55,7 @@ OBJS	=	$(MTOBJODIR)$(DIRSEP)ansiterm$(OF
 			$(MTOBJODIR)$(DIRSEP)js_sprintf$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)js_system$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)js_user$(OFILE)\
+			$(MTOBJODIR)$(DIRSEP)js_sqlite$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)js_xtrn_area$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)listfile$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)load_cfg$(OFILE)\
Index: sbbs.h
===================================================================
RCS file: /cvsroot/sbbs/src/sbbs3/sbbs.h,v
retrieving revision 1.315
diff -u -p -r1.315 sbbs.h
--- sbbs.h	19 Mar 2008 00:24:44 -0000	1.315
+++ sbbs.h	5 May 2008 00:50:36 -0000
@@ -1057,6 +1057,9 @@ extern "C" {
 	/* js_file.c */
 	DLLEXPORT JSObject* DLLCALL js_CreateFileClass(JSContext* cx, JSObject* parent);
 
+    /* js_sqlite.c */ 
+    DLLEXPORT JSObject* DLLCALL js_CreateSqliteClass(JSContext* cx, JSObject* parent);
+
 	/* js_sprintf.c */
 	DLLEXPORT char*		DLLCALL js_sprintf(JSContext* cx, uint argn, uintN argc, jsval *argv);
 	DLLEXPORT void		DLLCALL js_sprintf_free(char *);
Index: sbbsdefs.h
===================================================================
RCS file: /cvsroot/sbbs/src/sbbs3/sbbsdefs.h,v
retrieving revision 1.154
diff -u -p -r1.154 sbbsdefs.h
--- sbbsdefs.h	23 Feb 2008 22:35:09 -0000	1.154
+++ sbbsdefs.h	5 May 2008 00:50:40 -0000
@@ -50,7 +50,7 @@
 /* Constants */
 /*************/
 
-#define VERSION 	"3.15"  /* Version: Major.minor  */
+#define VERSION 	"3.15Sqlite by Ragnarok"  /* Version: Major.minor  */
 #define REVISION	'a'     /* Revision: lowercase letter */
 #define VERSION_NUM	(31500	 + (tolower(REVISION)-'a'))
 #define VERSION_HEX	(0x31500 + (tolower(REVISION)-'a'))
