Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

js_msgbase.c 105 KB
Newer Older
1 2 3 4 5 6
/* Synchronet JavaScript "MsgBase" Object */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
7
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *																			*
 * 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										*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"
23
#include "js_request.h"
24
#include "userdat.h"
25
#include <stdbool.h>
26 27 28 29 30 31

#ifdef JAVASCRIPT

typedef struct
{
	smb_t	smb;
32
	int		smb_result;
33 34 35 36
	BOOL	debug;

} private_t;

37 38 39 40
typedef struct
{
	private_t	*p;
	BOOL		expand_fields;
41
	BOOL		enumerated;
42
	smbmsg_t	msg;
rswindell's avatar
rswindell committed
43
	post_t		post;
44 45 46

} privatemsg_t;

47 48 49 50 51
/* Destructor */

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

53 54 55 56 57 58 59 60 61 62 63 64 65
	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 */

66 67
extern JSClass js_msgbase_class;

68
static JSBool
69
js_open(JSContext *cx, uintN argc, jsval *arglist)
70
{
71
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
72
	private_t* p;
deuce's avatar
deuce committed
73
	jsrefcount	rc;
74 75 76 77 78 79 80
	scfg_t*		scfg;

	scfg = JS_GetRuntimePrivate(JS_GetRuntime(cx));
	if(scfg == NULL) {
		JS_ReportError(cx, "JS_GetRuntimePrivate returned NULL");
		return JS_FALSE;
	}
81

82
	if((p=(private_t*)js_GetClassPrivate(cx, obj, &js_msgbase_class))==NULL) {
83
		return JS_FALSE;
84 85
	}

86
	JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
87

88
	if(p->smb.subnum==INVALID_SUB
89 90 91
		&& strchr(p->smb.file,'/')==NULL
		&& strchr(p->smb.file,'\\')==NULL) {
		JS_ReportError(cx,"Unrecognized msgbase code: %s",p->smb.file);
92
		return JS_TRUE;
93 94
	}

95
	rc=JS_SUSPENDREQUEST(cx);
96
	if((p->smb_result = smb_open_sub(scfg, &(p->smb), p->smb.subnum)) != SMB_SUCCESS) {
97
		JS_RESUMEREQUEST(cx, rc);
98
		return JS_TRUE;
deuce's avatar
deuce committed
99
	}
100
	JS_RESUMEREQUEST(cx, rc);
101

102
	JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
103
	return JS_TRUE;
104 105 106
}


107
static JSBool
108
js_close(JSContext *cx, uintN argc, jsval *arglist)
109
{
110
	JSObject *obj=JS_THIS_OBJECT(cx, arglist);
111
	private_t* p;
deuce's avatar
deuce committed
112
	jsrefcount	rc;
113

114
	if((p=(private_t*)js_GetClassPrivate(cx, obj, &js_msgbase_class))==NULL) {
115
		return JS_FALSE;
116
	}
117

118 119
	JS_SET_RVAL(cx, arglist, JSVAL_VOID);

120
	rc=JS_SUSPENDREQUEST(cx);
121
	smb_close(&(p->smb));
122
	JS_RESUMEREQUEST(cx, rc);
123

124
	return JS_TRUE;
125 126
}

127
static BOOL parse_recipient_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg)
128
{
129 130
	char*		cp=NULL;
	size_t		cp_sz=0;
131
	char		to[256];
132
	ushort		nettype=NET_UNKNOWN;
133 134 135
	ushort		agent;
	int32		i32;
	jsval		val;
136
	scfg_t*		scfg;
137
	int			smb_result = SMB_SUCCESS;
138

139
	scfg = JS_GetRuntimePrivate(JS_GetRuntime(cx));
140

141
	if(JS_GetProperty(cx, hdr, "to", &val) && !JSVAL_NULL_OR_VOID(val)) {
142
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
143
		HANDLE_PENDING(cx, cp);
144 145
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to\" string in recipient object");
146
			return(FALSE);
147
		}
148
	} else {
149
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL)) {	/* e-mail */
150
			JS_ReportError(cx, "\"to\" property not included in email recipient object");
151
			return(FALSE);					/* "to" property required */
152
		}
153
		cp=strdup("All");
154
	}
deuce's avatar
deuce committed
155

156 157
	if((smb_result = smb_hfield_str(msg, RECIPIENT, cp))!=SMB_SUCCESS) {
		JS_ReportError(cx, "Error %d adding RECIPIENT field to message header", smb_result);
158
		free(cp);
159
		goto err;
160
	}
161
	if((p != NULL) && !(p->smb.status.attr&SMB_EMAIL)) {
162 163 164 165 166
		SAFECOPY(to,cp);
		strlwr(to);
		msg->idx.to=crc16(to,0);
	}

