From c0a90ae4c6cfcd24976ae43c50ca3cd1879229dd Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Mon, 16 Apr 2001 23:53:36 +0000 Subject: [PATCH] New file_area object. --- src/sbbs3/fileobj.c | 158 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 src/sbbs3/fileobj.c diff --git a/src/sbbs3/fileobj.c b/src/sbbs3/fileobj.c new file mode 100644 index 0000000000..34081a4b69 --- /dev/null +++ b/src/sbbs3/fileobj.c @@ -0,0 +1,158 @@ +/* fileobj.c */ + +/* Synchronet JavaScript "File Area" Object */ + +/* $Id$ */ + +/**************************************************************************** + * @format.tab-size 4 (Plain Text/Source Code File Header) * + * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * + * * + * Copyright 2001 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" + +#ifdef JAVASCRIPT + +static JSClass js_file_area_class = { + "FileArea" /* name */ + ,JSCLASS_HAS_PRIVATE /* flags */ + ,JS_PropertyStub /* addProperty */ + ,JS_PropertyStub /* delProperty */ + ,JS_PropertyStub /* getProperty */ + ,JS_PropertyStub /* setProperty */ + ,JS_EnumerateStub /* enumerate */ + ,JS_ResolveStub /* resolve */ + ,JS_ConvertStub /* convert */ + ,JS_FinalizeStub /* finalize */ +}; + +JSObject* DLLCALL js_CreateFileAreaObject(scfg_t* cfg, JSContext* cx, JSObject* parent, user_t* user + ,char* html_index_file) +{ + char vpath[MAX_PATH+1]; + JSObject* areaobj; + JSObject* libobj; + JSObject* dirobj; + JSObject* lib_list; + JSObject* dir_list; + jsval val; + jsint index; + uint l,d; + + areaobj = JS_DefineObject(cx, parent, "file_area", &js_file_area_class, NULL, 0); + + if(areaobj==NULL) + return(NULL); + + /* lib_list[] */ + if((lib_list=JS_NewArrayObject(cx, 0, NULL))==NULL) + return(NULL); + + val=OBJECT_TO_JSVAL(lib_list); + if(!JS_SetProperty(cx, areaobj, "lib_list", &val)) + return(NULL); + + for(l=0;l<cfg->total_libs;l++) { + + if(!chk_ar(cfg,cfg->lib[l]->ar,user)) + continue; + + if((libobj=JS_NewObject(cx, &js_file_area_class, NULL, NULL))==NULL) + return(NULL); + + val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cfg->lib[l]->sname)); + if(!JS_SetProperty(cx, libobj, "name", &val)) + return(NULL); + + val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cfg->lib[l]->lname)); + if(!JS_SetProperty(cx, libobj, "description", &val)) + return(NULL); + + sprintf(vpath,"/%s/%s",cfg->lib[l]->sname,html_index_file); + val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx, vpath)); + if(!JS_SetProperty(cx, libobj, "link", &val)) + return(NULL); + + /* dir_list[] */ + if((dir_list=JS_NewArrayObject(cx, 0, NULL))==NULL) + return(NULL); + + val=OBJECT_TO_JSVAL(dir_list); + if(!JS_SetProperty(cx, libobj, "dir_list", &val)) + return(NULL); + + + for(d=0;d<cfg->total_dirs;d++) { + if(cfg->dir[d]->lib!=l) + continue; + if(!chk_ar(cfg,cfg->dir[d]->dl,user)) + continue; + + if((dirobj=JS_NewObject(cx, &js_file_area_class, NULL, NULL))==NULL) + return(NULL); + + val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cfg->dir[d]->code)); + if(!JS_SetProperty(cx, dirobj, "code", &val)) + return(NULL); + + val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cfg->dir[d]->sname)); + if(!JS_SetProperty(cx, dirobj, "name", &val)) + return(NULL); + + val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx, cfg->dir[d]->lname)); + if(!JS_SetProperty(cx, dirobj, "description", &val)) + return(NULL); + + sprintf(vpath,"/%s/%s/%s" + ,cfg->lib[l]->sname + ,cfg->dir[d]->code + ,html_index_file); + + val=STRING_TO_JSVAL(JS_NewStringCopyZ(cx, vpath)); + if(!JS_SetProperty(cx, dirobj, "link", &val)) + return(NULL); + + if(!JS_GetArrayLength(cx, dir_list, &index)) + return(NULL); + + val=OBJECT_TO_JSVAL(dirobj); + JS_SetElement(cx, dir_list, index, &val); + } + + if(!JS_GetArrayLength(cx, lib_list, &index)) + return(NULL); + + val=OBJECT_TO_JSVAL(libobj); + JS_SetElement(cx, lib_list, index, &val); + } + + return(areaobj); +} + +#endif /* JAVSCRIPT */ \ No newline at end of file -- GitLab