js_msgbase.c 96.3 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
typedef struct
{
	private_t	*p;
	BOOL		expand_fields;
	smbmsg_t	msg;
rswindell's avatar
rswindell committed
56
	post_t		post;
57 58 59

} privatemsg_t;

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

62 63 64 65 66 67 68 69 70 71
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;
}

72 73 74 75 76
/* Destructor */

static void js_finalize_msgbase(JSContext *cx, JSObject *obj)
{
	private_t* p;
77

78 79 80 81 82 83 84 85 86 87 88 89 90
	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 */

91
static JSBool
92
js_open(JSContext *cx, uintN argc, jsval *arglist)
93
{
94
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
95
	private_t* p;
deuce's avatar
deuce committed
96
	jsrefcount	rc;
97

98
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
99
		JS_ReportError(cx,getprivate_failure,WHERE);
100
		return JS_FALSE;
101 102
	}

103
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
104

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

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

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


124
static JSBool
125
js_close(JSContext *cx, uintN argc, jsval *arglist)
126
{
127
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
128
	private_t* p;
deuce's avatar
deuce committed
129
	jsrefcount	rc;
130

131
	if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
132
		JS_ReportError(cx,getprivate_failure,WHERE);
133
		return JS_FALSE;
134
	}
135

136 137
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

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

142
	return JS_TRUE;
143 144
}

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

157
	scfg = JS_GetRuntimePrivate(JS_GetRuntime(cx));
158

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

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

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

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

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

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

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

271
	if(JS_GetProperty(cx, hdr, "to_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
272 273
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
rswindell's avatar
rswindell committed
274
		agent=(ushort)i32;
275 276 277
		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;
278
		}
rswindell's avatar
rswindell committed
279
	}
280 281

	return(TRUE);
282 283 284 285 286 287

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

288 289 290 291 292
}

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

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

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

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

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

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

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

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

390
	if(JS_GetProperty(cx, hdr, "from_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
391
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
392
		HANDLE_PENDING(cx, cp);
393 394
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_net_addr\" string in header object");
395
			goto err;
396
		}
397 398
		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);
399
			goto err;
400
		}
401
	}
402

403
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
404
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL))
405
			msg->idx.from=0;
406 407
		if((smb_result = smb_hfield_bin(msg, SENDERNETTYPE, nettype))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERNETTYPE field to message header", smb_result);
408
			goto err;
409
		}
410 411
	}

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

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

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

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

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

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

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

	if(JS_GetProperty(cx, hdr, "sender_time", &val) && !JSVAL_NULL_OR_VOID(val)) {
501
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
502
		HANDLE_PENDING(cx, cp);
503 504
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"sender_time\" string in header object");
505
			goto err;
506
		}
507 508
		if((smb_result = smb_hfield_str(msg, SENDERTIME, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERTIME field to message header", smb_result);
509
			goto err;
510 511
		}
	}
512

513
	if(JS_GetProperty(cx, hdr, "replyto", &val) && !JSVAL_NULL_OR_VOID(val)) {
514
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
515
		HANDLE_PENDING(cx, cp);
516 517
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto\" string in header object");
518
			goto err;
519
		}
520 521
		if((smb_result = smb_hfield_str(msg, REPLYTO, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTO field to message header", smb_result);
522
			goto err;
523
		}
524 525
	}

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

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

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

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

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

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

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

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

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

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