js_msgbase.c 91.2 KB
Newer Older
1
2
3
/* Synchronet JavaScript "MsgBase" Object */

/* $Id$ */
4
// vi: tabstop=4
5
6
7
8
9

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
10
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
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
 *																			*
 * 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"
38
#include "js_request.h"
39
#include "userdat.h"
40
41
42
43
44
45

#ifdef JAVASCRIPT

typedef struct
{
	smb_t	smb;
46
	int		status;
47
48
49
50
	BOOL	debug;

} private_t;

51
52
53
54
55
56
57
58
typedef struct
{
	private_t	*p;
	BOOL		expand_fields;
	smbmsg_t	msg;

} privatemsg_t;

59
static const char* getprivate_failure = "line %d %s %s JS_GetPrivate failed";
60

61
62
63
64
65
66
67
68
69
70
JSBool JS_ValueToUint32(JSContext *cx, jsval v, uint32 *ip)
{
	jsdouble d;

	if(!JS_ValueToNumber(cx, v, &d))
		return JS_FALSE;
	*ip = (uint32)d;
	return JS_TRUE;
}

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Destructor */

static void js_finalize_msgbase(JSContext *cx, JSObject *obj)
{
	private_t* p;
	
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL)
		return;

	if(SMB_IS_OPEN(&(p->smb)))
		smb_close(&(p->smb));

	free(p);

	JS_SetPrivate(cx, obj, NULL);
}

/* Methods */

90
static JSBool
91
js_open(JSContext *cx, uintN argc, jsval *arglist)
92
{
93
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
94
	private_t* p;
deuce's avatar
deuce committed
95
	jsrefcount	rc;
96
97
	
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
98
		JS_ReportError(cx,getprivate_failure,WHERE);
99
		return JS_FALSE;
100
101
	}

102
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
103
104
105
106
107

	if(p->smb.subnum==INVALID_SUB 
		&& strchr(p->smb.file,'/')==NULL
		&& strchr(p->smb.file,'\\')==NULL) {
		JS_ReportError(cx,"Unrecognized msgbase code: %s",p->smb.file);
108
		return JS_TRUE;
109
110
	}

111
	rc=JS_SUSPENDREQUEST(cx);
deuce's avatar
deuce committed
112
	if((p->status=smb_open(&(p->smb)))!=SMB_SUCCESS) {
113
		JS_RESUMEREQUEST(cx, rc);
114
		return JS_TRUE;
deuce's avatar
deuce committed
115
	}
116
	JS_RESUMEREQUEST(cx, rc);
117

118
	JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
119
	return JS_TRUE;
120
121
122
}


123
static JSBool
124
js_close(JSContext *cx, uintN argc, jsval *arglist)
125
{
126
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
127
	private_t* p;
deuce's avatar
deuce committed
128
	jsrefcount	rc;
129
	
130
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
131
		JS_ReportError(cx,getprivate_failure,WHERE);
132
		return JS_FALSE;
133
	}
134

135
136
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

137
	rc=JS_SUSPENDREQUEST(cx);
138
	smb_close(&(p->smb));
139
	JS_RESUMEREQUEST(cx, rc);
140

141
	return JS_TRUE;
142
143
}

144
static BOOL parse_recipient_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg)
145
{
146
147
	char*		cp=NULL;
	size_t		cp_sz=0;
148
	char		to[256];
149
	ushort		nettype=NET_UNKNOWN;
150
151
152
	ushort		agent;
	int32		i32;
	jsval		val;
153
	scfg_t*		scfg;
154

155
156
	scfg = JS_GetRuntimePrivate(JS_GetRuntime(cx));
	
157
	if(JS_GetProperty(cx, hdr, "to", &val) && !JSVAL_NULL_OR_VOID(val)) {
158
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
159
		HANDLE_PENDING(cx, cp);
160
161
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to\" string in recipient object");
162
			return(FALSE);
163
		}
164
	} else {
165
166
		if(p->smb.status.attr&SMB_EMAIL) {	/* e-mail */
			JS_ReportError(cx, "\"to\" property not included in email recipient object");
167
			return(FALSE);					/* "to" property required */
168
		}
169
		cp=strdup("All");
170
	}
deuce's avatar
deuce committed
171

172
	if((p->status=smb_hfield_str(msg, RECIPIENT, cp))!=SMB_SUCCESS) {
173
		JS_ReportError(cx, "Error %d adding RECIPIENT field to message header", p->status);
174
		free(cp);
175
		return(FALSE);
176
	}
