js_msgbase.c 95.4 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		smb_result;
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);
112
	if((p->smb_result=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
173
	if((p->smb_result=smb_hfield_str(msg, RECIPIENT, cp))!=SMB_SUCCESS) {
		JS_ReportError(cx, "Error %d adding RECIPIENT field to message header", p->smb_result);
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->smb_result=smb_hfield_str(msg, RECIPIENTEXT, cp))!=SMB_SUCCESS) {
191
			free(cp);
192
			JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header", p->smb_result);
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->smb_result=smb_hfield_str(msg, RECIPIENTORG, cp))!=SMB_SUCCESS) {
207
			free(cp);
208
			JS_ReportError(cx, "Error %d adding RECIPIENTORG field to message header", p->smb_result);
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)) {
			free(cp);
216
			return(FALSE);
217
		}
rswindell's avatar
rswindell committed
218
219
220
		nettype=(ushort)i32;
	}

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

	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
237
238
239
240
241
242
243
244
245
		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);
				}
246
				if((p->smb_result=smb_hfield_str(msg, RECIPIENTNETADDR, fulladdr))!=SMB_SUCCESS) {
247
					JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header"
248
						,p->smb_result);
249
250
251
252
253
					return(FALSE);
				}
				if(msg->idx.to != 0) {
					char ext[32];
					sprintf(ext,"%u",msg->idx.to);
254
					if((p->smb_result=smb_hfield_str(msg, RECIPIENTEXT, ext))!=SMB_SUCCESS) {
255
						JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header"
256
							,p->smb_result);
257
258
259
260
261
262
						return(FALSE);
					}
				}
			} else
				msg->idx.to=0;
		}
263
264
		if((p->smb_result=smb_hfield_bin(msg, RECIPIENTNETTYPE, nettype))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding RECIPIENTNETTYPE field to message header", p->smb_result);
265
			return(FALSE);
266
		}
rswindell's avatar
rswindell committed
267
268
	}

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

	return(TRUE);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

725
	if(JS_GetProperty(cx, hdr, "ftn_tid", &val) && !JSVAL_NULL_OR_VOID(val)) {
726
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
727
		HANDLE_PENDING(cx, cp);