js_user.c 20.2 KB
Newer Older
rswindell's avatar
rswindell committed
1
/* js_user.c */
2
3
4
5
6
7
8
9
10
11
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
39
40
41

/* Synchronet JavaScript "User" 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

rswindell's avatar
rswindell committed
42
43
static scfg_t* scfg=NULL;

44
45
typedef struct
{
rswindell's avatar
rswindell committed
46
	uint	usernumber;
47
48
49
50
	scfg_t*	cfg;

} private_t;

51
52
/* User Object Properites */
enum {
rswindell's avatar
rswindell committed
53
54
	 USER_PROP_NUMBER
	,USER_PROP_ALIAS 	
55
56
57
58
59
60
61
62
63
64
65
	,USER_PROP_NAME		
	,USER_PROP_HANDLE	
	,USER_PROP_NOTE		
	,USER_PROP_COMP		
	,USER_PROP_COMMENT	
	,USER_PROP_NETMAIL	
	,USER_PROP_ADDRESS	
	,USER_PROP_LOCATION	
	,USER_PROP_ZIPCODE	
	,USER_PROP_PASS		
	,USER_PROP_PHONE  	
66
67
	,USER_PROP_BIRTH  
	,USER_PROP_AGE		/* READ ONLY */
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	,USER_PROP_MODEM     
	,USER_PROP_LASTON	
	,USER_PROP_FIRSTON	
	,USER_PROP_EXPIRE    
	,USER_PROP_PWMOD     
	,USER_PROP_LOGONS    
	,USER_PROP_LTODAY    
	,USER_PROP_TIMEON    
	,USER_PROP_TEXTRA  	
	,USER_PROP_TTODAY    
	,USER_PROP_TLAST     
	,USER_PROP_POSTS     
	,USER_PROP_EMAILS    
	,USER_PROP_FBACKS    
	,USER_PROP_ETODAY	
	,USER_PROP_PTODAY	
	,USER_PROP_ULB       
	,USER_PROP_ULS       
	,USER_PROP_DLB       
	,USER_PROP_DLS       
	,USER_PROP_CDT		
	,USER_PROP_MIN		
	,USER_PROP_LEVEL 	
	,USER_PROP_FLAGS1	
	,USER_PROP_FLAGS2	
	,USER_PROP_FLAGS3	
	,USER_PROP_FLAGS4	
	,USER_PROP_EXEMPT	
	,USER_PROP_REST		
	,USER_PROP_ROWS		
	,USER_PROP_SEX		
	,USER_PROP_MISC		
	,USER_PROP_LEECH 	
	,USER_PROP_CURSUB	
	,USER_PROP_CURDIR	
	,USER_PROP_FREECDT	
	,USER_PROP_XEDIT 	
	,USER_PROP_SHELL 	
	,USER_PROP_QWK		
	,USER_PROP_TMPEXT	
	,USER_PROP_CHAT		
	,USER_PROP_NS_TIME	
	,USER_PROP_PROT		
};

