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

Commit c59960a2 authored by deuce's avatar deuce
Browse files

Remove *_TO_STRING() macros.

parent 59ecd955
......@@ -323,7 +323,7 @@ static ushort js_port(JSContext* cx, jsval val, int type)
}
if(JSVAL_IS_STRING(val)) {
str = JS_ValueToString(cx,val);
JSSTRING_TO_STRING(cx, str, cp, NULL);
JSSTRING_TO_ASTRING(cx, str, cp, 16, NULL);
if(isdigit(*cp))
return((ushort)strtol(cp,NULL,0));
rc=JS_SUSPENDREQUEST(cx);
......@@ -390,7 +390,7 @@ js_bind(JSContext *cx, uintN argc, jsval *arglist)
port = js_port(cx,argv[0],p->type);
addr.sin_port = htons(port);
if(argc > 1)
JSVALUE_TO_STRING(cx, argv[1], cstr, NULL);
JSVALUE_TO_ASTRING(cx, argv[1], cstr, 16, NULL);
if(argc>1 && cstr != NULL
&& (ip=inet_addr(cstr))!=INADDR_NONE)
addr.sin_addr.s_addr = ip;
......@@ -510,7 +510,6 @@ js_connect(JSContext *cx, uintN argc, jsval *arglist)
fd_set socket_set;
struct timeval tv = {0, 0};
jsrefcount rc;
char* cstr;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
......@@ -518,13 +517,12 @@ js_connect(JSContext *cx, uintN argc, jsval *arglist)
}
str = JS_ValueToString(cx, argv[0]);
JSSTRING_TO_STRING(cx, str, cstr, NULL);
rc=JS_SUSPENDREQUEST(cx);
if(p->hostname)
free(p->hostname);
p->hostname=strdup(cstr);
dbprintf(FALSE, p, "resolving hostname: %s", cstr);
if((ip_addr=resolve_ip(cstr))==INADDR_NONE) {
JSSTRING_TO_MSTRING(cx, str, p->hostname, NULL);
rc=JS_SUSPENDREQUEST(cx);
dbprintf(FALSE, p, "resolving hostname: %s", p->hostname);
if((ip_addr=resolve_ip(p->hostname))==INADDR_NONE) {
p->last_error=ERROR_VALUE;
dbprintf(TRUE, p, "resolve_ip failed with error %d",ERROR_VALUE);
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
......@@ -541,7 +539,7 @@ js_connect(JSContext *cx, uintN argc, jsval *arglist)
js_timeval(cx,argv[2],&tv);
rc=JS_SUSPENDREQUEST(cx);
dbprintf(FALSE, p, "connecting to port %u at %s", port, cstr);
dbprintf(FALSE, p, "connecting to port %u at %s", port, p->hostname);
memset(&(p->remote_addr),0,sizeof(p->remote_addr));
p->remote_addr.sin_addr.s_addr = ip_addr;
......@@ -575,7 +573,7 @@ js_connect(JSContext *cx, uintN argc, jsval *arglist)
p->is_connected = TRUE;
JS_SET_RVAL(cx, arglist, JSVAL_TRUE);
dbprintf(FALSE, p, "connected to port %u at %s", port, cstr);
dbprintf(FALSE, p, "connected to port %u at %s", port, p->hostname);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -587,7 +585,7 @@ js_send(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* cp;
int len;
size_t len;
JSString* str;
private_t* p;
jsrefcount rc;
......@@ -602,8 +600,10 @@ js_send(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
str = JS_ValueToString(cx, argv[0]);
JSSTRING_TO_STRING(cx, str, cp, NULL);
len = JS_GetStringLength(str);
JSSTRING_TO_MSTRING(cx, str, cp, &len);
HANDLE_PENDING(cx);
if(cp==NULL)
return JS_TRUE;
rc=JS_SUSPENDREQUEST(cx);
if(js_socket_sendsocket(p,cp,len,TRUE)==len) {
......@@ -613,6 +613,7 @@ js_send(JSContext *cx, uintN argc, jsval *arglist)
p->last_error=ERROR_VALUE;
dbprintf(TRUE, p, "send of %u bytes failed",len);
}
free(cp);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -624,7 +625,7 @@ js_sendto(JSContext *cx, uintN argc, jsval *arglist)
JSObject *obj=JS_THIS_OBJECT(cx, arglist);
jsval *argv=JS_ARGV(cx, arglist);
char* cp;
int len;
size_t len;
ulong ip_addr;
ushort port;
JSString* data_str;
......@@ -632,7 +633,6 @@ js_sendto(JSContext *cx, uintN argc, jsval *arglist)
private_t* p;
SOCKADDR_IN addr;
jsrefcount rc;
char* cstr;
JS_SET_RVAL(cx, arglist, JSVAL_VOID);
......@@ -645,21 +645,31 @@ js_sendto(JSContext *cx, uintN argc, jsval *arglist)
/* data */
data_str = JS_ValueToString(cx, argv[0]);
JSSTRING_TO_STRING(cx, data_str, cp, NULL);
len = JS_GetStringLength(data_str);
JSSTRING_TO_MSTRING(cx, data_str, cp, &len);
HANDLE_PENDING(cx);
if(cp==NULL)
return JS_TRUE;
/* address */
ip_str = JS_ValueToString(cx, argv[1]);
JSSTRING_TO_STRING(cx, ip_str, cstr, NULL);
rc=JS_SUSPENDREQUEST(cx);
if(p->hostname)
free(p->hostname);
p->hostname=strdup(cstr);
dbprintf(FALSE, p, "resolving hostname: %s", cstr);
if((ip_addr=resolve_ip(cstr))==INADDR_NONE) {
JSSTRING_TO_MSTRING(cx, ip_str, p->hostname, NULL);
if(JS_IsExceptionPending(cx)) {
free(cp);
return JS_FALSE;
}
if(p->hostname==NULL) {
free(cp);
return JS_TRUE;
}
rc=JS_SUSPENDREQUEST(cx);
dbprintf(FALSE, p, "resolving hostname: %s", p->hostname);
if((ip_addr=resolve_ip(p->hostname))==INADDR_NONE) {
p->last_error=ERROR_VALUE;
dbprintf(TRUE, p, "resolve_ip failed with error %d",ERROR_VALUE);
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
free(cp);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -670,7 +680,7 @@ js_sendto(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
dbprintf(FALSE, p, "sending %d bytes to port %u at %s"
,len, port, cstr);
,len, port, p->hostname);
memset(&addr,0,sizeof(addr));
addr.sin_addr.s_addr = ip_addr;
......@@ -684,6 +694,7 @@ js_sendto(JSContext *cx, uintN argc, jsval *arglist)
p->last_error=ERROR_VALUE;
dbprintf(TRUE, p, "send of %u bytes failed",len);
}
free(cp);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -710,7 +721,8 @@ js_sendfile(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist, JSVAL_FALSE);
JSVALUE_TO_STRING(cx, argv[0], fname, NULL);
JSVALUE_TO_MSTRING(cx, argv[0], fname, NULL);
HANDLE_PENDING(cx);
if(fname==NULL) {
JS_ReportError(cx,"Failure reading filename");
return(JS_FALSE);
......@@ -718,9 +730,11 @@ js_sendfile(JSContext *cx, uintN argc, jsval *arglist)
rc=JS_SUSPENDREQUEST(cx);
if((file=nopen(fname,O_RDONLY|O_BINARY))==-1) {
free(fname);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
free(fname);
len = js_socket_sendfilesocket(p, file, NULL, 0);
close(file);
......@@ -1240,7 +1254,7 @@ js_getsockopt(JSContext *cx, uintN argc, jsval *arglist)
}
rc=JS_SUSPENDREQUEST(cx);
JSVALUE_TO_STRING(cx, argv[0], cstr, NULL);
JSVALUE_TO_ASTRING(cx, argv[0], cstr, 64, NULL);
if((opt = getSocketOptionByName(cstr, &level)) == -1) {
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......@@ -1291,7 +1305,7 @@ js_setsockopt(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
}
JSVALUE_TO_STRING(cx, argv[0], optname, NULL);
JSVALUE_TO_ASTRING(cx, argv[0], optname, 64, NULL);
rc=JS_SUSPENDREQUEST(cx);
opt = getSocketOptionByName(optname,&level);
if(argv[1]!=JSVAL_VOID) {
......@@ -1792,16 +1806,22 @@ static jsSyncMethodSpec js_socket_functions[] = {
static JSBool js_socket_resolve(JSContext *cx, JSObject *obj, jsid id)
{
char* name=NULL;
JSBool ret;
if(id != JSID_VOID && id != JSID_EMPTY) {
jsval idval;
JS_IdToValue(cx, id, &idval);
if(JSVAL_IS_STRING(idval))
JSSTRING_TO_STRING(cx, JSVAL_TO_STRING(idval), name, NULL);
if(JSVAL_IS_STRING(idval)) {
JSSTRING_TO_MSTRING(cx, JSVAL_TO_STRING(idval), name, NULL);
HANDLE_PENDING(cx);
}
}
return(js_SyncResolve(cx, obj, name, js_socket_properties, js_socket_functions, NULL, 0));
ret=js_SyncResolve(cx, obj, name, js_socket_properties, js_socket_functions, NULL, 0);
if(name)
free(name);
return ret;
}
static JSBool js_socket_enumerate(JSContext *cx, JSObject *obj)
......@@ -1867,20 +1887,28 @@ js_socket_constructor(JSContext *cx, uintN argc, jsval *arglist)
for(i=0;i<argc;i++) {
if(JSVAL_IS_NUMBER(argv[i]))
JS_ValueToInt32(cx,argv[i],&type);
else if(protocol==NULL)
JSVALUE_TO_STRING(cx, argv[i], protocol, NULL);
else if(protocol==NULL) {
JSVALUE_TO_MSTRING(cx, argv[i], protocol, NULL);
HANDLE_PENDING(cx);
}
}
if((p=(private_t*)malloc(sizeof(private_t)))==NULL) {
JS_ReportError(cx,"malloc failed");
if(protocol)
free(protocol);
return(JS_FALSE);
}
memset(p,0,sizeof(private_t));
if((p->sock=open_socket(type,protocol))==INVALID_SOCKET) {
JS_ReportError(cx,"open_socket failed with error %d",ERROR_VALUE);
if(protocol)
free(protocol);
return(JS_FALSE);
}
if(protocol)
free(protocol);
p->type = type;
p->network_byte_order = TRUE;
p->session=-1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment