js_msgbase.c 102 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
#include <stdbool.h>
41 42 43 44 45 46

#ifdef JAVASCRIPT

typedef struct
{
	smb_t	smb;
47
	int		smb_result;
48 49 50 51
	BOOL	debug;

} private_t;

52 53 54 55 56
typedef struct
{
	private_t	*p;
	BOOL		expand_fields;
	smbmsg_t	msg;
rswindell's avatar
rswindell committed
57
	post_t		post;
58 59 60

} privatemsg_t;

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

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

73 74 75 76 77
/* Destructor */

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

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

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

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

104
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
105

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

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

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


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

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

137 138
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

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

143
	return JS_TRUE;
144 145
}

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

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

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

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

186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
	if(JS_GetProperty(cx, hdr, "to_list", &val) && !JSVAL_NULL_OR_VOID(val)) {
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx, cp);
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_list\" string in recipient object");
			return(FALSE);
		}
		if((smb_result = smb_hfield_str(msg, RFC822TO, cp))!=SMB_SUCCESS) {
			free(cp);
			JS_ReportError(cx, "Error %d adding RFC822TO field to message header", smb_result);
			goto err;
		}
	}

	if(JS_GetProperty(cx, hdr, "cc_list", &val) && !JSVAL_NULL_OR_VOID(val)) {
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
		HANDLE_PENDING(cx, cp);
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"cc_list\" string in recipient object");
			return(FALSE);
		}
		if((smb_result = smb_hfield_str(msg, SMB_CARBONCOPY, cp))!=SMB_SUCCESS) {
			free(cp);
			JS_ReportError(cx, "Error %d adding SMB_CARBONCOPY field to message header", smb_result);
			goto err;
		}
	}

214
	if(JS_GetProperty(cx, hdr, "to_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
215
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
216
		HANDLE_PENDING(cx, cp);
217 218
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_ext\" string in recipient object");
rswindell's avatar
rswindell committed
219
			return(FALSE);
220
		}
221
		if((smb_result = smb_hfield_str(msg, RECIPIENTEXT, cp))!=SMB_SUCCESS) {
222
			free(cp);
223 224
			JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header", smb_result);
			goto err;
225
		}
226
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL))
rswindell's avatar
rswindell committed
227 228 229
			msg->idx.to=atoi(cp);
	}

230
	if(JS_GetProperty(cx, hdr, "to_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
231
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
232
		HANDLE_PENDING(cx, cp);
233 234
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_org\" string in recipient object");
rswindell's avatar
rswindell committed
235
			return(FALSE);
236
		}
237
		if((smb_result = smb_hfield_str(msg, RECIPIENTORG, cp))!=SMB_SUCCESS) {
238
			free(cp);
239 240
			JS_ReportError(cx, "Error %d adding RECIPIENTORG field to message header", smb_result);
			goto err;
241
		}
rswindell's avatar
rswindell committed
242 243
	}

244
	if(JS_GetProperty(cx, hdr, "to_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
245 246
		if(!JS_ValueToInt32(cx,val,&i32)) {
			free(cp);
247
			return(FALSE);
248
		}
rswindell's avatar
rswindell committed
249 250 251
		nettype=(ushort)i32;
	}

252
	if(JS_GetProperty(cx, hdr, "to_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
253
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
254
		HANDLE_PENDING(cx, cp);
255 256
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_net_addr\" string in recipient object");
rswindell's avatar
rswindell committed
257
			return(FALSE);
258
		}
259
		if((smb_result = smb_hfield_netaddr(msg, RECIPIENTNETADDR, cp, &nettype))!=SMB_SUCCESS) {
260
			free(cp);
261 262
			JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header", smb_result);
			goto err;
263
		}
264
	}
265
	free(cp);
266 267

	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
268
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL)) {
269 270 271 272 273 274 275 276
			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);
				}
277
				if((smb_result = smb_hfield_str(msg, RECIPIENTNETADDR, fulladdr))!=SMB_SUCCESS) {
278
					JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header"
279 280
						,smb_result);
					goto err;
281 282 283 284
				}
				if(msg->idx.to != 0) {
					char ext[32];
					sprintf(ext,"%u",msg->idx.to);
285
					if((smb_result = smb_hfield_str(msg, RECIPIENTEXT, ext))!=SMB_SUCCESS) {
286
						JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header"
287 288
							,smb_result);
						goto err;
289 290 291 292 293
					}
				}
			} else
				msg->idx.to=0;
		}
294 295 296
		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;
297
		}
rswindell's avatar
rswindell committed
298 299
	}

300
	if(JS_GetProperty(cx, hdr, "to_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
301 302
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
rswindell's avatar
rswindell committed
303
		agent=(ushort)i32;
304 305 306
		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;
307
		}
rswindell's avatar
rswindell committed
308
	}
309 310

	return(TRUE);
311 312 313 314 315 316

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

317 318 319 320 321
}