113
static JSBool js_user_get(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
114
{
115
116
117
	char*		s=NULL;
	char		tmp[128];
	ulong		val=0;
118
    jsint       tiny;
rswindell's avatar
rswindell committed
119
	user_t		user;
120
	private_t*	p;
121

122
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
123
124
		return(JS_FALSE);

rswindell's avatar
rswindell committed
125
126
	user.number=p->usernumber;
	getuserdat(p->cfg,&user);
127
128
129
130

    tiny = JSVAL_TO_INT(id);

	switch(tiny) {
rswindell's avatar
rswindell committed
131
132
133
		case USER_PROP_NUMBER:
			val=user.number;
			break;
134
		case USER_PROP_ALIAS: 
rswindell's avatar
rswindell committed
135
			s=user.alias;
136
137
			break;
		case USER_PROP_NAME:
rswindell's avatar
rswindell committed
138
			s=user.name;
139
140
			break;
		case USER_PROP_HANDLE:
rswindell's avatar
rswindell committed
141
			s=user.handle;
142
143
			break;
		case USER_PROP_NOTE:
rswindell's avatar
rswindell committed
144
			s=user.note;
145
146
			break;
		case USER_PROP_COMP:
rswindell's avatar
rswindell committed
147
			s=user.comp;
148
149
			break;
		case USER_PROP_COMMENT:
rswindell's avatar
rswindell committed
150
			s=user.comment;
151
152
			break;
		case USER_PROP_NETMAIL:
rswindell's avatar
rswindell committed
153
			s=user.netmail;
154
155
			break;
		case USER_PROP_ADDRESS:
rswindell's avatar
rswindell committed
156
			s=user.address;
157
158
			break;
		case USER_PROP_LOCATION:
rswindell's avatar
rswindell committed
159
			s=user.location;
160
161
			break;
		case USER_PROP_ZIPCODE:
rswindell's avatar
rswindell committed
162
			s=user.zipcode;
163
164
			break;
		case USER_PROP_PASS:
rswindell's avatar
rswindell committed
165
			s=user.pass;
166
167
			break;
		case USER_PROP_PHONE:
rswindell's avatar
rswindell committed
168
			s=user.phone;
169
170
			break;
		case USER_PROP_BIRTH:
rswindell's avatar
rswindell committed
171
			s=user.birth;
172
173
			break;
		case USER_PROP_AGE:
rswindell's avatar
rswindell committed
174
			val=getage(p->cfg,user.birth);
175
176
			break;
		case USER_PROP_MODEM:
rswindell's avatar
rswindell committed
177
			s=user.modem;
178
179
			break;
		case USER_PROP_LASTON:
rswindell's avatar
rswindell committed
180
			val=user.laston;
181
182
			break;
		case USER_PROP_FIRSTON:
rswindell's avatar
rswindell committed
183
			val=user.firston;
184
185
			break;
		case USER_PROP_EXPIRE:
rswindell's avatar
rswindell committed
186
			val=user.expire;
187
188
			break;
		case USER_PROP_PWMOD: 
rswindell's avatar
rswindell committed
189
			val=user.pwmod;
190
191
			break;
		case USER_PROP_LOGONS:
rswindell's avatar
rswindell committed
192
			val=user.logons;
193
194
			break;
		case USER_PROP_LTODAY:
rswindell's avatar
rswindell committed
195
			val=user.ltoday;
196
197
			break;
		case USER_PROP_TIMEON:
rswindell's avatar
rswindell committed
198
			val=user.timeon;
199
200
			break;
		case USER_PROP_TEXTRA:
rswindell's avatar
rswindell committed
201
			val=user.textra;
202
203
			break;
		case USER_PROP_TTODAY:
rswindell's avatar
rswindell committed
204
			val=user.ttoday;
205
206
			break;
		case USER_PROP_TLAST: 
rswindell's avatar
rswindell committed
207
			val=user.tlast;
208
209
			break;
		case USER_PROP_POSTS: 
rswindell's avatar
rswindell committed
210
			val=user.posts;
211
212
			break;
		case USER_PROP_EMAILS: 
rswindell's avatar
rswindell committed
213
			val=user.emails;
214
215
			break;
		case USER_PROP_FBACKS: 
rswindell's avatar
rswindell committed
216
			val=user.fbacks;
217
218
			break;
		case USER_PROP_ETODAY:	
rswindell's avatar
rswindell committed
219
			val=user.etoday;
220
221
			break;
		case USER_PROP_PTODAY:
rswindell's avatar
rswindell committed
222
			val=user.ptoday;
223
224
			break;
		case USER_PROP_ULB:
rswindell's avatar
rswindell committed
225
			val=user.ulb;
226
227
			break;
		case USER_PROP_ULS:
rswindell's avatar
rswindell committed
228
			val=user.uls;
229
230
			break;
		case USER_PROP_DLB:
rswindell's avatar
rswindell committed
231
			val=user.dlb;
232
233
			break;
		case USER_PROP_DLS:
rswindell's avatar
rswindell committed
234
			val=user.dls;
235
236
			break;
		case USER_PROP_CDT:
rswindell's avatar
rswindell committed
237
			val=user.cdt;
238
239
			break;
		case USER_PROP_MIN:
rswindell's avatar
rswindell committed
240
			val=user.min;
241
242
			break;
		case USER_PROP_LEVEL:
rswindell's avatar
rswindell committed
243
			val=user.level;
244
245
			break;
		case USER_PROP_FLAGS1:
rswindell's avatar
rswindell committed
246
			val=user.flags1;
247
248
			break;
		case USER_PROP_FLAGS2:
rswindell's avatar
rswindell committed
249
			val=user.flags2;
250
251
			break;
		case USER_PROP_FLAGS3:
rswindell's avatar
rswindell committed
252
			val=user.flags3;
253
254
			break;
		case USER_PROP_FLAGS4:
rswindell's avatar
rswindell committed
255
			val=user.flags4;
256
257
			break;
		case USER_PROP_EXEMPT:
rswindell's avatar
rswindell committed
258
			val=user.exempt;
259
260
			break;
		case USER_PROP_REST:
rswindell's avatar
rswindell committed
261
			val=user.rest;
262
263
			break;
		case USER_PROP_ROWS:
rswindell's avatar
rswindell committed
264
			val=user.rows;
265
266
			break;
		case USER_PROP_SEX:
rswindell's avatar
rswindell committed
267
			sprintf(tmp,"%c",user.sex);
268
269
			s=tmp;
			break;
270
		case USER_PROP_MISC:
rswindell's avatar
rswindell committed
271
			val=user.misc;
272
273
			break;
		case USER_PROP_LEECH:
rswindell's avatar
rswindell committed
274
			val=user.leech;
275
276
			break;
		case USER_PROP_CURSUB:
rswindell's avatar
rswindell committed
277
			s=user.cursub;
278
279
			break;
		case USER_PROP_CURDIR:
rswindell's avatar
rswindell committed
280
			s=user.curdir;
281
282
			break;
		case USER_PROP_FREECDT:
rswindell's avatar
rswindell committed
283
			val=user.freecdt;
284
285
			break;
		case USER_PROP_XEDIT:
286
287
288
289
			if(user.xedit>0 && user.xedit<=p->cfg->total_xedits)
				s=p->cfg->xedit[user.xedit-1]->code;
			else
				s=""; /* internal editor */
290
291
			break;
		case USER_PROP_SHELL:
292
			s=p->cfg->shell[user.shell]->code;
293
			break;
294
		case USER_PROP_QWK:
rswindell's avatar
rswindell committed
295
			val=user.qwk;
296
297
			break;
		case USER_PROP_TMPEXT:
rswindell's avatar
rswindell committed
298
			s=user.tmpext;
299
300
			break;
		case USER_PROP_CHAT:
301
			val=user.chat;
302
303
			break;
		case USER_PROP_NS_TIME:
rswindell's avatar
rswindell committed
304
			val=user.laston;
305
306
			break;
		case USER_PROP_PROT:
rswindell's avatar
rswindell committed
307
			sprintf(tmp,"%c",user.prot);
308
309
310
311
			s=tmp;
			break;
		default:
			return(JS_TRUE);
312
	}
313
314
315
316
	if(s!=NULL) 
		*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, s));
	else
		*vp = INT_TO_JSVAL(val);