177
178
179
180
181
182
	if(!(p->smb.status.attr&SMB_EMAIL)) {
		SAFECOPY(to,cp);
		strlwr(to);
		msg->idx.to=crc16(to,0);
	}

183
	if(JS_GetProperty(cx, hdr, "to_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
184
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
185
		HANDLE_PENDING(cx, cp);
186
187
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_ext\" string in recipient object");
rswindell's avatar
rswindell committed
188
			return(FALSE);
189
190
		}
		if((p->status=smb_hfield_str(msg, RECIPIENTEXT, cp))!=SMB_SUCCESS) {
191
			free(cp);
192
			JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header", p->status);
193
			return(FALSE);
194
		}
rswindell's avatar
rswindell committed
195
196
197
198
		if(p->smb.status.attr&SMB_EMAIL)
			msg->idx.to=atoi(cp);
	}

199
	if(JS_GetProperty(cx, hdr, "to_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
200
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
201
		HANDLE_PENDING(cx, cp);
202
203
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_org\" string in recipient object");
rswindell's avatar
rswindell committed
204
			return(FALSE);
205
206
		}
		if((p->status=smb_hfield_str(msg, RECIPIENTORG, cp))!=SMB_SUCCESS) {
207
			free(cp);
208
			JS_ReportError(cx, "Error %d adding RECIPIENTORG field to message header", p->status);
209
			return(FALSE);
210
		}
rswindell's avatar
rswindell committed
211
212
	}

213
	if(JS_GetProperty(cx, hdr, "to_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
214
215
		if(!JS_ValueToInt32(cx,val,&i32))
			return(FALSE);
rswindell's avatar
rswindell committed
216
217
218
		nettype=(ushort)i32;
	}

219
	if(JS_GetProperty(cx, hdr, "to_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
220
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
221
		HANDLE_PENDING(cx, cp);
222
223
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_net_addr\" string in recipient object");
rswindell's avatar
rswindell committed
224
			return(FALSE);
225
		}
226
		if((p->status=smb_hfield_netaddr(msg, RECIPIENTNETADDR, cp, &nettype))!=SMB_SUCCESS) {
227
			free(cp);
228
			JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header", p->status);
229
			return(FALSE);
230
		}
231
	}
232
	free(cp);
233
234

	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
		if(p->smb.status.attr&SMB_EMAIL) {
			if(nettype==NET_QWK && msg->idx.to==0) {
				char fulladdr[128];
				msg->idx.to = qwk_route(scfg, msg->to_net.addr, fulladdr, sizeof(fulladdr)-1);
				if(fulladdr[0]==0) {
					JS_ReportError(cx, "Unrouteable QWKnet \"to_net_addr\" (%s) in recipient object"
						,msg->to_net.addr);
					return(FALSE);
				}
				if((p->status=smb_hfield_str(msg, RECIPIENTNETADDR, fulladdr))!=SMB_SUCCESS) {
					JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header"
						,p->status);
					return(FALSE);
				}
				if(msg->idx.to != 0) {
					char ext[32];
					sprintf(ext,"%u",msg->idx.to);
					if((p->status=smb_hfield_str(msg, RECIPIENTEXT, ext))!=SMB_SUCCESS) {
						JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header"
							,p->status);
						return(FALSE);
					}
				}
			} else
				msg->idx.to=0;
		}
261
		if((p->status=smb_hfield_bin(msg, RECIPIENTNETTYPE, nettype))!=SMB_SUCCESS) {
262
			JS_ReportError(cx, "Error %d adding RECIPIENTNETTYPE field to message header", p->status);
263
			return(FALSE);
264
		}
rswindell's avatar
rswindell committed
265
266
	}

267
	if(JS_GetProperty(cx, hdr, "to_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
268
269
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
rswindell's avatar
rswindell committed
270
		agent=(ushort)i32;
271
		if((p->status=smb_hfield_bin(msg, RECIPIENTAGENT, agent))!=SMB_SUCCESS) {
272
			JS_ReportError(cx, "Error %d adding RECIPIENTAGENT field to message header", p->status);
273
			return(FALSE);
274
		}
rswindell's avatar
rswindell committed
275
	}
276
277
278
279
280
281
282

	return(TRUE);
}

