js_bbs.cpp 82.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* js_bbs.cpp */

/* Synchronet JavaScript "bbs" Object */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
11
 * Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html		*
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 *																			*
 * 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"
39
#include "js_request.h"
40
41
42
43
44
45
46
47
48
49
50

#ifdef JAVASCRIPT

/*****************************/
/* BBS Object Properites */
/*****************************/
enum {
	 BBS_PROP_SYS_STATUS
	,BBS_PROP_STARTUP_OPT
	,BBS_PROP_ANSWER_TIME
	,BBS_PROP_LOGON_TIME
51
	,BBS_PROP_START_TIME
52
53
54
55
	,BBS_PROP_NS_TIME
	,BBS_PROP_LAST_NS_TIME
	,BBS_PROP_ONLINE
	,BBS_PROP_TIMELEFT
56
	,BBS_PROP_EVENT_TIME
57
	,BBS_PROP_EVENT_CODE
58
59
60

	,BBS_PROP_NODE_NUM
	,BBS_PROP_NODE_MISC
rswindell's avatar
rswindell committed
61
	,BBS_PROP_NODE_ACTION
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	,BBS_PROP_NODE_VAL_USER

	,BBS_PROP_LOGON_ULB
	,BBS_PROP_LOGON_DLB
	,BBS_PROP_LOGON_ULS
	,BBS_PROP_LOGON_DLS
	,BBS_PROP_LOGON_POSTS
	,BBS_PROP_LOGON_EMAILS
	,BBS_PROP_LOGON_FBACKS
	,BBS_PROP_POSTS_READ

	,BBS_PROP_MENU_DIR
	,BBS_PROP_MENU_FILE
	,BBS_PROP_MAIN_CMDS
rswindell's avatar
rswindell committed
76
	,BBS_PROP_FILE_CMDS
77

78
79
	,BBS_PROP_CURGRP
	,BBS_PROP_CURSUB
80
	,BBS_PROP_CURSUB_CODE
81
82
	,BBS_PROP_CURLIB
	,BBS_PROP_CURDIR
83
	,BBS_PROP_CURDIR_CODE
84

85
86
	,BBS_PROP_CONNECTION		/* READ ONLY */
	,BBS_PROP_RLOGIN_NAME
87
	,BBS_PROP_RLOGIN_PASS
88
	,BBS_PROP_CLIENT_NAME
89
90

	,BBS_PROP_ALTUL
91

92
93
	,BBS_PROP_ERRORLEVEL		/* READ ONLY */

94
95
96
97
98
99
100
101
102
103
104
	/* READ ONLY */
	,BBS_PROP_SMB_GROUP		
	,BBS_PROP_SMB_GROUP_DESC
	,BBS_PROP_SMB_GROUP_NUM
	,BBS_PROP_SMB_SUB
	,BBS_PROP_SMB_SUB_DESC
	,BBS_PROP_SMB_SUB_CODE
	,BBS_PROP_SMB_SUB_NUM
	,BBS_PROP_SMB_ATTR
	,BBS_PROP_SMB_LAST_MSG
	,BBS_PROP_SMB_TOTAL_MSGS
105
106
	,BBS_PROP_SMB_MSGS
	,BBS_PROP_SMB_CURMSG
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

	/* READ ONLY */
	,BBS_PROP_MSG_TO
	,BBS_PROP_MSG_TO_EXT
	,BBS_PROP_MSG_TO_NET
	,BBS_PROP_MSG_TO_AGENT
	,BBS_PROP_MSG_FROM
	,BBS_PROP_MSG_FROM_EXT
	,BBS_PROP_MSG_FROM_NET
	,BBS_PROP_MSG_FROM_AGENT
	,BBS_PROP_MSG_REPLYTO
	,BBS_PROP_MSG_REPLYTO_EXT
	,BBS_PROP_MSG_REPLYTO_NET
	,BBS_PROP_MSG_REPLYTO_AGENT
	,BBS_PROP_MSG_SUBJECT
	,BBS_PROP_MSG_DATE
	,BBS_PROP_MSG_TIMEZONE
	,BBS_PROP_MSG_DATE_IMPORTED
	,BBS_PROP_MSG_ATTR
	,BBS_PROP_MSG_AUXATTR
	,BBS_PROP_MSG_NETATTR
	,BBS_PROP_MSG_OFFSET
	,BBS_PROP_MSG_NUMBER
	,BBS_PROP_MSG_EXPIRATION
	,BBS_PROP_MSG_FORWARDED
132
	,BBS_PROP_MSG_THREAD_BACK
133
134
	,BBS_PROP_MSG_THREAD_NEXT
	,BBS_PROP_MSG_THREAD_FIRST
135
136
	,BBS_PROP_MSG_ID
	,BBS_PROP_MSG_REPLY_ID
137
	,BBS_PROP_MSG_DELIVERY_ATTEMPTS
138

139
140
141
142
	/* READ ONLY */
	,BBS_PROP_BATCH_UPLOAD_TOTAL
	,BBS_PROP_BATCH_DNLOAD_TOTAL

143
	,BBS_PROP_COMMAND_STR
144
145
};