317

318
	return(JS_TRUE);
319
320
}

321
static JSBool js_user_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
322
{
323
324
	char*		str;
	char		tmp[64];
325
	jsint		val;
rswindell's avatar
rswindell committed
326
	ulong		usermisc;
327
    jsint       tiny;
328
	JSString*	js_str;
329
	private_t*	p;
330

331
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
332
333
334
335
336
337
338
		return(JS_FALSE);

	if((js_str=JS_ValueToString(cx,*vp))==NULL)
		return(JS_FALSE);

	if((str=JS_GetStringBytes(js_str))==NULL)
		return(JS_FALSE);
339
340
341
342

    tiny = JSVAL_TO_INT(id);

	switch(tiny) {
rswindell's avatar
rswindell committed
343
		case USER_PROP_NUMBER:
344
			JS_ValueToInt32(cx, *vp, (jsint*)&p->usernumber);
rswindell's avatar
rswindell committed
345
			break;
346
		case USER_PROP_ALIAS:
rswindell's avatar
rswindell committed
347
348
349
350
351
352
353
354
			/* update USER.DAT */
			putuserrec(p->cfg,p->usernumber,U_ALIAS,LEN_ALIAS,str);

			/* update NAME.DAT */
			getuserrec(p->cfg,p->usernumber,U_MISC,8,tmp);
			usermisc=ahtoul(tmp);
			if(!(usermisc&DELETED))
				putusername(p->cfg,p->usernumber,str);
355
356
			break;
		case USER_PROP_NAME:
rswindell's avatar
rswindell committed
357
			putuserrec(p->cfg,p->usernumber,U_NAME,LEN_NAME,str);
358
359
			break;
		case USER_PROP_HANDLE:
rswindell's avatar
rswindell committed
360
			putuserrec(p->cfg,p->usernumber,U_HANDLE,LEN_HANDLE,str);
361
362
			break;
		case USER_PROP_NOTE:		 
rswindell's avatar
rswindell committed
363
			putuserrec(p->cfg,p->usernumber,U_NOTE,LEN_NOTE,str);
364
365
			break;
		case USER_PROP_COMP:		 
rswindell's avatar
rswindell committed
366
			putuserrec(p->cfg,p->usernumber,U_COMP,LEN_COMP,str);
367
368
			break;
		case USER_PROP_COMMENT:	 
rswindell's avatar
rswindell committed
369
			putuserrec(p->cfg,p->usernumber,U_COMMENT,LEN_COMMENT,str);
370
371
			break;
		case USER_PROP_NETMAIL:	 
rswindell's avatar
rswindell committed
372
			putuserrec(p->cfg,p->usernumber,U_NETMAIL,LEN_NETMAIL,str);
373
374
			break;
		case USER_PROP_ADDRESS:	 
rswindell's avatar
rswindell committed
375
			putuserrec(p->cfg,p->usernumber,U_ADDRESS,LEN_ADDRESS,str);
376
377
			break;
		case USER_PROP_LOCATION:	 
rswindell's avatar
rswindell committed
378
			putuserrec(p->cfg,p->usernumber,U_LOCATION,LEN_LOCATION,str);
379
380
			break;
		case USER_PROP_ZIPCODE:	 
rswindell's avatar
rswindell committed
381
			putuserrec(p->cfg,p->usernumber,U_ZIPCODE,LEN_ZIPCODE,str);
382
383
			break;
		case USER_PROP_PHONE:  	 
rswindell's avatar
rswindell committed
384
			putuserrec(p->cfg,p->usernumber,U_PHONE,LEN_PHONE,str);
385
386
			break;
		case USER_PROP_BIRTH:  	 
rswindell's avatar
rswindell committed
387
			putuserrec(p->cfg,p->usernumber,U_BIRTH,LEN_BIRTH,str);
388
389
			break;
		case USER_PROP_MODEM:     
rswindell's avatar
rswindell committed
390
			putuserrec(p->cfg,p->usernumber,U_MODEM,LEN_MODEM,str);
391
392
			break;
		case USER_PROP_ROWS:		 
rswindell's avatar
rswindell committed
393
			putuserrec(p->cfg,p->usernumber,U_ROWS,2,str);	/* base 10 */
394
395
			break;
		case USER_PROP_SEX:		 
rswindell's avatar
rswindell committed
396
			putuserrec(p->cfg,p->usernumber,U_SEX,1,strupr(str));	/* single char */
397
398
			break;
		case USER_PROP_CURSUB:	 
rswindell's avatar
rswindell committed
399
			putuserrec(p->cfg,p->usernumber,U_CURSUB,8,strupr(str));
400
401
			break;
		case USER_PROP_CURDIR:	 
rswindell's avatar
rswindell committed
402
			putuserrec(p->cfg,p->usernumber,U_CURDIR,8,strupr(str));
403
404
			break;
		case USER_PROP_XEDIT: 	 
rswindell's avatar
rswindell committed
405
			putuserrec(p->cfg,p->usernumber,U_XEDIT,8,strupr(str));
406
407
			break;
		case USER_PROP_SHELL: 	 
rswindell's avatar
rswindell committed
408
			putuserrec(p->cfg,p->usernumber,U_COMP,8,strupr(str));
409
410
411
			break;
		case USER_PROP_MISC:
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
412
			putuserrec(p->cfg,p->usernumber,U_MISC,8,ultoa(val,tmp,16));
413
414
415
			break;
		case USER_PROP_QWK:		 
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
416
			putuserrec(p->cfg,p->usernumber,U_QWK,8,ultoa(val,tmp,16));
417
418
419
			break;
		case USER_PROP_CHAT:		 
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
420
			putuserrec(p->cfg,p->usernumber,U_CHAT,8,ultoa(val,tmp,16));
421
422
			break;
		case USER_PROP_TMPEXT:	 
rswindell's avatar
rswindell committed
423
			putuserrec(p->cfg,p->usernumber,U_TMPEXT,3,str);
424
425
426
			break;
		case USER_PROP_NS_TIME:	 
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
427
			putuserrec(p->cfg,p->usernumber,U_NS_TIME,8,ultoa(val,tmp,16));
428
429
			break;
		case USER_PROP_PROT:	
rswindell's avatar
rswindell committed
430
			putuserrec(p->cfg,p->usernumber,U_PROT,1,strupr(str)); /* single char */
431
432
433
434
			break;
			
		/* security properties*/
		case USER_PROP_PASS:	
rswindell's avatar
rswindell committed
435
			putuserrec(p->cfg,p->usernumber,U_PASS,LEN_PASS,strupr(str));
436
437
438
			break;
		case USER_PROP_PWMOD:
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
439
			putuserrec(p->cfg,p->usernumber,U_PWMOD,8,ultoa(val,tmp,16));
440
441
			break;
		case USER_PROP_LEVEL: 
rswindell's avatar
rswindell committed
442
			putuserrec(p->cfg,p->usernumber,U_LEVEL,2,str);
443
444
445
			break;
		case USER_PROP_FLAGS1:
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
446
			putuserrec(p->cfg,p->usernumber,U_FLAGS1,8,ultoa(val,tmp,16));
447
448
449
			break;
		case USER_PROP_FLAGS2:
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
450
			putuserrec(p->cfg,p->usernumber,U_FLAGS2,8,ultoa(val,tmp,16));
451
452
453
			break;
		case USER_PROP_FLAGS3:
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
454
			putuserrec(p->cfg,p->usernumber,U_FLAGS3,8,ultoa(val,tmp,16));
455
456
457
			break;
		case USER_PROP_FLAGS4:
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
458
			putuserrec(p->cfg,p->usernumber,U_FLAGS4,8,ultoa(val,tmp,16));
459
460
461
			break;
		case USER_PROP_EXEMPT:
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
462
			putuserrec(p->cfg,p->usernumber,U_EXEMPT,8,ultoa(val,tmp,16));
463
464
465
			break;
		case USER_PROP_REST:	
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
466
			putuserrec(p->cfg,p->usernumber,U_REST,8,ultoa(val,tmp,16));
467
468
			break;
		case USER_PROP_CDT:	
rswindell's avatar
rswindell committed
469
			putuserrec(p->cfg,p->usernumber,U_CDT,10,str);
470
471
			break;
		case USER_PROP_FREECDT:
rswindell's avatar
rswindell committed
472
			putuserrec(p->cfg,p->usernumber,U_FREECDT,10,str);
473
474
			break;
		case USER_PROP_MIN:	
rswindell's avatar
rswindell committed
475
			putuserrec(p->cfg,p->usernumber,U_MIN,10,str);
476
477
			break;
		case USER_PROP_TEXTRA:  
rswindell's avatar
rswindell committed
478
			putuserrec(p->cfg,p->usernumber,U_TEXTRA,5,str);
479
480
481
			break;
		case USER_PROP_EXPIRE:  
			JS_ValueToInt32(cx,*vp,&val);
rswindell's avatar
rswindell committed
482
			putuserrec(p->cfg,p->usernumber,U_EXPIRE,8,ultoa(val,tmp,16));
483
			break;
484
485
	}

486
	return(JS_TRUE);
487
488
}

