|
|
1.1 ! root 1: /* js_file_area.c */ ! 2: ! 3: /* Synchronet JavaScript "File Area" Object */ ! 4: ! 5: /* $Id: js_file_area.c,v 1.45 2006/12/28 02:45:27 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #include "sbbs.h" ! 39: ! 40: #ifdef JAVASCRIPT ! 41: ! 42: #ifdef BUILD_JSDOCS ! 43: ! 44: static char* file_area_prop_desc[] = { ! 45: "minimum amount of available disk space (in bytes) required for user uploads to be allowed" ! 46: ,"file area settings (bitfield) - see <tt>FM_*</tt> in <tt>sbbsdefs.js</tt> for details" ! 47: ,NULL ! 48: }; ! 49: ! 50: ! 51: static char* lib_prop_desc[] = { ! 52: "index into lib_list array (or -1 if not in array) <i>(introduced in v3.12)</i>" ! 53: ,"unique number for this library" ! 54: ,"library name" ! 55: ,"library description" ! 56: ,"library access requirements" ! 57: ,"library link (for HTML index)" ! 58: ,NULL ! 59: }; ! 60: ! 61: static char* dir_prop_desc[] = { ! 62: ! 63: "index into dir_list array (or -1 if not in array) <i>(introduced in v3.12)</i>" ! 64: ,"unique number for this directory" ! 65: ,"library index <i>(introduced in v3.12)</i>" ! 66: ,"library number" ! 67: ,"library name <i>(introduced in v3.12)</i>" ! 68: ,"directory internal code" ! 69: ,"directory name" ! 70: ,"directory description" ! 71: ,"directory file storage location" ! 72: ,"directory access requirements" ! 73: ,"directory upload requirements" ! 74: ,"directory download requirements" ! 75: ,"directory exemption requirements" ! 76: ,"directory operator requirements" ! 77: ,"allowed file extensions (comma delimited)" ! 78: ,"upload semaphore file" ! 79: ,"directory data storage location" ! 80: ,"toggle options (bitfield)" ! 81: ,"sequential (slow storage) device number" ! 82: ,"sort order (see <tt>SORT_*</tt> in <tt>sbbsdefs.js</tt> for valid values)" ! 83: ,"configured maximum number of files" ! 84: ,"configured maximum age (in days) of files before expiration" ! 85: ,"percent of file size awarded uploader in credits upon file upload" ! 86: ,"percent of file size awarded uploader in credits upon subsequent downloads" ! 87: ,"directory link (for HTML index)" ! 88: ,"user has sufficient access to upload files" ! 89: ,"user has sufficient access to download files" ! 90: ,"user is exempt from download credit costs" ! 91: ,"user has operator access to this directory" ! 92: ,"directory is for offline storage <i>(introduced in v3.14)</i>" ! 93: ,"directory is for uploads only <i>(introduced in v3.14)</i>" ! 94: ,"directory is for uploads to sysop only <i>(introduced in v3.14)</i>" ! 95: ,NULL ! 96: }; ! 97: #endif ! 98: ! 99: ! 100: JSObject* DLLCALL js_CreateFileAreaObject(JSContext* cx, JSObject* parent, scfg_t* cfg ! 101: ,user_t* user, char* html_index_file) ! 102: { ! 103: char vpath[MAX_PATH+1]; ! 104: JSObject* areaobj; ! 105: JSObject* alllibs; ! 106: JSObject* alldirs; ! 107: JSObject* libobj; ! 108: JSObject* dirobj; ! 109: JSObject* lib_list; ! 110: JSObject* dir_list; ! 111: JSString* js_str; ! 112: jsval val; ! 113: jsuint lib_index; ! 114: jsuint dir_index; ! 115: uint l,d; ! 116: ! 117: /* Return existing object if it's already been created */ ! 118: if(JS_GetProperty(cx,parent,"file_area",&val) && val!=JSVAL_VOID) ! 119: areaobj = JSVAL_TO_OBJECT(val); ! 120: else ! 121: areaobj = JS_DefineObject(cx, parent, "file_area", NULL ! 122: , NULL, JSPROP_ENUMERATE|JSPROP_READONLY); ! 123: if(areaobj==NULL) ! 124: return(NULL); ! 125: ! 126: /* file_area.properties */ ! 127: if(!JS_NewNumberValue(cx,cfg->min_dspace,&val)) ! 128: return(NULL); ! 129: if(!JS_SetProperty(cx, areaobj, "min_diskspace", &val)) ! 130: return(NULL); ! 131: ! 132: if(!JS_NewNumberValue(cx,cfg->file_misc,&val)) ! 133: return(NULL); ! 134: if(!JS_SetProperty(cx, areaobj, "settings", &val)) ! 135: return(NULL); ! 136: ! 137: /* file_area.lib[] */ ! 138: if((alllibs=JS_NewObject(cx, NULL, NULL, areaobj))==NULL) ! 139: return(NULL); ! 140: ! 141: val=OBJECT_TO_JSVAL(alllibs); ! 142: if(!JS_SetProperty(cx, areaobj, "lib", &val)) ! 143: return(NULL); ! 144: ! 145: /* file_area.dir[] */ ! 146: if((alldirs=JS_NewObject(cx, NULL, NULL, areaobj))==NULL) ! 147: return(NULL); ! 148: ! 149: val=OBJECT_TO_JSVAL(alldirs); ! 150: if(!JS_SetProperty(cx, areaobj, "dir", &val)) ! 151: return(NULL); ! 152: ! 153: if(html_index_file==NULL) ! 154: html_index_file=""; ! 155: ! 156: #ifdef BUILD_JSDOCS ! 157: js_DescribeSyncObject(cx,areaobj,"File Transfer Areas",310); ! 158: #endif ! 159: ! 160: /* file_area.lib_list[] */ ! 161: if((lib_list=JS_NewArrayObject(cx, 0, NULL))==NULL) ! 162: return(NULL); ! 163: ! 164: val=OBJECT_TO_JSVAL(lib_list); ! 165: if(!JS_SetProperty(cx, areaobj, "lib_list", &val)) ! 166: return(NULL); ! 167: ! 168: for(l=0;l<cfg->total_libs;l++) { ! 169: ! 170: if((libobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL) ! 171: return(NULL); ! 172: ! 173: val=OBJECT_TO_JSVAL(libobj); ! 174: lib_index=-1; ! 175: if(user==NULL || chk_ar(cfg,cfg->lib[l]->ar,user)) { ! 176: ! 177: if(!JS_GetArrayLength(cx, lib_list, &lib_index)) ! 178: return(NULL); ! 179: ! 180: if(!JS_SetElement(cx, lib_list, lib_index, &val)) ! 181: return(NULL); ! 182: } ! 183: ! 184: /* Add as property (associative array element) */ ! 185: if(!JS_DefineProperty(cx, alllibs, cfg->lib[l]->sname, val ! 186: ,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE)) ! 187: return(NULL); ! 188: ! 189: val=INT_TO_JSVAL(lib_index); ! 190: if(!JS_SetProperty(cx, libobj, "index", &val)) ! 191: return(NULL); ! 192: ! 193: val=INT_TO_JSVAL(l); ! 194: if(!JS_SetProperty(cx, libobj, "number", &val)) ! 195: return(NULL); ! 196: ! 197: if((js_str=JS_NewStringCopyZ(cx, cfg->lib[l]->sname))==NULL) ! 198: return(NULL); ! 199: val=STRING_TO_JSVAL(js_str); ! 200: if(!JS_SetProperty(cx, libobj, "name", &val)) ! 201: return(NULL); ! 202: ! 203: if((js_str=JS_NewStringCopyZ(cx, cfg->lib[l]->lname))==NULL) ! 204: return(NULL); ! 205: val=STRING_TO_JSVAL(js_str); ! 206: if(!JS_SetProperty(cx, libobj, "description", &val)) ! 207: return(NULL); ! 208: ! 209: if((js_str=JS_NewStringCopyZ(cx, cfg->lib[l]->arstr))==NULL) ! 210: return(NULL); ! 211: val=STRING_TO_JSVAL(js_str); ! 212: if(!JS_SetProperty(cx, libobj, "ars", &val)) ! 213: return(NULL); ! 214: ! 215: sprintf(vpath,"/%s/%s",cfg->lib[l]->sname,html_index_file); ! 216: if((js_str=JS_NewStringCopyZ(cx, vpath))==NULL) ! 217: return(NULL); ! 218: val=STRING_TO_JSVAL(js_str); ! 219: if(!JS_SetProperty(cx, libobj, "link", &val)) ! 220: return(NULL); ! 221: ! 222: #ifdef BUILD_JSDOCS ! 223: js_DescribeSyncObject(cx,libobj,"File Transfer Libraries (current user has access to)",310); ! 224: #endif ! 225: ! 226: /* dir_list[] */ ! 227: if((dir_list=JS_NewArrayObject(cx, 0, NULL))==NULL) ! 228: return(NULL); ! 229: ! 230: val=OBJECT_TO_JSVAL(dir_list); ! 231: if(!JS_SetProperty(cx, libobj, "dir_list", &val)) ! 232: return(NULL); ! 233: ! 234: for(d=0;d<cfg->total_dirs;d++) { ! 235: if(cfg->dir[d]->lib!=l) ! 236: continue; ! 237: ! 238: if((dirobj=JS_NewObject(cx, NULL, NULL, NULL))==NULL) ! 239: return(NULL); ! 240: ! 241: val=OBJECT_TO_JSVAL(dirobj); ! 242: dir_index=-1; ! 243: if(user==NULL || chk_ar(cfg,cfg->dir[d]->ar,user)) { ! 244: ! 245: if(!JS_GetArrayLength(cx, dir_list, &dir_index)) ! 246: return(NULL); ! 247: ! 248: if(!JS_SetElement(cx, dir_list, dir_index, &val)) ! 249: return(NULL); ! 250: } ! 251: ! 252: /* Add as property (associative array element) */ ! 253: if(!JS_DefineProperty(cx, alldirs, cfg->dir[d]->code, val ! 254: ,NULL,NULL,JSPROP_READONLY|JSPROP_ENUMERATE)) ! 255: return(NULL); ! 256: ! 257: if(d==cfg->user_dir ! 258: && !JS_DefineProperty(cx, areaobj, "user_dir", val ! 259: ,NULL,NULL,JSPROP_READONLY)) ! 260: return(NULL); ! 261: ! 262: if(d==cfg->sysop_dir ! 263: && !JS_DefineProperty(cx, areaobj, "sysop_dir", val ! 264: ,NULL,NULL,JSPROP_READONLY)) ! 265: return(NULL); ! 266: ! 267: if(d==cfg->upload_dir ! 268: && !JS_DefineProperty(cx, areaobj, "upload_dir", val ! 269: ,NULL,NULL,JSPROP_READONLY)) ! 270: return(NULL); ! 271: ! 272: if(d==cfg->lib[l]->offline_dir ! 273: && !JS_DefineProperty(cx, libobj, "offline_dir", val ! 274: ,NULL,NULL,JSPROP_READONLY)) ! 275: return(NULL); ! 276: ! 277: val=INT_TO_JSVAL(dir_index); ! 278: if(!JS_SetProperty(cx, dirobj, "index", &val)) ! 279: return(NULL); ! 280: ! 281: val=INT_TO_JSVAL(d); ! 282: if(!JS_SetProperty(cx, dirobj, "number", &val)) ! 283: return(NULL); ! 284: ! 285: val=INT_TO_JSVAL(lib_index); ! 286: if(!JS_SetProperty(cx, dirobj, "lib_index", &val)) ! 287: return(NULL); ! 288: ! 289: val=INT_TO_JSVAL(cfg->dir[d]->lib); ! 290: if(!JS_SetProperty(cx, dirobj, "lib_number", &val)) ! 291: return(NULL); ! 292: ! 293: if((js_str=JS_NewStringCopyZ(cx, cfg->lib[cfg->dir[d]->lib]->sname))==NULL) ! 294: return(NULL); ! 295: val=STRING_TO_JSVAL(js_str); ! 296: if(!JS_SetProperty(cx, dirobj, "lib_name", &val)) ! 297: return(NULL); ! 298: ! 299: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->code))==NULL) ! 300: return(NULL); ! 301: val=STRING_TO_JSVAL(js_str); ! 302: if(!JS_SetProperty(cx, dirobj, "code", &val)) ! 303: return(NULL); ! 304: ! 305: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->sname))==NULL) ! 306: return(NULL); ! 307: val=STRING_TO_JSVAL(js_str); ! 308: if(!JS_SetProperty(cx, dirobj, "name", &val)) ! 309: return(NULL); ! 310: ! 311: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->lname))==NULL) ! 312: return(NULL); ! 313: val=STRING_TO_JSVAL(js_str); ! 314: if(!JS_SetProperty(cx, dirobj, "description", &val)) ! 315: return(NULL); ! 316: ! 317: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->path))==NULL) ! 318: return(NULL); ! 319: val=STRING_TO_JSVAL(js_str); ! 320: if(!JS_SetProperty(cx, dirobj, "path", &val)) ! 321: return(NULL); ! 322: ! 323: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->arstr))==NULL) ! 324: return(NULL); ! 325: if(!JS_DefineProperty(cx, dirobj, "ars", STRING_TO_JSVAL(js_str) ! 326: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY)) ! 327: return(NULL); ! 328: ! 329: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->ul_arstr))==NULL) ! 330: return(NULL); ! 331: if(!JS_DefineProperty(cx, dirobj, "upload_ars", STRING_TO_JSVAL(js_str) ! 332: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY)) ! 333: return(NULL); ! 334: ! 335: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->dl_arstr))==NULL) ! 336: return(NULL); ! 337: if(!JS_DefineProperty(cx, dirobj, "download_ars", STRING_TO_JSVAL(js_str) ! 338: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY)) ! 339: return(NULL); ! 340: ! 341: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->ex_arstr))==NULL) ! 342: return(NULL); ! 343: if(!JS_DefineProperty(cx, dirobj, "exempt_ars", STRING_TO_JSVAL(js_str) ! 344: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY)) /* exception here: Oct-15-2006 */ ! 345: return(NULL); /* ChangeScope->calloc() */ ! 346: ! 347: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->op_arstr))==NULL) ! 348: return(NULL); ! 349: if(!JS_DefineProperty(cx, dirobj, "operator_ars", STRING_TO_JSVAL(js_str) ! 350: ,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY)) ! 351: return(NULL); ! 352: ! 353: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->exts))==NULL) ! 354: return(NULL); ! 355: val=STRING_TO_JSVAL(js_str); ! 356: if(!JS_SetProperty(cx, dirobj, "extensions", &val)) ! 357: return(NULL); ! 358: ! 359: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->upload_sem))==NULL) ! 360: return(NULL); ! 361: val=STRING_TO_JSVAL(js_str); ! 362: if(!JS_SetProperty(cx, dirobj, "upload_sem", &val)) ! 363: return(NULL); ! 364: ! 365: if((js_str=JS_NewStringCopyZ(cx, cfg->dir[d]->data_dir))==NULL) ! 366: return(NULL); ! 367: val=STRING_TO_JSVAL(js_str); ! 368: if(!JS_SetProperty(cx, dirobj, "data_dir", &val)) ! 369: return(NULL); ! 370: ! 371: if(!JS_NewNumberValue(cx,cfg->dir[d]->misc,&val)) ! 372: return(NULL); ! 373: if(!JS_SetProperty(cx, dirobj, "settings", &val)) ! 374: return(NULL); ! 375: ! 376: val=INT_TO_JSVAL(cfg->dir[d]->seqdev); ! 377: if(!JS_SetProperty(cx, dirobj, "seqdev", &val)) ! 378: return(NULL); ! 379: ! 380: val=INT_TO_JSVAL(cfg->dir[d]->sort); ! 381: if(!JS_SetProperty(cx, dirobj, "sort", &val)) ! 382: return(NULL); ! 383: ! 384: val=INT_TO_JSVAL(cfg->dir[d]->maxfiles); ! 385: if(!JS_SetProperty(cx, dirobj, "max_files", &val)) ! 386: return(NULL); ! 387: ! 388: val=INT_TO_JSVAL(cfg->dir[d]->maxage); ! 389: if(!JS_SetProperty(cx, dirobj, "max_age", &val)) ! 390: return(NULL); ! 391: ! 392: val=INT_TO_JSVAL(cfg->dir[d]->up_pct); ! 393: if(!JS_SetProperty(cx, dirobj, "upload_credit_pct", &val)) ! 394: return(NULL); ! 395: ! 396: val=INT_TO_JSVAL(cfg->dir[d]->dn_pct); ! 397: if(!JS_SetProperty(cx, dirobj, "download_credit_pct", &val)) ! 398: return(NULL); ! 399: ! 400: sprintf(vpath,"/%s/%s/%s" ! 401: ,cfg->lib[l]->sname ! 402: ,cfg->dir[d]->code_suffix ! 403: ,html_index_file); ! 404: if((js_str=JS_NewStringCopyZ(cx, vpath))==NULL) ! 405: return(NULL); ! 406: val=STRING_TO_JSVAL(js_str); ! 407: if(!JS_SetProperty(cx, dirobj, "link", &val)) ! 408: return(NULL); ! 409: ! 410: if(user==NULL ! 411: || (chk_ar(cfg,cfg->dir[d]->ul_ar,user) && !(user->rest&FLAG('U')))) ! 412: val=JSVAL_TRUE; ! 413: else ! 414: val=JSVAL_FALSE; ! 415: if(!JS_SetProperty(cx, dirobj, "can_upload", &val)) ! 416: return(NULL); ! 417: ! 418: if(user==NULL ! 419: || (chk_ar(cfg,cfg->dir[d]->dl_ar,user) && !(user->rest&FLAG('D')))) ! 420: val=JSVAL_TRUE; ! 421: else ! 422: val=JSVAL_FALSE; ! 423: if(!JS_SetProperty(cx, dirobj, "can_download", &val)) ! 424: return(NULL); ! 425: ! 426: if(is_download_free(cfg,d,user)) ! 427: val=JSVAL_TRUE; ! 428: else ! 429: val=JSVAL_FALSE; ! 430: if(!JS_SetProperty(cx, dirobj, "is_exempt", &val)) ! 431: return(NULL); ! 432: ! 433: if(user!=NULL ! 434: && (user->level>=SYSOP_LEVEL ! 435: || (cfg->dir[d]->op_ar[0]!=0 ! 436: && chk_ar(cfg,cfg->dir[d]->op_ar,user)))) ! 437: val=JSVAL_TRUE; ! 438: else ! 439: val=JSVAL_FALSE; ! 440: if(!JS_SetProperty(cx, dirobj, "is_operator", &val)) ! 441: return(NULL); ! 442: ! 443: val=BOOLEAN_TO_JSVAL(d==cfg->lib[l]->offline_dir); ! 444: if(!JS_SetProperty(cx, dirobj, "is_offline", &val)) ! 445: return(NULL); ! 446: ! 447: val=BOOLEAN_TO_JSVAL(d==cfg->upload_dir); ! 448: if(!JS_SetProperty(cx, dirobj, "is_upload", &val)) ! 449: return(NULL); ! 450: ! 451: val=BOOLEAN_TO_JSVAL(d==cfg->sysop_dir); ! 452: if(!JS_SetProperty(cx, dirobj, "is_sysop", &val)) ! 453: return(NULL); ! 454: ! 455: #ifdef BUILD_JSDOCS ! 456: js_CreateArrayOfStrings(cx, dirobj, "_property_desc_list", dir_prop_desc, JSPROP_READONLY); ! 457: js_DescribeSyncObject(cx,dirobj,"File Transfer Directories (current user has access to)",310); ! 458: #endif ! 459: } ! 460: ! 461: #ifdef BUILD_JSDOCS ! 462: js_CreateArrayOfStrings(cx, libobj, "_property_desc_list", lib_prop_desc, JSPROP_READONLY); ! 463: #endif ! 464: } ! 465: ! 466: #ifdef BUILD_JSDOCS ! 467: js_CreateArrayOfStrings(cx, areaobj, "_property_desc_list", file_area_prop_desc, JSPROP_READONLY); ! 468: ! 469: js_DescribeSyncObject(cx,alllibs,"Associative array of all libraries (use name as index)",312); ! 470: JS_DefineProperty(cx,alllibs,"_dont_document",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY); ! 471: ! 472: js_DescribeSyncObject(cx,alldirs,"Associative array of all directories (use internal code as index)",311); ! 473: JS_DefineProperty(cx,alldirs,"_dont_document",JSVAL_TRUE,NULL,NULL,JSPROP_READONLY); ! 474: #endif ! 475: ! 476: return(areaobj); ! 477: } ! 478: ! 479: #endif /* JAVSCRIPT */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.