146
#ifdef BUILD_JSDOCS
147
	static char* bbs_prop_desc[] = {
148
149
	 "system status bitfield (see <tt>SS_*</tt> in <tt>sbbsdefs.js</tt> for bit definitions)"
	,"startup options bitfield (see <tt>BBS_OPT_*</tt> in <tt>sbbsdefs.js</tt> for bit definitions)"
150
151
152
153
154
	,"answer time, in <i>time_t</i> format"
	,"logon time, in <i>time_t</i> format"
	,"time from which user's time left is calculated, in <i>time_t</i> format"
	,"current file new-scan time, in <i>time_t</i> format"
	,"previous file new-scan time, in <i>time_t</i> format"
155
	,"online (see <tt>ON_*</tt> in <tt>sbbsdefs.js</tt> for valid values)"
156
	,"time left (in seconds)"
157
	,"time of next exclusive event (in <i>time_t</i> format), or 0 if none"
158
	,"internal code of next exclusive event"
159

160
	,"current node number"
161
162
	,"current node settings bitfield (see <tt>NM_*</tt> in <tt>sbbsdefs.js</tt> for bit definitions)"
	,"current node action (see <tt>nodedefs.js</tt> for valid values)"
163
	,"validation feedback user for this node (or 0 for no validation feedback required)"
164

165
166
167
168
169
170
171
172
	,"bytes uploaded during this session"
	,"bytes downloaded during this session"
	,"files uploaded during this session"
	,"files downloaded during this session"
	,"messages posted during this session"
	,"e-mails sent during this session"
	,"feedback messages sent during this session"
	,"messages read during this session"
173
174
175

	,"menu subdirectory (overrides default)"
	,"menu file (overrides default)"
176
177
	,"total main menu commands received from user during this session"
	,"total file menu commands received from user during this session"
178
179
180

	,"current message group"
	,"current message sub-board"
181
	,"current message sub-board internal code"
182
183
	,"current file library"
	,"current file directory"
184
	,"current file directory internal code"
185
186

	,"remote connection type"
187
188
	,"login name given during RLogin negotiation"
	,"password specified during RLogin negotiation"
189
190
191
	,"client name"

	,"current alternate upload path number"
192

193
194
	,"error level returned from last executed external program"

195
	/* READ ONLY */
196
197
198
199
200
201
202
203
204
205
206
207
	,"message group name of message being read"
	,"message group description of message being read"
	,"message group number of message being read"
	,"sub-board name of message being read"
	,"sub-board description of message being read"
	,"sub-board internal code of message being read"
	,"sub-board number of message being read"
	,"message base attributes"
	,"highest message number in message base"
	,"total number of messages in message base"
	,"number of messages loaded from message base"
	,"current message number in message base"
208
209

	/* READ ONLY */
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
	,"message recipient name"
	,"message recipient extension"
	,"message recipient network type"
	,"message recipient agent type"
	,"message sender name"
	,"message sender extension"
	,"message sender network type"
	,"message sender agent type"
	,"message reply-to name"
	,"message reply-to extension"
	,"message reply-to network type"
	,"message reply-to agent type"
	,"message subject"
	,"message date/time"
	,"message time zone"
	,"message date/time imported"
	,"message attributes"
	,"message auxillary attributes"
	,"message network attributes"
	,"message header offset"
	,"message number"
	,"message expiration"
	,"message forwarded"
233
	,"message thread, back message number (AKA msg_thread_orig)"
234
235
236
237
238
239
	,"message thread, next message number"
	,"message thread, first reply to this message"
	,"message identifier"
	,"message replied-to identifier"
	,"message delivery attempt counter"

240
241
242
	,"number of files in batch upload queue"
	,"number of files in batch download queue"

243
	,"current command shell/module <i>command string</i> value"
244
	,NULL
245
246
247
	};
#endif