489
#define USER_PROP_FLAGS JSPROP_ENUMERATE
490
491
492
493

static struct JSPropertySpec js_user_properties[] = {
/*		 name				,tinyid					,flags,				getter,	setter	*/

494
	{	"number"			,USER_PROP_NUMBER		,USER_PROP_FLAGS,		NULL,NULL},
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
	{	"alias"				,USER_PROP_ALIAS 		,USER_PROP_FLAGS,		NULL,NULL},
	{	"name"				,USER_PROP_NAME		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"handle"			,USER_PROP_HANDLE	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"note"				,USER_PROP_NOTE		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"ip_address"		,USER_PROP_NOTE		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"computer"			,USER_PROP_COMP		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"host_name"			,USER_PROP_COMP		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"comment"			,USER_PROP_COMMENT	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"netmail"			,USER_PROP_NETMAIL	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"email"				,USER_PROP_NETMAIL	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"address"			,USER_PROP_ADDRESS	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"location"			,USER_PROP_LOCATION	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"zipcode"			,USER_PROP_ZIPCODE	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"phone"				,USER_PROP_PHONE  	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"birthdate"			,USER_PROP_BIRTH  	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"age"				,USER_PROP_AGE			,USER_PROP_FLAGS|JSPROP_READONLY,		NULL,NULL},
	{	"modem"				,USER_PROP_MODEM      	,USER_PROP_FLAGS,		NULL,NULL},
	{	"connection"		,USER_PROP_MODEM      	,USER_PROP_FLAGS,		NULL,NULL},
	{	"screen_rows"		,USER_PROP_ROWS		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"gender"			,USER_PROP_SEX		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"cursub"			,USER_PROP_CURSUB	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"curdir"			,USER_PROP_CURDIR	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"editor"			,USER_PROP_XEDIT 	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"command_shell"		,USER_PROP_SHELL 	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"settings"			,USER_PROP_MISC		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"qwk_settings"		,USER_PROP_QWK		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"chat_settings"		,USER_PROP_CHAT		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"temp_file_ext"		,USER_PROP_TMPEXT	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"newscan_date"		,USER_PROP_NS_TIME	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"download_protocol"	,USER_PROP_PROT		 	,USER_PROP_FLAGS,		NULL,NULL},
525
526
527
	{0}
};