167 168 169 170 171 172 173
	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);
		}
174
		if((smb_result = smb_hfield_str(msg, RECIPIENTLIST, cp))!=SMB_SUCCESS) {
175
			free(cp);
176
			JS_ReportError(cx, "Error %d adding RECIPIENTLIST field to message header", smb_result);
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
			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;
		}
	}

195
	if(JS_GetProperty(cx, hdr, "to_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
196
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
197
		HANDLE_PENDING(cx, cp);
198 199
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_ext\" string in recipient object");
rswindell's avatar
rswindell committed
200
			return(FALSE);
201
		}
202
		if((smb_result = smb_hfield_str(msg, RECIPIENTEXT, cp))!=SMB_SUCCESS) {
203
			free(cp);
204 205
			JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header", smb_result);
			goto err;
206
		}
207
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL))
rswindell's avatar
rswindell committed
208 209 210
			msg->idx.to=atoi(cp);
	}

211
	if(JS_GetProperty(cx, hdr, "to_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
212
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
213
		HANDLE_PENDING(cx, cp);
214 215
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"to_org\" string in recipient object");
rswindell's avatar
rswindell committed
216
			return(FALSE);
217
		}
218
		if((smb_result = smb_hfield_str(msg, RECIPIENTORG, cp))!=SMB_SUCCESS) {
219
			free(cp);
220 221
			JS_ReportError(cx, "Error %d adding RECIPIENTORG field to message header", smb_result);
			goto err;
222
		}
rswindell's avatar
rswindell committed
223 224
	}

225
	if(JS_GetProperty(cx, hdr, "to_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
226 227
		if(!JS_ValueToInt32(cx,val,&i32)) {
			free(cp);
228
			return(FALSE);
229
		}
rswindell's avatar
rswindell committed
230 231 232
		nettype=(ushort)i32;
	}

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

248
	if(nettype!=NET_UNKNOWN) {
249
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL)) {
250 251 252 253
			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) {
254
					JS_ReportError(cx, "Unroutable QWKnet \"to_net_addr\" (%s) in recipient object"
255 256 257
						,msg->to_net.addr);
					return(FALSE);
				}
258
				if((smb_result = smb_hfield_str(msg, RECIPIENTNETADDR, fulladdr))!=SMB_SUCCESS) {
259
					JS_ReportError(cx, "Error %d adding RECIPIENTADDR field to message header"
260 261
						,smb_result);
					goto err;
262 263 264 265
				}
				if(msg->idx.to != 0) {
					char ext[32];
					sprintf(ext,"%u",msg->idx.to);
266
					if((smb_result = smb_hfield_str(msg, RECIPIENTEXT, ext))!=SMB_SUCCESS) {
267
						JS_ReportError(cx, "Error %d adding RECIPIENTEXT field to message header"
268 269
							,smb_result);
						goto err;
270 271 272 273 274
					}
				}
			} else
				msg->idx.to=0;
		}
275 276 277
		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;
278
		}
rswindell's avatar
rswindell committed
279 280
	}

281
	if(JS_GetProperty(cx, hdr, "to_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
282 283
		if(!JS_ValueToInt32(cx,val,&i32))
			return FALSE;
rswindell's avatar
rswindell committed
284
		agent=(ushort)i32;
285 286 287
		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;
288
		}
rswindell's avatar
rswindell committed
289
	}
290 291

	return(TRUE);
292 293 294 295 296 297

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

298 299 300 301 302
}

static BOOL parse_header_object(JSContext* cx, private_t* p, JSObject* hdr, smbmsg_t* msg
								,BOOL recipient)
{
303 304
	char*		cp=NULL;
	size_t		cp_sz=0;
305
	char		from[256];
306
	ushort		nettype=NET_UNKNOWN;
307
	ushort		type;
308 309
	ushort		agent;
	int32		i32;
310
	uint32		u32;
311
	jsval		val;
312 313 314
	JSObject*	array;
	JSObject*	field;
	jsuint		i,len;
315
	int			smb_result = SMB_SUCCESS;
316

317 318
	if(hdr==NULL) {
		JS_ReportError(cx, "NULL header object");
319
		goto err;
320
	}
321

322
	if(recipient && !parse_recipient_object(cx,p,hdr,msg))
323
		goto err;
324

325
	if(msg->hdr.type != SMB_MSG_TYPE_BALLOT) {
326 327 328
		/* Required Header Fields */
		if(JS_GetProperty(cx, hdr, "subject", &val) && !JSVAL_NULL_OR_VOID(val)) {
			JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
329
			HANDLE_PENDING(cx, cp);
330 331 332 333 334 335 336
			if(cp==NULL) {
				JS_ReportError(cx, "Invalid \"subject\" string in header object");
				goto err;
			}
		} else
			cp=strdup("");

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

	/* Optional Header Fields */
365
	if(JS_GetProperty(cx, hdr, "from_ext", &val) && !JSVAL_NULL_OR_VOID(val)) {
366
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
367
		HANDLE_PENDING(cx, cp);
368 369
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_ext\" string in header object");
370
			goto err;
371
		}
372 373
		if((smb_result = smb_hfield_str(msg, SENDEREXT, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDEREXT field to message header", smb_result);
374
			goto err;
375
		}
376
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL))
377 378 379
			msg->idx.from=atoi(cp);
	}