248
249
static JSBool js_bbs_get(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
250
251
	const char*	p=NULL;
	const char*	nulstr="";
252
	ulong		val=0;
253
254
    jsint       tiny;
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
255
	jsrefcount	rc;
256
257
258
259
260
261
262

	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
		return(JS_FALSE);

    tiny = JSVAL_TO_INT(id);

	switch(tiny) {
263
264
265
266
267
268
269
270
271
272
273
274
		case BBS_PROP_SYS_STATUS:
			val=sbbs->sys_status;
			break;
		case BBS_PROP_STARTUP_OPT:
			val=sbbs->startup->options;
			break;
		case BBS_PROP_ANSWER_TIME:
			val=sbbs->answertime;
			break;
		case BBS_PROP_LOGON_TIME:
			val=sbbs->logontime;
			break;
275
276
277
		case BBS_PROP_START_TIME:
			val=sbbs->starttime;
			break;
278
279
280
281
282
283
		case BBS_PROP_NS_TIME:
			val=sbbs->ns_time;
			break;
		case BBS_PROP_LAST_NS_TIME:
			val=sbbs->last_ns_time;
			break;
284
285
286
		case BBS_PROP_ONLINE:
			val=sbbs->online;
			break;
287
		case BBS_PROP_TIMELEFT:
288
			rc=JS_SUSPENDREQUEST(cx);
289
			val=sbbs->gettimeleft(false);
290
			JS_RESUMEREQUEST(cx, rc);
291
			break;
292
293
294
		case BBS_PROP_EVENT_TIME:
			val=sbbs->event_time;
			break;
295
296
297
		case BBS_PROP_EVENT_CODE:
			p=sbbs->event_code;
			break;
298
299
300

		case BBS_PROP_NODE_NUM:
			val=sbbs->cfg.node_num;
301
			break;
302
303
		case BBS_PROP_NODE_MISC:
			val=sbbs->cfg.node_misc;
304
			break;
rswindell's avatar
rswindell committed
305
306
307
		case BBS_PROP_NODE_ACTION:
			val=sbbs->action;
			break;
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
		case BBS_PROP_NODE_VAL_USER:
			val=sbbs->cfg.node_valuser;
			break;

		case BBS_PROP_LOGON_ULB:
			val=sbbs->logon_ulb;
			break;
		case BBS_PROP_LOGON_DLB:
			val=sbbs->logon_dlb;
			break;
		case BBS_PROP_LOGON_ULS:
			val=sbbs->logon_uls;
			break;
		case BBS_PROP_LOGON_DLS:
			val=sbbs->logon_dls;
			break;
		case BBS_PROP_LOGON_POSTS:
			val=sbbs->logon_posts;
			break;
		case BBS_PROP_LOGON_EMAILS:
			val=sbbs->logon_emails;
			break;
		case BBS_PROP_LOGON_FBACKS:
			val=sbbs->logon_fbacks;
			break;
		case BBS_PROP_POSTS_READ:
			val=sbbs->posts_read;
			break;

		case BBS_PROP_MENU_DIR:
			p=sbbs->menu_dir;
339
			break;
340
341
		case BBS_PROP_MENU_FILE:
			p=sbbs->menu_file;
342
			break;
343
344
		case BBS_PROP_MAIN_CMDS:
			val=sbbs->main_cmds;
345
			break;
rswindell's avatar
rswindell committed
346
		case BBS_PROP_FILE_CMDS:
347
			val=sbbs->xfer_cmds;
348
			break;
349
350
351
352
353
354
355
356

		case BBS_PROP_CURGRP:
			val=sbbs->curgrp;
			break;
		case BBS_PROP_CURSUB:
			if(sbbs->curgrp<sbbs->usrgrps)
				val=sbbs->cursub[sbbs->curgrp];
			break;
357
358
359
360
361
		case BBS_PROP_CURSUB_CODE:
			if(sbbs->cursubnum<sbbs->cfg.total_subs)
				p=sbbs->cfg.sub[sbbs->cursubnum]->code;
			break;

362
363
364
365
366
367
368
		case BBS_PROP_CURLIB:
			val=sbbs->curlib;
			break;
		case BBS_PROP_CURDIR:
			if(sbbs->curlib<sbbs->usrlibs)
				val=sbbs->curdir[sbbs->curlib];
			break;
369
370
371
372
		case BBS_PROP_CURDIR_CODE:
			if(sbbs->curdirnum<sbbs->cfg.total_dirs)
				p=sbbs->cfg.dir[sbbs->curdirnum]->code;
			break;
373

374
375
		case BBS_PROP_CONNECTION:
			p=sbbs->connection;
376
			break;
377
378
379
		case BBS_PROP_RLOGIN_NAME:
			p=sbbs->rlogin_name;
			break;
380
381
382
		case BBS_PROP_RLOGIN_PASS:
			p=sbbs->rlogin_pass;
			break;
383
384
385
386
		case BBS_PROP_CLIENT_NAME:
			p=sbbs->client_name;
			break;

387
388
389
390
		case BBS_PROP_ALTUL:
			val=sbbs->altul;
			break;

391
392
393
394
		case BBS_PROP_ERRORLEVEL:
			val=sbbs->errorlevel;
			break;

395
396
		/* Currently Open Message Base (sbbs.smb) */
		case BBS_PROP_SMB_GROUP:
397
			if(sbbs->smb.subnum==INVALID_SUB || sbbs->smb.subnum>=sbbs->cfg.total_subs)
398
399
400
401
402
				p=nulstr;
			else
				p=sbbs->cfg.grp[sbbs->cfg.sub[sbbs->smb.subnum]->grp]->sname;
			break;
		case BBS_PROP_SMB_GROUP_DESC:
403
			if(sbbs->smb.subnum==INVALID_SUB || sbbs->smb.subnum>=sbbs->cfg.total_subs)
404
405
406
407
408
409
410
411
412
413
414
415
416
417
				p=nulstr;
			else
				p=sbbs->cfg.grp[sbbs->cfg.sub[sbbs->smb.subnum]->grp]->lname;
			break;
		case BBS_PROP_SMB_GROUP_NUM:
			if(sbbs->smb.subnum!=INVALID_SUB && sbbs->smb.subnum<sbbs->cfg.total_subs) {
				uint ugrp;
				for(ugrp=0;ugrp<sbbs->usrgrps;ugrp++)
					if(sbbs->usrgrp[ugrp]==sbbs->cfg.sub[sbbs->smb.subnum]->grp)
						break;
				val=ugrp+1;
			}
			break;
		case BBS_PROP_SMB_SUB:
418
			if(sbbs->smb.subnum==INVALID_SUB || sbbs->smb.subnum>=sbbs->cfg.total_subs)
419
420
421
422
423
				p=nulstr;
			else
				p=sbbs->cfg.sub[sbbs->smb.subnum]->sname;
			break;
		case BBS_PROP_SMB_SUB_DESC:
424
			if(sbbs->smb.subnum==INVALID_SUB || sbbs->smb.subnum>=sbbs->cfg.total_subs)
425
426
427
428
429
				p=nulstr;
			else
				p=sbbs->cfg.sub[sbbs->smb.subnum]->lname;
			break;
		case BBS_PROP_SMB_SUB_CODE:
430
			if(sbbs->smb.subnum==INVALID_SUB || sbbs->smb.subnum>=sbbs->cfg.total_subs)
431
432
433
434
435
436
437
438
439
440
441
442
443
444
				p=nulstr;
			else
				p=sbbs->cfg.sub[sbbs->smb.subnum]->code;
			break;
		case BBS_PROP_SMB_SUB_NUM:
			if(sbbs->smb.subnum!=INVALID_SUB && sbbs->smb.subnum<sbbs->cfg.total_subs) {
				uint ugrp;
				for(ugrp=0;ugrp<sbbs->usrgrps;ugrp++)
					if(sbbs->usrgrp[ugrp]==sbbs->cfg.sub[sbbs->smb.subnum]->grp)
						break;
				uint usub;
				for(usub=0;usub<sbbs->usrsubs[ugrp];usub++)
					if(sbbs->usrsub[ugrp][usub]==sbbs->smb.subnum)
						break;
445
				val=usub+1;
446
447
448
449
450
451
452
453
454
455
456
			}
			break;
		case BBS_PROP_SMB_ATTR:
			val=sbbs->smb.status.attr;
			break;
		case BBS_PROP_SMB_LAST_MSG:
			val=sbbs->smb.status.last_msg;
			break;
		case BBS_PROP_SMB_TOTAL_MSGS:
			val=sbbs->smb.status.total_msgs;
			break;
457
458
459
460
461
462
		case BBS_PROP_SMB_MSGS:
			val=sbbs->smb.msgs;
			break;
		case BBS_PROP_SMB_CURMSG:
			val=sbbs->smb.curmsg;
			break;
463
464
465

		/* Currently Displayed Message Header (sbbs.current_msg) */
		case BBS_PROP_MSG_TO:
466
			if(sbbs->current_msg==NULL || sbbs->current_msg->to==NULL)
467
468
469
470
471
				p=nulstr;
			else
				p=sbbs->current_msg->to;
			break;
		case BBS_PROP_MSG_TO_EXT:
472
			if(sbbs->current_msg==NULL || sbbs->current_msg->to_ext==NULL)
473
474
475
476
477
				p=nulstr;
			else
				p=sbbs->current_msg->to_ext;
			break;
		case BBS_PROP_MSG_TO_NET:
478
			if(sbbs->current_msg==NULL || sbbs->current_msg->to_net.type==NET_NONE)
479
480
				p=nulstr;
			else
481
				p=smb_netaddr(&sbbs->current_msg->to_net);
482
483
484
485
486
487
			break;
		case BBS_PROP_MSG_TO_AGENT:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->to_agent;
			break;
		case BBS_PROP_MSG_FROM:
488
			if(sbbs->current_msg==NULL || sbbs->current_msg->from==NULL)
489
490
491
492
493
				p=nulstr;
			else
				p=sbbs->current_msg->from;
			break;
		case BBS_PROP_MSG_FROM_EXT:
494
			if(sbbs->current_msg==NULL || sbbs->current_msg->from_ext==NULL)
495
496
497
498
499
				p=nulstr;
			else
				p=sbbs->current_msg->from_ext;
			break;
		case BBS_PROP_MSG_FROM_NET:
500
			if(sbbs->current_msg==NULL || sbbs->current_msg->from_net.type==NET_NONE)
501
502
				p=nulstr;
			else
503
				p=smb_netaddr(&sbbs->current_msg->from_net);
504
505
506
507
508
509
			break;
		case BBS_PROP_MSG_FROM_AGENT:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->from_agent;
			break;
		case BBS_PROP_MSG_REPLYTO:
510
			if(sbbs->current_msg==NULL || sbbs->current_msg->replyto==NULL)
511
512
513
514
515
				p=nulstr;
			else
				p=sbbs->current_msg->replyto;
			break;
		case BBS_PROP_MSG_REPLYTO_EXT:
516
			if(sbbs->current_msg==NULL || sbbs->current_msg->replyto_ext==NULL)
517
518
519
520
521
				p=nulstr;
			else
				p=sbbs->current_msg->replyto_ext;
			break;
		case BBS_PROP_MSG_REPLYTO_NET:
522
			if(sbbs->current_msg==NULL || sbbs->current_msg->replyto_net.type==NET_NONE)
523
524
				p=nulstr;
			else
525
				p=smb_netaddr(&sbbs->current_msg->replyto_net);
526
527
528
529
530
531
532
			break;
		case BBS_PROP_MSG_REPLYTO_AGENT:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->replyto_agent;
			break;

		case BBS_PROP_MSG_SUBJECT:
533
			if(sbbs->current_msg==NULL || sbbs->current_msg->subj==NULL)
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
				p=nulstr;
			else
				p=sbbs->current_msg->subj;
			break;
		case BBS_PROP_MSG_DATE:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.when_written.time;
			break;
		case BBS_PROP_MSG_TIMEZONE:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.when_written.zone;
			break;
		case BBS_PROP_MSG_DATE_IMPORTED:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.when_imported.time;
			break;
		case BBS_PROP_MSG_ATTR:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.attr;
			break;
		case BBS_PROP_MSG_AUXATTR:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.auxattr;
			break;
		case BBS_PROP_MSG_NETATTR:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.netattr;
			break;
		case BBS_PROP_MSG_OFFSET:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->offset;
			break;
		case BBS_PROP_MSG_NUMBER:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.number;
			break;
		case BBS_PROP_MSG_EXPIRATION:
			if(sbbs->current_msg!=NULL)
572
				val=sbbs->current_msg->expiration;
573
574
575
576
577
			break;
		case BBS_PROP_MSG_FORWARDED:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->forwarded;
			break;
578
		case BBS_PROP_MSG_THREAD_BACK:
579
			if(sbbs->current_msg!=NULL)
580
				val=sbbs->current_msg->hdr.thread_back;
581
582
583
584
585
586
587
588
589
590
591
592
593
			break;
		case BBS_PROP_MSG_THREAD_NEXT:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.thread_next;
			break;
		case BBS_PROP_MSG_THREAD_FIRST:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.thread_first;
			break;
		case BBS_PROP_MSG_DELIVERY_ATTEMPTS:
			if(sbbs->current_msg!=NULL)
				val=sbbs->current_msg->hdr.delivery_attempts;
			break;
594
595
596
597
598
599
600
601
602
603
604
605
		case BBS_PROP_MSG_ID:
			if(sbbs->current_msg==NULL || sbbs->current_msg->id==NULL)
				p=nulstr;
			else
				p=sbbs->current_msg->id;
			break;
		case BBS_PROP_MSG_REPLY_ID:
			if(sbbs->current_msg==NULL || sbbs->current_msg->reply_id==NULL)
				p=nulstr;
			else
				p=sbbs->current_msg->reply_id;
			break;
606

607
608
609
610
611
		case BBS_PROP_BATCH_UPLOAD_TOTAL:
			val=sbbs->batup_total;
			break;
		case BBS_PROP_BATCH_DNLOAD_TOTAL:
			val=sbbs->batdn_total;
612
			break;
613

614
615
616
617
		case BBS_PROP_COMMAND_STR:
			p=sbbs->main_csi.str;
			break;

618
619
620
		default:
			return(JS_TRUE);
	}
621
622
623
624
625
626
	if(p!=NULL) {
		JSString* js_str=JS_NewStringCopyZ(cx, p);
		if(js_str==NULL)
			return(JS_FALSE);
		*vp = STRING_TO_JSVAL(js_str);
	} else
627
		JS_NewNumberValue(cx,val,vp);
628
629
630
631
632
633

	return(JS_TRUE);
}