528
529
/* user.security */
static struct JSPropertySpec js_user_security_properties[] = {
530
531
/*		 name				,tinyid					,flags,				getter,	setter	*/

532
533
534
535
536
537
538
539
540
541
542
543
544
545
	{	"password"			,USER_PROP_PASS		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"password_date"		,USER_PROP_PWMOD      	,USER_PROP_FLAGS,		NULL,NULL},
	{	"level"				,USER_PROP_LEVEL 	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"flags1"			,USER_PROP_FLAGS1	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"flags2"			,USER_PROP_FLAGS2	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"flags3"			,USER_PROP_FLAGS3	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"flags4"			,USER_PROP_FLAGS4	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"exemptions"		,USER_PROP_EXEMPT	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"restrictions"		,USER_PROP_REST		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"credits"			,USER_PROP_CDT		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"free_credits"		,USER_PROP_FREECDT	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"minutes"			,USER_PROP_MIN		 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"extra_time"		,USER_PROP_TEXTRA  	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"expiration_date"	,USER_PROP_EXPIRE     	,USER_PROP_FLAGS,		NULL,NULL},
546
547
548
	{0}
};

549
550
551
552
553
#undef  USER_PROP_FLAGS
#define USER_PROP_FLAGS JSPROP_ENUMERATE|JSPROP_READONLY