static BOOL parse_header_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg
								,BOOL recipient)
{
322 323
	char*		cp=NULL;
	size_t		cp_sz=0;
324
	char		from[256];
325
	ushort		nettype=NET_UNKNOWN;
326
	ushort		type;
327 328
	ushort		agent;
	int32		i32;
329
	uint32		u32;
330
	jsval		val;
331 332 333
	JSObject*	array;
	JSObject*	field;
	jsuint		i,len;
334
	int			smb_result = SMB_SUCCESS;
335

336 337
	if(hdr==NULL) {
		JS_ReportError(cx, "NULL header object");
338
		goto err;
339
	}
340

341
	if(recipient && !parse_recipient_object(cx,p,hdr,msg))
342
		goto err;
343

344
	if(msg->hdr.type != SMB_MSG_TYPE_BALLOT) {
345 346 347
		/* Required Header Fields */
		if(JS_GetProperty(cx, hdr, "subject", &val) && !JSVAL_NULL_OR_VOID(val)) {
			JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
348
			HANDLE_PENDING(cx, cp);
349 350 351 352 353 354 355
			if(cp==NULL) {
				JS_ReportError(cx, "Invalid \"subject\" string in header object");
				goto err;
			}
		} else
			cp=strdup("");

356 357
		if((smb_result = smb_hfield_str(msg, SUBJECT, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SUBJECT field to message header", smb_result);
358
			goto err;
359
		}
360
		msg->idx.subj=smb_subject_crc(cp);
361
	}
362
	if(JS_GetProperty(cx, hdr, "from", &val) && !JSVAL_NULL_OR_VOID(val)) {
363
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
364
		HANDLE_PENDING(cx, cp);
365 366
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from\" string in header object");
367
			goto err;
368 369 370
		}
	} else {
		JS_ReportError(cx, "\"from\" property required in header");
371
		goto err;	/* "from" property required */
372
	}
373 374
	if((smb_result = smb_hfield_str(msg, SENDER, cp))!=SMB_SUCCESS) {
		JS_ReportError(cx, "Error %d adding SENDER field to message header", smb_result);
375
		goto err;
376
	}
377
	if((p != NULL) && !(p->smb.status.attr&SMB_EMAIL) && msg->hdr.type != SMB_MSG_TYPE_BALLOT) {
378 379
		SAFECOPY(from,cp);
		strlwr(from);
380
		msg->idx.from=crc16(from,0);
381
	}
382 383

	/* Optional Header Fields */
384
	if(JS_GetProperty(cx, hdr, "from_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
385
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
386
		HANDLE_PENDING(cx, cp);
387 388
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ext\" string in header object");
389
			goto err;
390
		}
391 392
		if((smb_result = smb_hfield_str(msg, SENDEREXT, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDEREXT field to message header", smb_result);
393
			goto err;
394
		}
395
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL))
396 397 398
			msg->idx.from=atoi(cp);
	}

399
	if(JS_GetProperty(cx, hdr, "from_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
400
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
401
		HANDLE_PENDING(cx, cp);
402 403
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_org\" string in header object");
404
			goto err;
405
		}
406 407
		if((smb_result = smb_hfield_str(msg, SENDERORG, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERORG field to message header", smb_result);
408
			goto err;
409
		}
410 411
	}

412
	if(JS_GetProperty(cx, hdr, "from_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
413 414 415
		if(!JS_ValueToInt32(cx,val,&i32)) {
			goto err;
		}
416
		nettype=(ushort)i32;
417 418
	}

419
	if(JS_GetProperty(cx, hdr, "from_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
420
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
421
		HANDLE_PENDING(cx, cp);
422 423
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_net_addr\" string in header object");
424
			goto err;
425
		}
426 427
		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);
428
			goto err;
429
		}
430
	}
431

432
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
433
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL))
434
			msg->idx.from=0;
435 436
		if((smb_result = smb_hfield_bin(msg, SENDERNETTYPE, nettype))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERNETTYPE field to message header", smb_result);
437
			goto err;
438
		}
439 440
	}

441
	if(JS_GetProperty(cx, hdr, "from_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
442
		if(!JS_ValueToInt32(cx,val,&i32))
443
			goto err;
444
		agent=(ushort)i32;
445 446
		if((smb_result = smb_hfield_bin(msg, SENDERAGENT, agent))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERAGENT field to message header", smb_result);
447
			goto err;
448
		}
449 450
	}

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

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

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

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

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

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

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

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

555
	if(JS_GetProperty(cx, hdr, "replyto_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
556
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
557
		HANDLE_PENDING(cx, cp);
558 559
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_ext\" string in header object");
560
			goto err;
561
		}
562 563
		if((smb_result = smb_hfield_str(msg, REPLYTOEXT, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOEXT field to message header", smb_result);
564
			goto err;
565
		}
566 567
	}

568
	if(JS_GetProperty(cx, hdr, "replyto_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
569
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
570
		HANDLE_PENDING(cx, cp);
571 572
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"replyto_org\" string in header object");
573
			goto err;
574
		}
575 576
		if((smb_result = smb_hfield_str(msg, REPLYTOORG, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOORG field to message header", smb_result);
577
			goto err;
578
		}
579 580
	}

581
	nettype=NET_UNKNOWN;
582
	if(JS_GetProperty(cx, hdr, "replyto_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
583
		if(!JS_ValueToInt32(cx,val,&i32))
584
			goto err;
585
		nettype=(ushort)i32;
586
	}
587
	if(JS_GetProperty(cx, hdr, "replyto_net_addr", &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 \"replyto_net_addr\" string in header object");
592
			goto err;
593
		}
594 595
		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);
596
			goto err;
597
		}
598 599
	}
	if(nettype!=NET_UNKNOWN && nettype!=NET_NONE) {
600 601
		if((smb_result = smb_hfield_bin(msg, REPLYTONETTYPE, nettype))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTONETTYPE field to message header", smb_result);
602
			goto err;
603
		}
604 605
	}

606
	if(JS_GetProperty(cx, hdr, "replyto_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
607
		if(!JS_ValueToInt32(cx,val,&i32))
608
			goto err;
609
		agent=(ushort)i32;
610 611
		if((smb_result = smb_hfield_bin(msg, REPLYTOAGENT, agent))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOAGENT field to message header", smb_result);
612
			goto err;
613
		}
614 615
	}

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

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

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

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

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

683
	/* USENET headers */
684
	if(JS_GetProperty(cx, hdr, "path", &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 \"path\" string in header object");
689
			goto err;
690
		}
691 692
		if((smb_result = smb_hfield_str(msg, USENETPATH, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding USENETPATH field to message header", smb_result);