static JSBool js_bbs_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
rswindell's avatar
rswindell committed
634
	char*		p=NULL;
635
	int32		val=0;
636
    jsint       tiny;
rswindell's avatar
rswindell committed
637
	JSString*	js_str;
638
639
640
641
642
643
644
	sbbs_t*		sbbs;

	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
		return(JS_FALSE);

    tiny = JSVAL_TO_INT(id);

645
	if(JSVAL_IS_NUM(*vp) || JSVAL_IS_BOOLEAN(*vp))
646
		JS_ValueToInt32(cx, *vp, &val);
rswindell's avatar
rswindell committed
647
648
649
650
651
	else if(JSVAL_IS_STRING(*vp)) {
		if((js_str = JS_ValueToString(cx, *vp))==NULL)
			return(JS_FALSE);
		p=JS_GetStringBytes(js_str);
	}
652
653

	switch(tiny) {
654
655
656
657
658
659
660
661
662
663
664
665
		case BBS_PROP_SYS_STATUS:
			sbbs->sys_status=val;
			break;
		case BBS_PROP_STARTUP_OPT:
			sbbs->startup->options=val;
			break;
		case BBS_PROP_ANSWER_TIME:
			sbbs->answertime=val;
			break;
		case BBS_PROP_LOGON_TIME:
			sbbs->logontime=val;
			break;
666
667
668
		case BBS_PROP_START_TIME:
			sbbs->starttime=val;
			break;
669
670
671
672
673
674
		case BBS_PROP_NS_TIME:
			sbbs->ns_time=val;
			break;
		case BBS_PROP_LAST_NS_TIME:
			sbbs->last_ns_time=val;
			break;
675
676
677
		case BBS_PROP_ONLINE:
			sbbs->online=val;
			break;
678
679
680
		case BBS_PROP_NODE_MISC:
			sbbs->cfg.node_misc=val;
			break;
rswindell's avatar
rswindell committed
681
682
683
		case BBS_PROP_NODE_ACTION:
			sbbs->action=(uchar)val;
			break;
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
		case BBS_PROP_NODE_VAL_USER:
			sbbs->cfg.node_valuser=(ushort)val;
			break;
		case BBS_PROP_LOGON_ULB:
			sbbs->logon_ulb=val;
			break;
		case BBS_PROP_LOGON_DLB:
			sbbs->logon_dlb=val;
			break;
		case BBS_PROP_LOGON_ULS:
			sbbs->logon_uls=val;
			break;
		case BBS_PROP_LOGON_DLS:
			sbbs->logon_dls=val;
			break;
		case BBS_PROP_LOGON_POSTS:
			sbbs->logon_posts=val;
			break;
		case BBS_PROP_LOGON_EMAILS:
			sbbs->logon_emails=val;
704
			break;
705
706
		case BBS_PROP_LOGON_FBACKS:
			sbbs->logon_fbacks=val;
707
			break;
708
709
		case BBS_PROP_POSTS_READ:
			sbbs->posts_read=val;
710
			break;
711
		case BBS_PROP_MENU_DIR:
712
			SAFECOPY(sbbs->menu_dir,p);
713
			break;
714
		case BBS_PROP_MENU_FILE:
715
			SAFECOPY(sbbs->menu_file,p);
716
			break;
717
718
		case BBS_PROP_MAIN_CMDS:
			sbbs->main_cmds=val;
719
			break;
rswindell's avatar
rswindell committed
720
		case BBS_PROP_FILE_CMDS:
721
722
			sbbs->xfer_cmds=val;
			break;
723
724

		case BBS_PROP_CURGRP:
725
726
727
728
729
730
731
732
733
			if(p!=NULL) {	/* set by name */
				uint i;
				for(i=0;i<sbbs->usrgrps;i++)
					if(!stricmp(sbbs->cfg.grp[sbbs->usrgrp[i]]->sname,p))
						break;
				if(i<sbbs->usrgrps)
					sbbs->curgrp=i;
				break;
			}
734
735
736
737
			if((uint)val<sbbs->cfg.total_grps && (uint)val<sbbs->usrgrps)
				sbbs->curgrp=val;
			break;
		case BBS_PROP_CURSUB:
738
		case BBS_PROP_CURSUB_CODE:
739
740
741
742
743
744
745
746
747
748
			if(p!=NULL) {	/* set by code */
				for(uint i=0;i<sbbs->usrgrps;i++)
					for(uint j=0;j<sbbs->usrsubs[i];j++)
						if(!stricmp(sbbs->cfg.sub[sbbs->usrsub[i][j]]->code,p)) {
							sbbs->curgrp=i;
							sbbs->cursub[i]=j;
							break; 
						}
				break;
			}
749
750
751
752
			if(sbbs->curgrp<sbbs->cfg.total_grps && (uint)val<sbbs->usrsubs[sbbs->curgrp])
				sbbs->cursub[sbbs->curgrp]=val;
			break;
		case BBS_PROP_CURLIB:
753
754
755
756
757
758
759
760
761
			if(p!=NULL) {	/* set by name */
				uint i;
				for(i=0;i<sbbs->usrlibs;i++)
					if(!stricmp(sbbs->cfg.lib[sbbs->usrlib[i]]->sname,p))
						break;
				if(i<sbbs->usrlibs)
					sbbs->curlib=i;
				break;
			}
762
763
764
765
			if((uint)val<sbbs->cfg.total_libs && (uint)val<sbbs->usrlibs)
				sbbs->curlib=val;
			break;
		case BBS_PROP_CURDIR:
766
		case BBS_PROP_CURDIR_CODE:
767
768
769
770
771
772
773
774
775
776
			if(p!=NULL) {	/* set by code */
				for(uint i=0;i<sbbs->usrlibs;i++)
					for(uint j=0;j<sbbs->usrdirs[i];j++)
						if(!stricmp(sbbs->cfg.dir[sbbs->usrdir[i][j]]->code,p)) {
							sbbs->curlib=i;
							sbbs->curdir[i]=j;
							break; 
						}
				break;
			}
777
778
779
780
			if(sbbs->curlib<sbbs->cfg.total_libs && (uint)val<sbbs->usrdirs[sbbs->curlib])
				sbbs->curdir[sbbs->curlib]=val;
			break;

781
		case BBS_PROP_RLOGIN_NAME:
782
			SAFECOPY(sbbs->rlogin_name,p);
783
			break;
784
785
786
		case BBS_PROP_RLOGIN_PASS:
			SAFECOPY(sbbs->rlogin_pass,p);
			break;
787
		case BBS_PROP_CLIENT_NAME:
788
			SAFECOPY(sbbs->client_name,p);
789
			break;
790
791
792
793
794

		case BBS_PROP_ALTUL:
			if(val<sbbs->cfg.altpaths)
				sbbs->altul=(ushort)val;
			break;
795
796
797
798
799

		case BBS_PROP_COMMAND_STR:
			sprintf(sbbs->main_csi.str, "%.*s", 1024, p);
			break;

800
801
802
803
		default:
			return(JS_TRUE);
	}