/* user.stats: These should be READ ONLY by nature */
static struct JSPropertySpec js_user_stats_properties[] = {
554
555
/*		 name				,tinyid					,flags,				getter,	setter	*/

556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
	{	"laston_date"		,USER_PROP_LASTON	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"firston_date"		,USER_PROP_FIRSTON	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"total_logons"		,USER_PROP_LOGONS     	,USER_PROP_FLAGS,		NULL,NULL},
	{	"logons_today"		,USER_PROP_LTODAY     	,USER_PROP_FLAGS,		NULL,NULL},
	{	"total_timeon"		,USER_PROP_TIMEON     	,USER_PROP_FLAGS,		NULL,NULL},
	{	"timeon_today"		,USER_PROP_TTODAY     	,USER_PROP_FLAGS,		NULL,NULL},
	{	"timeon_last_logon"	,USER_PROP_TLAST      	,USER_PROP_FLAGS,		NULL,NULL},
	{	"total_posts"		,USER_PROP_POSTS      	,USER_PROP_FLAGS,		NULL,NULL},
	{	"total_emails"		,USER_PROP_EMAILS     	,USER_PROP_FLAGS,		NULL,NULL},
	{	"total_feedbacks"	,USER_PROP_FBACKS     	,USER_PROP_FLAGS,		NULL,NULL},
	{	"email_today"		,USER_PROP_ETODAY	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"posts_today"		,USER_PROP_PTODAY	 	,USER_PROP_FLAGS,		NULL,NULL},
	{	"bytes_uploaded"	,USER_PROP_ULB        	,USER_PROP_FLAGS,		NULL,NULL},
	{	"files_uploaded"	,USER_PROP_ULS        	,USER_PROP_FLAGS,		NULL,NULL},
	{	"bytes_downloaded"	,USER_PROP_DLB        	,USER_PROP_FLAGS,		NULL,NULL},
	{	"files_downloaded"	,USER_PROP_DLS        	,USER_PROP_FLAGS,		NULL,NULL},
	{	"leech_attempts"	,USER_PROP_LEECH 	 	,USER_PROP_FLAGS,		NULL,NULL},
573
574
575
	{0}
};