static BOOL parse_header_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg
								,BOOL recipient)
{
283
284
	char*		cp=NULL;
	size_t		cp_sz=0;
285
	char		from[256];
286
	ushort		nettype=NET_UNKNOWN;
287
	ushort		type;
288
289
	ushort		agent;
	int32		i32;
290
	uint32		u32;
291
	jsval		val;
292
293
294
	JSObject*	array;
	JSObject*	field;
	jsuint		i,len;
295

296
297
	if(hdr==NULL) {
		JS_ReportError(cx, "NULL header object");
298
		goto err;
299
	}
300

301
	if(recipient && !parse_recipient_object(cx,p,hdr,msg))
302
		goto err;
303

304
	if(msg->hdr.type != SMB_MSG_TYPE_BALLOT) {
305
306
307
		/* Required Header Fields */
		if(JS_GetProperty(cx, hdr, "subject", &val) && !JSVAL_NULL_OR_VOID(val)) {
			JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
308
			HANDLE_PENDING(cx, cp);
309
310
311
312
313
314
315
316
317
			if(cp==NULL) {
				JS_ReportError(cx, "Invalid \"subject\" string in header object");
				goto err;
			}
		} else
			cp=strdup("");

		if((p->status=smb_hfield_str(msg, SUBJECT, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SUBJECT field to message header", p->status);
318
			goto err;
319
		}
320
		msg->idx.subj=smb_subject_crc(cp);
321
	}
322
	if(JS_GetProperty(cx, hdr, "from", &val) && !JSVAL_NULL_OR_VOID(val)) {
323
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
324
		HANDLE_PENDING(cx, cp);
325
326
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from\" string in header object");
327
			goto err;
328
329
330
		}
	} else {
		JS_ReportError(cx, "\"from\" property required in header");
331
		goto err;	/* "from" property required */
332
333
	}
	if((p->status=smb_hfield_str(msg, SENDER, cp))!=SMB_SUCCESS) {
334
		JS_ReportError(cx, "Error %d adding SENDER field to message header", p->status);
335
		goto err;
336
	}
337
	if(!(p->smb.status.attr&SMB_EMAIL) && msg->hdr.type != SMB_MSG_TYPE_BALLOT) {
338
339
		SAFECOPY(from,cp);
		strlwr(from);
340
		msg->idx.from=crc16(from,0);
341
	}
342
343

	/* Optional Header Fields */
344
	if(JS_GetProperty(cx, hdr, "from_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
345
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
346
		HANDLE_PENDING(cx, cp);
347
348
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ext\" string in header object");
349
			goto err;
350
351
		}
		if((p->status=smb_hfield_str(msg, SENDEREXT, cp))!=SMB_SUCCESS) {
352
			JS_ReportError(cx, "Error %d adding SENDEREXT field to message header", p->status);
353
			goto err;
354
		}
355
		if(p->smb.status.attr&SMB_EMAIL)
356
357
358
			msg->idx.from=atoi(cp);
	}

359
	if(JS_GetProperty(cx, hdr, "from_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
360
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
361
		HANDLE_PENDING(cx, cp);
362
363
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_org\" string in header object");
364
			goto err;
365
366
		}
		if((p->status=smb_hfield_str(msg, SENDERORG, cp))!=SMB_SUCCESS) {
367
			JS_ReportError(cx, "Error %d adding SENDERORG field to message header", p->status);
368
			goto err;
369
		}
370
371
	}

372
	if(JS_GetProperty(cx, hdr, "from_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
373
374
375
		if(!JS_ValueToInt32(cx,val,&i32)) {
			goto err;
		}
376
		nettype=(ushort)i32;
377
378
	}

379
	if(JS_GetProperty(cx, hdr, "from_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
380
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
381
		HANDLE_PENDING(cx, cp);
382
383
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_net_addr\" string in header object");
384
			goto err;
385
		}
386
		if((p->status=smb_hfield_netaddr(msg, SENDERNETADDR, cp, &nettype))!=SMB_SUCCESS) {
387
			JS_ReportError(cx, "Error %d adding SENDERNETADDR field to message header", p->status);
388
			goto err;
389
		}
390
391
392
393
394
	}
	
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
		if(p->smb.status.attr&SMB_EMAIL)
			msg->idx.from=0;
395
		if((p->status=smb_hfield_bin(msg, SENDERNETTYPE, nettype))!=SMB_SUCCESS) {
396
			JS_ReportError(cx, "Error %d adding SENDERNETTYPE field to message header", p->status);
397
			goto err;
398
		}
399
400
	}