804
805
806
807
808
809
810
811
812
	if(sbbs->usrgrps)
		sbbs->cursubnum=sbbs->usrsub[sbbs->curgrp][sbbs->cursub[sbbs->curgrp]];		/* Used for ARS */
	else
		sbbs->cursubnum=INVALID_SUB;
	if(sbbs->usrlibs) 
		sbbs->curdirnum=sbbs->usrdir[sbbs->curlib][sbbs->curdir[sbbs->curlib]];		/* Used for ARS */
	else 
		sbbs->curdirnum=INVALID_DIR;

813
814
815
	return(JS_TRUE);
}

816
#define PROP_READONLY JSPROP_ENUMERATE|JSPROP_READONLY
817

818
819
820
821
822
823
824
static jsSyncPropertySpec js_bbs_properties[] = {
/*		 name				,tinyid					,flags				,ver	*/

	{	"sys_status"		,BBS_PROP_SYS_STATUS	,JSPROP_ENUMERATE	,310},
	{	"startup_options"	,BBS_PROP_STARTUP_OPT	,JSPROP_ENUMERATE	,310},
	{	"answer_time"		,BBS_PROP_ANSWER_TIME	,JSPROP_ENUMERATE	,310},
	{	"logon_time"		,BBS_PROP_LOGON_TIME	,JSPROP_ENUMERATE	,310},
825
	{	"start_time"		,BBS_PROP_START_TIME	,JSPROP_ENUMERATE	,314},
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
	{	"new_file_time"		,BBS_PROP_NS_TIME		,JSPROP_ENUMERATE	,310},
	{	"last_new_file_time",BBS_PROP_LAST_NS_TIME	,JSPROP_ENUMERATE	,310},
	{	"online"			,BBS_PROP_ONLINE		,JSPROP_ENUMERATE	,310},
	{	"timeleft"			,BBS_PROP_TIMELEFT		,JSPROP_READONLY	,310},	/* alias */
	{	"time_left"			,BBS_PROP_TIMELEFT		,PROP_READONLY		,311},
	{	"event_time"		,BBS_PROP_EVENT_TIME	,PROP_READONLY		,311},
	{	"event_code"		,BBS_PROP_EVENT_CODE	,PROP_READONLY		,311},
	{	"node_num"			,BBS_PROP_NODE_NUM		,PROP_READONLY		,310},
	{	"node_settings"		,BBS_PROP_NODE_MISC		,JSPROP_ENUMERATE	,310},
	{	"node_action"		,BBS_PROP_NODE_ACTION	,JSPROP_ENUMERATE	,310},
	{	"node_val_user"		,BBS_PROP_NODE_VAL_USER	,JSPROP_ENUMERATE	,310},
	{	"logon_ulb"			,BBS_PROP_LOGON_ULB		,JSPROP_ENUMERATE	,310},
	{	"logon_dlb"			,BBS_PROP_LOGON_DLB		,JSPROP_ENUMERATE	,310},
	{	"logon_uls"			,BBS_PROP_LOGON_ULS		,JSPROP_ENUMERATE	,310},
	{	"logon_dls"			,BBS_PROP_LOGON_DLS		,JSPROP_ENUMERATE	,310},
	{	"logon_posts"		,BBS_PROP_LOGON_POSTS	,JSPROP_ENUMERATE	,310},
	{	"logon_emails"		,BBS_PROP_LOGON_EMAILS	,JSPROP_ENUMERATE	,310},
	{	"logon_fbacks"		,BBS_PROP_LOGON_FBACKS	,JSPROP_ENUMERATE	,310},
	{	"posts_read"		,BBS_PROP_POSTS_READ	,JSPROP_ENUMERATE	,310},
	{	"menu_dir"			,BBS_PROP_MENU_DIR		,JSPROP_ENUMERATE	,310},
	{	"menu_file"			,BBS_PROP_MENU_FILE		,JSPROP_ENUMERATE	,310},
	{	"main_cmds"			,BBS_PROP_MAIN_CMDS		,JSPROP_ENUMERATE	,310},
	{	"file_cmds"			,BBS_PROP_FILE_CMDS		,JSPROP_ENUMERATE	,310},
	{	"curgrp"			,BBS_PROP_CURGRP		,JSPROP_ENUMERATE	,310},
	{	"cursub"			,BBS_PROP_CURSUB		,JSPROP_ENUMERATE	,310},
851
	{	"cursub_code"		,BBS_PROP_CURSUB_CODE	,JSPROP_ENUMERATE	,314},
852
853
	{	"curlib"			,BBS_PROP_CURLIB		,JSPROP_ENUMERATE	,310},
	{	"curdir"			,BBS_PROP_CURDIR		,JSPROP_ENUMERATE	,310},
854
	{	"curdir_code"		,BBS_PROP_CURDIR_CODE	,JSPROP_ENUMERATE	,314},
855
856
	{	"connection"		,BBS_PROP_CONNECTION	,PROP_READONLY		,310},
	{	"rlogin_name"		,BBS_PROP_RLOGIN_NAME	,JSPROP_ENUMERATE	,310},
857
	{	"rlogin_password"	,BBS_PROP_RLOGIN_PASS	,JSPROP_ENUMERATE	,315},
858
859
	{	"client_name"		,BBS_PROP_CLIENT_NAME	,JSPROP_ENUMERATE	,310},
	{	"alt_ul_dir"		,BBS_PROP_ALTUL			,JSPROP_ENUMERATE	,310},
860
	{	"errorlevel"		,BBS_PROP_ERRORLEVEL	,PROP_READONLY		,312},
861
862
863
864
865
866
867
868
869
870
871
872
873

	{	"smb_group"			,BBS_PROP_SMB_GROUP			,PROP_READONLY	,310},
	{	"smb_group_desc"	,BBS_PROP_SMB_GROUP_DESC	,PROP_READONLY	,310},
	{	"smb_group_number"	,BBS_PROP_SMB_GROUP_NUM		,PROP_READONLY	,310},
	{	"smb_sub"			,BBS_PROP_SMB_SUB			,PROP_READONLY	,310},
	{	"smb_sub_desc"		,BBS_PROP_SMB_SUB_DESC		,PROP_READONLY	,310},
	{	"smb_sub_code"		,BBS_PROP_SMB_SUB_CODE		,PROP_READONLY	,310},
	{	"smb_sub_number"	,BBS_PROP_SMB_SUB_NUM		,PROP_READONLY	,310},
	{	"smb_attr"			,BBS_PROP_SMB_ATTR			,PROP_READONLY	,310},
	{	"smb_last_msg"		,BBS_PROP_SMB_LAST_MSG		,PROP_READONLY	,310},
	{	"smb_total_msgs"	,BBS_PROP_SMB_TOTAL_MSGS	,PROP_READONLY	,310},
	{	"smb_msgs"			,BBS_PROP_SMB_MSGS			,PROP_READONLY	,310},
	{	"smb_curmsg"		,BBS_PROP_SMB_CURMSG		,PROP_READONLY	,310},
874
																		
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
	{	"msg_to"			,BBS_PROP_MSG_TO			,PROP_READONLY	,310},
	{	"msg_to_ext"		,BBS_PROP_MSG_TO_EXT		,PROP_READONLY	,310},
	{	"msg_to_net"		,BBS_PROP_MSG_TO_NET		,PROP_READONLY	,310},
	{	"msg_to_agent"		,BBS_PROP_MSG_TO_AGENT		,PROP_READONLY	,310},
	{	"msg_from"			,BBS_PROP_MSG_FROM			,PROP_READONLY	,310},
	{	"msg_from_ext"		,BBS_PROP_MSG_FROM_EXT		,PROP_READONLY	,310},
	{	"msg_from_net"		,BBS_PROP_MSG_FROM_NET		,PROP_READONLY	,310},
	{	"msg_from_agent"	,BBS_PROP_MSG_FROM_AGENT	,PROP_READONLY	,310},
	{	"msg_replyto"		,BBS_PROP_MSG_REPLYTO		,PROP_READONLY	,310},
	{	"msg_replyto_ext"	,BBS_PROP_MSG_REPLYTO_EXT	,PROP_READONLY	,310},
	{	"msg_replyto_net"	,BBS_PROP_MSG_REPLYTO_NET	,PROP_READONLY	,310},
	{	"msg_replyto_agent"	,BBS_PROP_MSG_REPLYTO_AGENT	,PROP_READONLY	,310},
	{	"msg_subject"		,BBS_PROP_MSG_SUBJECT		,PROP_READONLY	,310},
	{	"msg_date"			,BBS_PROP_MSG_DATE			,PROP_READONLY	,310},
	{	"msg_timezone"		,BBS_PROP_MSG_TIMEZONE		,PROP_READONLY	,310},
	{	"msg_date_imported"	,BBS_PROP_MSG_DATE_IMPORTED	,PROP_READONLY	,310},
	{	"msg_attr"			,BBS_PROP_MSG_ATTR			,PROP_READONLY	,310},
	{	"msg_auxattr"		,BBS_PROP_MSG_AUXATTR		,PROP_READONLY	,310},
	{	"msg_netattr"		,BBS_PROP_MSG_NETATTR		,PROP_READONLY	,310},
	{	"msg_offset"		,BBS_PROP_MSG_OFFSET		,PROP_READONLY	,310},
	{	"msg_number"		,BBS_PROP_MSG_NUMBER		,PROP_READONLY	,310},
	{	"msg_expiration"	,BBS_PROP_MSG_EXPIRATION	,PROP_READONLY	,310},
	{	"msg_forwarded"		,BBS_PROP_MSG_FORWARDED		,PROP_READONLY	,310},
898
	{	"msg_thread_back"	,BBS_PROP_MSG_THREAD_BACK	,PROP_READONLY	,312},
899
	{	"msg_thread_orig"	,BBS_PROP_MSG_THREAD_BACK	,JSPROP_READONLY,310},	/* alias */
900
901
902
903
	{	"msg_thread_next"	,BBS_PROP_MSG_THREAD_NEXT	,PROP_READONLY	,310},
	{	"msg_thread_first"	,BBS_PROP_MSG_THREAD_FIRST	,PROP_READONLY	,310},
	{	"msg_id"			,BBS_PROP_MSG_ID			,PROP_READONLY	,310},
	{	"msg_reply_id"		,BBS_PROP_MSG_REPLY_ID		,PROP_READONLY	,310},
904
	{	"msg_delivery_attempts"	,BBS_PROP_MSG_DELIVERY_ATTEMPTS
905
														,PROP_READONLY	,310},
906

907
908
	{	"batch_upload_total",BBS_PROP_BATCH_UPLOAD_TOTAL,PROP_READONLY	,310},
	{	"batch_dnload_total",BBS_PROP_BATCH_DNLOAD_TOTAL,PROP_READONLY	,310},
909

rswindell's avatar
rswindell committed
910
	{	"command_str"		,BBS_PROP_COMMAND_STR		,JSPROP_ENUMERATE, 314},
911
912
913
	{0}
};