380
	if(JS_GetProperty(cx, hdr, "from_org", &val) && !JSVAL_NULL_OR_VOID(val)) {
381
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
382
		HANDLE_PENDING(cx, cp);
383 384
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_org\" string in header object");
385
			goto err;
386
		}
387 388
		if((smb_result = smb_hfield_str(msg, SENDERORG, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERORG field to message header", smb_result);
389
			goto err;
390
		}
391 392
	}

393
	if(JS_GetProperty(cx, hdr, "from_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
394 395 396
		if(!JS_ValueToInt32(cx,val,&i32)) {
			goto err;
		}
397
		nettype=(ushort)i32;
398 399
	}

400
	if(JS_GetProperty(cx, hdr, "from_net_addr", &val) && !JSVAL_NULL_OR_VOID(val)) {
401
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
402
		HANDLE_PENDING(cx, cp);
403 404
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"from_net_addr\" string in header object");
405
			goto err;
406
		}
407 408
		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);
409
			goto err;
410
		}
411
	}
412

413
	if(nettype!=NET_UNKNOWN) {
414
		if((p != NULL) && (p->smb.status.attr&SMB_EMAIL))
415
			msg->idx.from=0;
416 417
		if((smb_result = smb_hfield_bin(msg, SENDERNETTYPE, nettype))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERNETTYPE field to message header", smb_result);
418
			goto err;
419
		}
420 421
	}

422
	if(JS_GetProperty(cx, hdr, "from_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
423
		if(!JS_ValueToInt32(cx,val,&i32))
424
			goto err;
425
		agent=(ushort)i32;
426 427
		if((smb_result = smb_hfield_bin(msg, SENDERAGENT, agent))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding SENDERAGENT field to message header", smb_result);
428
			goto err;
429
		}
430 431
	}

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

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

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

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

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

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

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

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

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

549
	if(JS_GetProperty(cx, hdr, "replyto_org", &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_org\" string in header object");
554
			goto err;
555
		}
556 557
		if((smb_result = smb_hfield_str(msg, REPLYTOORG, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOORG field to message header", smb_result);
558
			goto err;
559
		}
560 561
	}

562
	nettype=NET_UNKNOWN;
563
	if(JS_GetProperty(cx, hdr, "replyto_net_type", &val) && !JSVAL_NULL_OR_VOID(val)) {
564
		if(!JS_ValueToInt32(cx,val,&i32))
565
			goto err;
566
		nettype=(ushort)i32;
567
	}
568
	if(JS_GetProperty(cx, hdr, "replyto_net_addr", &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_net_addr\" string in header object");
573
			goto err;
574
		}
575 576
		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);
577
			goto err;
578
		}
579
	}
580
	if(nettype!=NET_UNKNOWN) {
581 582
		if((smb_result = smb_hfield_bin(msg, REPLYTONETTYPE, nettype))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTONETTYPE field to message header", smb_result);
583
			goto err;
584
		}
585 586
	}

587
	if(JS_GetProperty(cx, hdr, "replyto_agent", &val) && !JSVAL_NULL_OR_VOID(val)) {
588
		if(!JS_ValueToInt32(cx,val,&i32))
589
			goto err;
590
		agent=(ushort)i32;
591 592
		if((smb_result = smb_hfield_bin(msg, REPLYTOAGENT, agent))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOAGENT field to message header", smb_result);
593
			goto err;
594
		}
595 596
	}

597
	/* RFC822 headers */
598 599 600 601 602 603 604
	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;
		}
605 606
		if((smb_result = smb_hfield_str(msg, REPLYTOLIST, cp))!=SMB_SUCCESS) {
			JS_ReportError(cx, "Error %d adding REPLYTOLIST field to message header", smb_result);
607 608 609 610
			goto err;
		}
	}

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

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

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

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

664
	/* USENET headers */
665
	if(JS_GetProperty(cx, hdr, "path", &val) && !JSVAL_NULL_OR_VOID(val)) {
666
		JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
667
		HANDLE_PENDING(cx, cp);
668 669
		if(cp==NULL) {
			JS_ReportError(cx, "Invalid \"path\" string in header object");
670
			goto err;
671
		}