js_msgbase.c 95.9 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
	int			smb_result = SMB_SUCCESS;
155

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

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

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

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

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

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

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

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

	return(TRUE);
281
282
283
284
285
286

err:
	if(smb_result != SMB_SUCCESS && p != NULL)
		p->smb_result = smb_result;
	return(FALSE);

287
288
289
290
291
}

static BOOL parse_header_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg
								,BOOL recipient)
{
292
293
	char*		cp=NULL;
	size_t		cp_sz=0;
294
	char		from[256];
295
	ushort		nettype=NET_UNKNOWN;
296
	ushort		type;
297
298
	ushort		agent;
	int32		i32;
299
	uint32		u32;
300
	jsval		val;
301
302
303
	JSObject*	array;
	JSObject*	field;
	jsuint		i,len;
304
	int			smb_result = SMB_SUCCESS;
305

306
307
	if(hdr==NULL) {
		JS_ReportError(cx, "NULL header object");
308
		goto err;
309
	}
310

311
	if(recipient && !parse_recipient_object(cx,p,hdr,msg))
312
		goto err;
313

314
	if(msg->hdr.type != SMB_MSG_TYPE_BALLOT) {
315
316
317
		/* Required Header Fields */
		if(JS_GetProperty(cx, hdr, "subject", &val) && !JSVAL_NULL_OR_VOID(val)) {
			JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
318
			HANDLE_PENDING(cx, cp);
319
320
321
322
323
324
325
			if(cp==NULL) {
				JS_ReportError(cx, "Invalid \"subject\" string in header object");
				goto err;
			}
		} else
			cp=strdup("");

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

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

369
	if(JS_GetProperty(cx, hdr, "from_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
370
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
371
		HANDLE_PENDING(cx, cp);
372
373
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_org\" string in header object");
374
			goto err;
375
		}
376
377
		if((smb_result = smb_hfield_str(msg, SENDERORG, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERORG field to message header", smb_result);
378
			goto err;
379
		}
380
381
	}

382
	if(JS_GetProperty(cx, hdr, "from_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
383
384
385
		if(!JS_ValueToInt32(cx,val,&i32)) {
			goto err;
		}
386
		nettype=(ushort)i32;
387
388
	}

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

411
	if(JS_GetProperty(cx, hdr, "from_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
412
		if(!JS_ValueToInt32(cx,val,&i32))
413
			goto err;
414
		agent=(ushort)i32;
415
416
		if((smb_result = smb_hfield_bin(msg, SENDERAGENT, agent))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERAGENT field to message header", smb_result);
417
			goto err;
418
		}
419
420
	}

421
	if(JS_GetProperty(cx, hdr, "from_ip_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
422
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
423
		HANDLE_PENDING(cx, cp);
424
425
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ip_addr\" string in header object");
426
			goto err;
427
		}
428
429
		if((smb_result = smb_hfield_str(msg, SENDERIPADDR, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERIPADDR field to message header", smb_result);
430
			goto err;
431
		}
432
433
	}

434
	if(JS_GetProperty(cx, hdr, "from_host_name", &val) && !JSVAL_NULL_OR_VOID(val)) {
435
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
436
		HANDLE_PENDING(cx, cp);
437
438
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_host_name\" string in header object");
439
			goto err;
440
		}
441
442
		if((smb_result = smb_hfield_str(msg, SENDERHOSTNAME, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERHOSTNAME field to message header", smb_result);
443
			goto err;
444
		}
445
446
	}

447
	if(JS_GetProperty(cx, hdr, "from_protocol", &val) && !JSVAL_NULL_OR_VOID(val)) {
448
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
449
		HANDLE_PENDING(cx, cp);
450
451
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_protocol\" string in header object");
452
			goto err;
453
		}
454
455
		if((smb_result = smb_hfield_str(msg, SENDERPROTOCOL, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERPROTOCOL field to message header", smb_result);
456
			goto err;
457
		}
458
459
	}

460
	if(JS_GetProperty(cx, hdr, "from_port", &val) && !JSVAL_NULL_OR_VOID(val)) {
461
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
462
		HANDLE_PENDING(cx, cp);
463
464
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_port\" string in header object");
465
			goto err;
466
		}
467
468
		if((smb_result = smb_hfield_str(msg, SENDERPORT, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERPORT field to message header", smb_result);
469
			goto err;
470
		}
471
472
	}

473
	if(JS_GetProperty(cx, hdr, "sender_userid", &val) && !JSVAL_NULL_OR_VOID(val)) {
474
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
475
		HANDLE_PENDING(cx, cp);
476
477
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_userid\" string in header object");
478
			goto err;
479
		}
480
481
		if((smb_result = smb_hfield_str(msg, SENDERUSERID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERUSERID field to message header", smb_result);
482
			goto err;
483
484
485
486
		}
	}

	if(JS_GetProperty(cx, hdr, "sender_server", &val) && !JSVAL_NULL_OR_VOID(val)) {
487
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
488
		HANDLE_PENDING(cx, cp);
489
490
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_server\" string in header object");
491
			goto err;
492
		}
493
494
		if((smb_result = smb_hfield_str(msg, SENDERSERVER, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERSERVER field to message header", smb_result);
495
			goto err;
496
497
498
499
		}
	}

	if(JS_GetProperty(cx, hdr, "sender_time", &val) && !JSVAL_NULL_OR_VOID(val)) {
500
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
501
		HANDLE_PENDING(cx, cp);
502
503
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_time\" string in header object");
504
			goto err;
505
		}
506
507
		if((smb_result = smb_hfield_str(msg, SENDERTIME, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERTIME field to message header", smb_result);
508
			goto err;
509
510
511
		}
	}
	
512
	if(JS_GetProperty(cx, hdr, "replyto", &val) && !JSVAL_NULL_OR_VOID(val)) {
513
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
514
		HANDLE_PENDING(cx, cp);
515
516
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto\" string in header object");
517
			goto err;
518
		}
519
520
		if((smb_result = smb_hfield_str(msg, REPLYTO, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTO field to message header", smb_result);
521
			goto err;
522
		}
523
524
	}

525
	if(JS_GetProperty(cx, hdr, "replyto_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
526
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
527
		HANDLE_PENDING(cx, cp);
528
529
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_ext\" string in header object");
530
			goto err;
531
		}
532
533
		if((smb_result = smb_hfield_str(msg, REPLYTOEXT, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOEXT field to message header", smb_result);
534
			goto err;
535
		}
536
537
	}

538
	if(JS_GetProperty(cx, hdr, "replyto_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
539
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
540
		HANDLE_PENDING(cx, cp);
541
542
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_org\" string in header object");
543
			goto err;
544
		}
545
546
		if((smb_result = smb_hfield_str(msg, REPLYTOORG, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOORG field to message header", smb_result);
547
			goto err;
548
		}
549
550
	}

551
	nettype=NET_UNKNOWN;
552
	if(JS_GetProperty(cx, hdr, "replyto_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
553
		if(!JS_ValueToInt32(cx,val,&i32))
554
			goto err;
555
		nettype=(ushort)i32;
556
	}
557
	if(JS_GetProperty(cx, hdr, "replyto_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
558
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
559
		HANDLE_PENDING(cx, cp);
560
561
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_net_addr\" string in header object");
562
			goto err;
563
		}
564
565
		if((smb_result = smb_hfield_netaddr(msg, REPLYTONETADDR, cp, &nettype))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTONETADDR field to message header", smb_result);
566
			goto err;
567
		}
568
569
	}
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
570
571
		if((smb_result = smb_hfield_bin(msg, REPLYTONETTYPE, nettype))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTONETTYPE field to message header", smb_result);
572
			goto err;
573
		}
574
575
	}

576
	if(JS_GetProperty(cx, hdr, "replyto_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
577
		if(!JS_ValueToInt32(cx,val,&i32))
578
			goto err;
579
		agent=(ushort)i32;
580
581
		if((smb_result = smb_hfield_bin(msg, REPLYTOAGENT, agent))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOAGENT field to message header", smb_result);
582
			goto err;
583
		}
584
585
	}

586
	/* RFC822 headers */
587
	if(JS_GetProperty(cx, hdr, "id", &val) && !JSVAL_NULL_OR_VOID(val)) {
588
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
589
		HANDLE_PENDING(cx, cp);
590
591
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"id\" string in header object");
592
			goto err;
593
		}
594
595
		if((smb_result = smb_hfield_str(msg, RFC822MSGID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding RFC822MSGID field to message header", smb_result);
596
			goto err;
597
		}
598
599
	}

600
	if(JS_GetProperty(cx, hdr, "reply_id", &val) && !JSVAL_NULL_OR_VOID(val)) {
601
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
602
		HANDLE_PENDING(cx, cp);
603
604
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"reply_id\" string in header object");
605
			goto err;
606
		}
607
608
		if((smb_result = smb_hfield_str(msg, RFC822REPLYID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding RFC822REPLYID field to message header", smb_result);
609
			goto err;
610
		}
611
612
	}

613
	/* SMTP headers */
614
	if(JS_GetProperty(cx, hdr, "reverse_path", &val) && !JSVAL_NULL_OR_VOID(val)) {
615
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
616
		HANDLE_PENDING(cx, cp);
617
618
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"reverse_path\" string in header object");
619
			goto err;
620
		}
621
622
		if((smb_result = smb_hfield_str(msg, SMTPREVERSEPATH, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SMTPREVERSEPATH field to message header", smb_result);
623
			goto err;
624
		}
625
626
	}

627
	if(JS_GetProperty(cx, hdr, "forward_path", &val) && !JSVAL_NULL_OR_VOID(val)) {
628
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
629
		HANDLE_PENDING(cx, cp);
630
631
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"forward_path\" string in header object");
632
			goto err;
633
		}
634
635
		if((smb_result = smb_hfield_str(msg, SMTPFORWARDPATH, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SMTPFORWARDPATH field to message header", smb_result);
636
			goto err;
637
		}
638
639
	}

640
	/* USENET headers */
641
	if(JS_GetProperty(cx, hdr, "path", &val) && !JSVAL_NULL_OR_VOID(val)) {
642
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
643
		HANDLE_PENDING(cx, cp);
644
645
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"path\" string in header object");
646
			goto err;
647
		}
648
649
		if((smb_result = smb_hfield_str(msg, USENETPATH, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding USENETPATH field to message header", smb_result);
650
			goto err;
651
		}
652
653
	}

654
	if(JS_GetProperty(cx, hdr, "newsgroups", &val) && !JSVAL_NULL_OR_VOID(val)) {
655
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
656
		HANDLE_PENDING(cx, cp);
657
658
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"newsgroups\" string in header object");
659
			goto err;
660
		}
661
662
		if((smb_result = smb_hfield_str(msg, USENETNEWSGROUPS, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding USENETNEWSGROUPS field to message header", smb_result);
663
			goto err;
664
		}
665
666
667
	}

	/* FTN headers */
668
	if(JS_GetProperty(cx, hdr, "ftn_msgid", &val) && !JSVAL_NULL_OR_VOID(val)) {
669
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
670
		HANDLE_PENDING(cx, cp);
671
672
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_msgid\" string in header object");
673
			goto err;
674
		}
675
676
		if((smb_result = smb_hfield_str(msg, FIDOMSGID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding FIDOMSGID field to message header", smb_result);
677
			goto err;
678
		}
679
680
	}

681
	if(JS_GetProperty(cx, hdr, "ftn_reply", &val) && !JSVAL_NULL_OR_VOID(val)) {
682
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
683
		HANDLE_PENDING(cx, cp);
684
685
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_reply\" string in header object");
686
			goto err;
687
		}
688
689
		if((smb_result = smb_hfield_str(msg, FIDOREPLYID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding FIDOREPLYID field to message header", smb_result);
690
			goto err;
691
		}
692
693
	}

694
	if(JS_GetProperty(cx, hdr, "ftn_area", &val) && !JSVAL_NULL_OR_VOID(val)) {
695
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
696
		HANDLE_PENDING(cx, cp);
697
698
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_area\" string in header object");
699
			goto err;
700
		}
701
702
		if((smb_result = smb_hfield_str(msg, FIDOAREA, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding FIDOAREA field to message header", smb_result);
703
			goto err;
704
		}
705
706
	}

707
	if(JS_GetProperty(cx, hdr, "ftn_flags", &val) && !JSVAL_NULL_OR_VOID(val)) {
708
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
709
		HANDLE_PENDING(cx, cp);
710
711
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_flags\" string in header object");
712
			goto err;
713
		}
714
715
		if((smb_result = smb_hfield_str(msg, FIDOFLAGS, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding FIDOFLAGS field to message header", smb_result);
716
			goto err;
717
		}
718
719
	}

720
	if(JS_GetProperty(cx, hdr, "ftn_pid", &val) && !JSVAL_NULL_OR_VOID(val)) {
721
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
722
		HANDLE_PENDING(cx, cp);
723
724
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"ftn_pid\" string in header object");
725
			goto err;
726
		}
727
728
		if((smb_result = smb_hfield_str(msg, FIDOPID, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding FIDOPID field to message header", smb_result);
729
			goto err;
730
		}
731
732
	}