914
915
916
917
918
919
920
921
922
923
/* Utility functions */
static uint get_subnum(JSContext* cx, sbbs_t* sbbs, jsval val)
{
	uint subnum=INVALID_SUB;

	if(JSVAL_IS_STRING(val)) {
		char* p=JS_GetStringBytes(JS_ValueToString(cx,val));
		for(subnum=0;subnum<sbbs->cfg.total_subs;subnum++)
			if(!stricmp(sbbs->cfg.sub[subnum]->code,p))
				break;
924
	} else if(JSVAL_IS_NUM(val))
925
		JS_ValueToInt32(cx,val,(int32*)&subnum);
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
	else if(sbbs->usrgrps>0)
		subnum=sbbs->usrsub[sbbs->curgrp][sbbs->cursub[sbbs->curgrp]];

	return(subnum);
}

static uint get_dirnum(JSContext* cx, sbbs_t* sbbs, jsval val)
{
	uint dirnum=INVALID_DIR;

	if(JSVAL_IS_STRING(val)) {
		char* p=JS_GetStringBytes(JS_ValueToString(cx,val));
		for(dirnum=0;dirnum<sbbs->cfg.total_dirs;dirnum++)
			if(!stricmp(sbbs->cfg.dir[dirnum]->code,p))
				break;
941
	} else if(JSVAL_IS_NUM(val))
942
		JS_ValueToInt32(cx,val,(int32*)&dirnum);
943
944
945
946
947
948
	else if(sbbs->usrlibs>0)
		dirnum=sbbs->usrdir[sbbs->curlib][sbbs->curdir[sbbs->curlib]];

	return(dirnum);
}