401
	if(JS_GetProperty(cx, hdr, "from_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
402
		if(!JS_ValueToInt32(cx,val,&i32))
403
			goto err;
404
		agent=(ushort)i32;
405
		if((p->status=smb_hfield_bin(msg, SENDERAGENT, agent))!=SMB_SUCCESS) {
406
			JS_ReportError(cx, "Error %d adding SENDERAGENT field to message header", p->status);
407
			goto err;
408
		}
409
410
	}

411
	if(JS_GetProperty(cx, hdr, "from_ip_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
412
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
413
		HANDLE_PENDING(cx, cp);
414
415
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ip_addr\" string in header object");
416
			goto err;
417
418
		}
		if((p->status=smb_hfield_str(msg, SENDERIPADDR, cp))!=SMB_SUCCESS) {
419
			JS_ReportError(cx, "Error %d adding SENDERIPADDR field to message header", p->status);
420
			goto err;
421
		}
422
423
	}

424
	if(JS_GetProperty(cx, hdr, "from_host_name", &val) && !JSVAL_NULL_OR_VOID(val)) {
425
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
426
		HANDLE_PENDING(cx, cp);
427
428
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_host_name\" string in header object");
429
			goto err;
430
431
		}
		if((p->status=smb_hfield_str(msg, SENDERHOSTNAME, cp))!=SMB_SUCCESS) {
432
			JS_ReportError(cx, "Error %d adding SENDERHOSTNAME field to message header", p->status);
433
			goto err;
434
		}
435
436
	}

437
	if(JS_GetProperty(cx, hdr, "from_protocol", &val) && !JSVAL_NULL_OR_VOID(val)) {
438
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
439
		HANDLE_PENDING(cx, cp);
440
441
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_protocol\" string in header object");
442
			goto err;
443
444
		}
		if((p->status=smb_hfield_str(msg, SENDERPROTOCOL, cp))!=SMB_SUCCESS) {
445
			JS_ReportError(cx, "Error %d adding SENDERPROTOCOL field to message header", p->status);
446
			goto err;
447
		}
448
449
	}

450
	if(JS_GetProperty(cx, hdr, "from_port", &val) && !JSVAL_NULL_OR_VOID(val)) {
451
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
452
		HANDLE_PENDING(cx, cp);
453
454
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_port\" string in header object");
455
			goto err;
456
457
		}
		if((p->status=smb_hfield_str(msg, SENDERPORT, cp))!=SMB_SUCCESS) {
458
			JS_ReportError(cx, "Error %d adding SENDERPORT field to message header", p->status);
459
			goto err;
460
		}
461
462
	}

463
	if(JS_GetProperty(cx, hdr, "sender_userid", &val) && !JSVAL_NULL_OR_VOID(val)) {
464
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
465
		HANDLE_PENDING(cx, cp);
466
467
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_userid\" string in header object");
468
			goto err;
469
470
471
		}
		if((p->status=smb_hfield_str(msg, SENDERUSERID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERUSERID field to message header", p->status);
472
			goto err;
473
474
475
476
		}
	}

	if(JS_GetProperty(cx, hdr, "sender_server", &val) && !JSVAL_NULL_OR_VOID(val)) {
477
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
478
		HANDLE_PENDING(cx, cp);
479
480
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_server\" string in header object");
481
			goto err;
482
483
484
		}
		if((p->status=smb_hfield_str(msg, SENDERSERVER, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERSERVER field to message header", p->status);
485
			goto err;
486
487
488
489
		}
	}

	if(JS_GetProperty(cx, hdr, "sender_time", &val) && !JSVAL_NULL_OR_VOID(val)) {
490
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
491
		HANDLE_PENDING(cx, cp);
492
493
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_time\" string in header object");
494
			goto err;
495
496
497
		}
		if((p->status=smb_hfield_str(msg, SENDERTIME, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERTIME field to message header", p->status);
498
			goto err;
499
500
501
		}
	}
	
502
	if(JS_GetProperty(cx, hdr, "replyto", &val) && !JSVAL_NULL_OR_VOID(val)) {
503
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
504
		HANDLE_PENDING(cx, cp);
505
506
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto\" string in header object");
507
			goto err;
508
509
		}
		if((p->status=smb_hfield_str(msg, REPLYTO, cp))!=SMB_SUCCESS) {
510
			JS_ReportError(cx, "Error %d adding REPLYTO field to message header", p->status);
511
			goto err;
512
		}
513
514
	}