576
577
578
579
580
581
static void js_user_finalize(JSContext *cx, JSObject *obj)
{
	private_t* p;

	p=(private_t*)JS_GetPrivate(cx,obj);

rswindell's avatar
rswindell committed
582
	if(p!=NULL && (scfg_t*)p!=scfg)
583
584
585
586
587
588
589
590
591
592
593
		free(p);

	p=NULL;
	JS_SetPrivate(cx,obj,p);
}

static JSBool
js_chk_ar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	char*		ar;
	JSString*	js_str;
rswindell's avatar
rswindell committed
594
	user_t		user;
595
596
597
598
599
600
601
602
603
604
	private_t*	p;

	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
		return JS_FALSE;

	if((js_str=JS_ValueToString(cx, argv[0]))==NULL)
		return JS_FALSE;

	ar = arstr(NULL,JS_GetStringBytes(js_str),p->cfg);

rswindell's avatar
rswindell committed
605
606
607
608
	user.number=p->usernumber;
	getuserdat(p->cfg,&user);

	*rval = BOOLEAN_TO_JSVAL(chk_ar(p->cfg,ar,&user));
609
610
611
612
613
614
615
616
617
618
619
620

	if(ar!=NULL && ar!=nular)
		free(ar);

	return(JS_TRUE);
}

static JSFunctionSpec js_user_functions[] = {
	{"compare_ars",	js_chk_ar,			1},		/* Verify ARS */
	{0}
};

621
622
623
624
625
626
627
628
629
630
static JSClass js_user_class = {
     "User"					/* name			*/
    ,JSCLASS_HAS_PRIVATE	/* flags		*/
	,JS_PropertyStub		/* addProperty	*/
	,JS_PropertyStub		/* delProperty	*/
	,js_user_get			/* getProperty	*/
	,js_user_set			/* setProperty	*/
	,JS_EnumerateStub		/* enumerate	*/
	,JS_ResolveStub			/* resolve		*/
	,JS_ConvertStub			/* convert		*/
631
	,js_user_finalize		/* finalize		*/
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
};