949
950
951
952
/**************************/
/* bbs Object Methods */
/**************************/

rswindell's avatar
rswindell committed
953
954
955
956
957
static JSBool
js_menu(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    JSString*	str;
 	sbbs_t*		sbbs;
deuce's avatar
deuce committed
958
	jsrefcount	rc;
rswindell's avatar
rswindell committed
959
960
961
962
963
964
965
966
 
 	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
 		return(JS_FALSE);
 
 	str = JS_ValueToString(cx, argv[0]);
 	if (!str)
 		return(JS_FALSE);
 
967
	rc=JS_SUSPENDREQUEST(cx);
rswindell's avatar
rswindell committed
968
	sbbs->menu(JS_GetStringBytes(str));
969
	JS_RESUMEREQUEST(cx, rc);
970

rswindell's avatar
rswindell committed
971
972
973
    return(JS_TRUE);
}
 
rswindell's avatar
rswindell committed
974
975
976
977
static JSBool
js_hangup(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
978
	jsrefcount	rc;
rswindell's avatar
rswindell committed
979
980
981
982

	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
		return(JS_FALSE);

983
	rc=JS_SUSPENDREQUEST(cx);
rswindell's avatar
rswindell committed
984
	sbbs->hangup();
985
	JS_RESUMEREQUEST(cx, rc);
rswindell's avatar
rswindell committed
986
987
988
989

	return(JS_TRUE);
}

rswindell's avatar
rswindell committed
990
991
992
993
static JSBool
js_nodesync(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	sbbs_t*		sbbs;
deuce's avatar
deuce committed
994
	jsrefcount	rc;
rswindell's avatar
rswindell committed
995
996
997
998

	if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
		return(JS_FALSE);

999
	rc=JS_SUSPENDREQUEST(cx);
rswindell's avatar
rswindell committed
1000
	sbbs->getnodedat(sbbs->cfg.node_num,&sbbs->thisnode,0);
For faster browsing, not all history is shown. View entire blame