515
	if(JS_GetProperty(cx, hdr, "replyto_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
516
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
517
		HANDLE_PENDING(cx, cp);
518
519
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_ext\" string in header object");
520
			goto err;
521
522
		}
		if((p->status=smb_hfield_str(msg, REPLYTOEXT, cp))!=SMB_SUCCESS) {
523
			JS_ReportError(cx, "Error %d adding REPLYTOEXT field to message header", p->status);
524
			goto err;
525
		}
526
527
	}

528
	if(JS_GetProperty(cx, hdr, "replyto_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
529
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
530
		HANDLE_PENDING(cx, cp);
531
532
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_org\" string in header object");
533
			goto err;
534
535
		}
		if((p->status=smb_hfield_str(msg, REPLYTOORG, cp))!=SMB_SUCCESS) {
536
			JS_ReportError(cx, "Error %d adding REPLYTOORG field to message header", p->status);
537
			goto err;
538
		}
539
540
	}

541
	nettype=NET_UNKNOWN;
542
	if(JS_GetProperty(cx, hdr, "replyto_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
543
		if(!JS_ValueToInt32(cx,val,&i32))
544
			goto err;
545
		nettype=(ushort)i32;
546
	}
547
	if(JS_GetProperty(cx, hdr, "replyto_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
548
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
549
		HANDLE_PENDING(cx, cp);
550
551
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_net_addr\" string in header object");
552
			goto err;
553
		}
554
		if((p->status=smb_hfield_netaddr(msg, REPLYTONETADDR, cp, &nettype))!=SMB_SUCCESS) {
555
			JS_ReportError(cx, "Error %d adding REPLYTONETADDR field to message header", p->status);
556
			goto err;
557
		}
558
559
	}
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
560
		if((p->status=smb_hfield_bin(msg, REPLYTONETTYPE, nettype))!=SMB_SUCCESS) {
561
			JS_ReportError(cx, "Error %d adding REPLYTONETTYPE field to message header", p->status);
562
			goto err;
563
		}
564
565
	}

566
	if(JS_GetProperty(cx, hdr, "replyto_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
567
		if(!JS_ValueToInt32(cx,val,&i32))
568
			goto err;
569
		agent=(ushort)i32;
570
		if((p->status=smb_hfield_bin(msg, REPLYTOAGENT, agent))!=SMB_SUCCESS) {
571
			JS_ReportError(cx, "Error %d adding REPLYTOAGENT field to message header", p->status);
572
			goto err;
573
		}
574
575
	}

576
	/* RFC822 headers */
577
	if(JS_GetProperty(cx, hdr, "id", &val) && !JSVAL_NULL_OR_VOID(val)) {
578
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
579
		HANDLE_PENDING(cx, cp);
580
581
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"id\" string in header object");
582
			goto err;
583
584
		}
		if((p->status=smb_hfield_str(msg, RFC822MSGID, cp))!=SMB_SUCCESS) {
585
			JS_ReportError(cx, "Error %d adding RFC822MSGID field to message header", p->status);
586
			goto err;
587
		}
588
589
	}

590
	if(JS_GetProperty(cx, hdr, "reply_id", &val) && !JSVAL_NULL_OR_VOID(val)) {
591
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
592
		HANDLE_PENDING(cx, cp);
593
594
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"reply_id\" string in header object");
595
			goto err;
596
597
		}
		if((p->status=smb_hfield_str(msg, RFC822REPLYID, cp))!=SMB_SUCCESS) {
598
			JS_ReportError(cx, "Error %d adding RFC822REPLYID field to message header", p->status);
599
			goto err;
600
		}
601
602
	}

603
	/* SMTP headers */
604
	if(JS_GetProperty(cx, hdr, "reverse_path", &val) && !JSVAL_NULL_OR_VOID(val)) {
605
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
606
		HANDLE_PENDING(cx, cp);
607
608
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"reverse_path\" string in header object");
609
			goto err;
610
611
		}
		if((p->status=smb_hfield_str(msg, SMTPREVERSEPATH, cp))!=SMB_SUCCESS) {
612
			JS_ReportError(cx, "Error %d adding SMTPREVERSEPATH field to message header", p->status);
613
			goto err;
614
		}
615
616
	}

617
	if(JS_GetProperty(cx, hdr, "forward_path", &val) && !JSVAL_NULL_OR_VOID(val)) {
618
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
619
		HANDLE_PENDING(cx, cp);
620
621
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"forward_path\" string in header object");
622
			goto err;
623
624
		}
		if((p->status=smb_hfield_str(msg, SMTPFORWARDPATH, cp))!=SMB_SUCCESS) {
625
			JS_ReportError(cx, "Error %d adding SMTPFORWARDPATH field to message header", p->status);
626
			goto err;
627
		}