static JSClass js_user_stats_class = {
     "UserStats"			/* name			*/
    ,JSCLASS_HAS_PRIVATE	/* flags		*/
	,JS_PropertyStub		/* addProperty	*/
	,JS_PropertyStub		/* delProperty	*/
	,js_user_get			/* getProperty	*/
	,js_user_set			/* setProperty	*/
	,JS_EnumerateStub		/* enumerate	*/
	,JS_ResolveStub			/* resolve		*/
	,JS_ConvertStub			/* convert		*/
	,JS_FinalizeStub		/* finalize		*/
};


static JSClass js_user_security_class = {
     "UserSecurity"			/* name			*/
    ,JSCLASS_HAS_PRIVATE	/* flags		*/
	,JS_PropertyStub		/* addProperty	*/
	,JS_PropertyStub		/* delProperty	*/
	,js_user_get			/* getProperty	*/
	,js_user_set			/* setProperty	*/
	,JS_EnumerateStub		/* enumerate	*/
	,JS_ResolveStub			/* resolve		*/
	,JS_ConvertStub			/* convert		*/
	,JS_FinalizeStub		/* finalize		*/
};

rswindell's avatar
rswindell committed
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/* User Constructor (creates instance of user class) */

static JSBool
js_user_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
	user_t		user;
	private_t*	p;

	user.number=(ushort)(JSVAL_TO_INT(argv[0]));
	if(getuserdat(scfg,&user)!=0)
		return(JS_FALSE);

	if((p=(private_t*)malloc(sizeof(private_t)))==NULL)
		return(JS_FALSE);

	p->cfg = scfg;
	p->usernumber = user.number;

	JS_SetPrivate(cx, obj, p);

	return(JS_TRUE);
}


JSObject* DLLCALL js_CreateUserClass(JSContext* cx, JSObject* parent, scfg_t* cfg)
{
	JSObject*	userclass;

	scfg = cfg;
	userclass = JS_InitClass(cx, parent, NULL
		,&js_user_class
		,js_user_constructor
		,1	/* number of constructor args */
		,js_user_properties
		,js_user_functions
		,NULL,NULL);

//	JS_SetPrivate(cx, userclass, cfg);	

	return(userclass);
}

JSObject* DLLCALL js_CreateUserObject(JSContext* cx, JSObject* parent, scfg_t* cfg, char* name, uint usernumber)
704
705
706
707
{
	JSObject*	userobj;
	JSObject*	statsobj;
	JSObject*	securityobj;
708
709
710
711
712
713
	private_t*	p;

	if((p=(private_t*)malloc(sizeof(private_t)))==NULL)
		return(NULL);

	p->cfg = cfg;
rswindell's avatar
rswindell committed
714
	p->usernumber = usernumber;
715
716
717
718
719
720

	userobj = JS_DefineObject(cx, parent, name, &js_user_class, NULL, 0);

	if(userobj==NULL)
		return(NULL);

721
	JS_SetPrivate(cx, userobj, p);	
722
723
724

	JS_DefineProperties(cx, userobj, js_user_properties);

725
726
	JS_DefineFunctions(cx, userobj, js_user_functions);

727
728
729
730
731
732
733
	/* user.stats */
	statsobj = JS_DefineObject(cx, userobj, "stats"
		,&js_user_stats_class, NULL, 0);

	if(statsobj==NULL)
		return(NULL);

734
	JS_SetPrivate(cx, statsobj, p);
735
736
737
738
739
740
741
742
743
744

	JS_DefineProperties(cx, statsobj, js_user_stats_properties);

	/* user.security */
	securityobj = JS_DefineObject(cx, userobj, "security"
		,&js_user_security_class, NULL, 0);

	if(securityobj==NULL)
		return(NULL);

745
	JS_SetPrivate(cx, securityobj, p);
746
747
748
749
750
751
752

	JS_DefineProperties(cx, securityobj, js_user_security_properties);

	return(userobj);
}

#endif	/* JAVSCRIPT */