628
629
	}

630
	/* USENET headers */
631
	if(JS_GetProperty(cx, hdr, "path", &val) && !JSVAL_NULL_OR_VOID(val)) {
632
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
633
		HANDLE_PENDING(cx, cp);
634
635
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"path\" string in header object");
636
			goto err;
637
638
		}
		if((p->status=smb_hfield_str(msg, USENETPATH, cp))!=SMB_SUCCESS) {
639
			JS_ReportError(cx, "Error %d adding USENETPATH field to message header", p->status);
640
			goto err;
641
		}
642
643
	}

644
	if(JS_GetProperty(cx, hdr, "newsgroups", &val) && !JSVAL_NULL_OR_VOID(val)) {
645
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
646
		HANDLE_PENDING(cx, cp);
647
648
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"newsgroups\" string in header object");
649
			goto err;
650
651
		}
		if((p->status=smb_hfield_str(msg, USENETNEWSGROUPS, cp))!=SMB_SUCCESS) {
652
			JS_ReportError(cx, "Error %d adding USENETNEWSGROUPS field to message header", p->status);
653
			goto err;
654
		}
655
656
657
	}

	/* FTN headers */
658
	if(JS_GetProperty(cx, hdr, "ftn_msgid", &val) && !JSVAL_NULL_OR_VOID(val)) {
659
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
660
		HANDLE_PENDING(cx, cp);
661
662
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_msgid\" string in header object");
663
			goto err;
664
665
		}
		if((p->status=smb_hfield_str(msg, FIDOMSGID, cp))!=SMB_SUCCESS) {
666
			JS_ReportError(cx, "Error %d adding FIDOMSGID field to message header", p->status);
667
			goto err;
668
		}
669
670
	}

671
	if(JS_GetProperty(cx, hdr, "ftn_reply", &val) && !JSVAL_NULL_OR_VOID(val)) {
672
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
673
		HANDLE_PENDING(cx, cp);
674
675
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_reply\" string in header object");
676
			goto err;
677
678
		}
		if((p->status=smb_hfield_str(msg, FIDOREPLYID, cp))!=SMB_SUCCESS) {
679
			JS_ReportError(cx, "Error %d adding FIDOREPLYID field to message header", p->status);
680
			goto err;
681
		}
682
683
	}

684
	if(JS_GetProperty(cx, hdr, "ftn_area", &val) && !JSVAL_NULL_OR_VOID(val)) {
685
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
686
		HANDLE_PENDING(cx, cp);
687
688
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_area\" string in header object");
689
			goto err;
690
691
		}
		if((p->status=smb_hfield_str(msg, FIDOAREA, cp))!=SMB_SUCCESS) {
692
			JS_ReportError(cx, "Error %d adding FIDOAREA field to message header", p->status);
693
			goto err;
694
		}
695
696
	}

697
	if(JS_GetProperty(cx, hdr, "ftn_flags", &val) && !JSVAL_NULL_OR_VOID(val)) {
698
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
699
		HANDLE_PENDING(cx, cp);
700
701
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_flags\" string in header object");
702
			goto err;
703
704
		}
		if((p->status=smb_hfield_str(msg, FIDOFLAGS, cp))!=SMB_SUCCESS) {
705
			JS_ReportError(cx, "Error %d adding FIDOFLAGS field to message header", p->status);
706
			goto err;
707
		}
708
709
	}

710
	if(JS_GetProperty(cx, hdr, "ftn_pid", &val) && !JSVAL_NULL_OR_VOID(val)) {
711
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
712
		HANDLE_PENDING(cx, cp);
713
714
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_pid\" string in header object");
715
			goto err;
716
717
		}
		if((p->status=smb_hfield_str(msg, FIDOPID, cp))!=SMB_SUCCESS) {
718
			JS_ReportError(cx, "Error %d adding FIDOPID field to message header", p->status);
719
			goto err;
720
		}
721
722
	}

723
	if(JS_GetProperty(cx, hdr, "ftn_tid", &val) && !JSVAL_NULL_OR_VOID(val)) {
724
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
725
		HANDLE_PENDING(cx, cp);
726
727
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_tid\" string in header object");
728
			goto err;
729
730
		}
		if((p->status=smb_hfield_str(msg, FIDOTID, cp))!=SMB_SUCCESS) {
731
			JS_ReportError(cx, "Error %d adding FIDOTID field to message header", p->status);
732
			goto err;
733
		}
rswindell's avatar