Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Main
Synchronet
Commits
1c96d408
Commit
1c96d408
authored
May 12, 2021
by
Rob Swindell
💬
Browse files
Allow the metadata property to be set with add() and update()
Sorry for the impending imminent merge hassle Deuce!
parent
75b575f1
Pipeline
#2160
passed with stage
in 8 minutes and 31 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
5 deletions
+19
-5
src/sbbs3/js_filebase.c
src/sbbs3/js_filebase.c
+19
-5
No files found.
src/sbbs3/js_filebase.c
View file @
1c96d408
...
@@ -368,7 +368,7 @@ parse_file_index_properties(JSContext *cx, JSObject* obj, fileidxrec_t* idx)
...
@@ -368,7 +368,7 @@ parse_file_index_properties(JSContext *cx, JSObject* obj, fileidxrec_t* idx)
}
}
static
int
static
int
parse_file_properties
(
JSContext
*
cx
,
JSObject
*
obj
,
file_t
*
file
,
char
**
extdesc
)
parse_file_properties
(
JSContext
*
cx
,
JSObject
*
obj
,
file_t
*
file
,
char
**
extdesc
,
char
**
metadata
)
{
{
char
*
cp
=
NULL
;
char
*
cp
=
NULL
;
size_t
cp_sz
=
0
;
size_t
cp_sz
=
0
;
...
@@ -536,6 +536,18 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
...
@@ -536,6 +536,18 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
}
}
truncsp
(
*
extdesc
);
truncsp
(
*
extdesc
);
}
}
prop_name
=
"metadata"
;
if
(
metadata
!=
NULL
&&
JS_GetProperty
(
cx
,
obj
,
prop_name
,
&
val
)
&&
!
JSVAL_NULL_OR_VOID
(
val
))
{
FREE_AND_NULL
(
*
metadata
);
JSVALUE_TO_MSTRING
(
cx
,
val
,
*
metadata
,
NULL
);
HANDLE_PENDING
(
cx
,
*
metadata
);
if
(
*
metadata
==
NULL
)
{
free
(
cp
);
JS_ReportError
(
cx
,
"Invalid '%s' string in file object"
,
prop_name
);
return
SMB_ERR_MEM
;
}
truncsp
(
*
metadata
);
}
prop_name
=
"tags"
;
prop_name
=
"tags"
;
if
(
JS_GetProperty
(
cx
,
obj
,
prop_name
,
&
val
)
&&
!
JSVAL_NULL_OR_VOID
(
val
))
{
if
(
JS_GetProperty
(
cx
,
obj
,
prop_name
,
&
val
)
&&
!
JSVAL_NULL_OR_VOID
(
val
))
{
JSVALUE_TO_RASTRING
(
cx
,
val
,
cp
,
&
cp_sz
,
NULL
);
JSVALUE_TO_RASTRING
(
cx
,
val
,
cp
,
&
cp_sz
,
NULL
);
...
@@ -1117,6 +1129,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
...
@@ -1117,6 +1129,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
jsval
*
argv
=
JS_ARGV
(
cx
,
arglist
);
jsval
*
argv
=
JS_ARGV
(
cx
,
arglist
);
private_t
*
p
;
private_t
*
p
;
char
*
extdesc
=
NULL
;
char
*
extdesc
=
NULL
;
char
*
metadata
=
NULL
;
file_t
file
;
file_t
file
;
client_t
*
client
=
NULL
;
client_t
*
client
=
NULL
;
bool
use_diz_always
=
false
;
bool
use_diz_always
=
false
;
...
@@ -1141,7 +1154,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
...
@@ -1141,7 +1154,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
uintN
argn
=
0
;
uintN
argn
=
0
;
if
(
argn
<
argc
&&
JSVAL_IS_OBJECT
(
argv
[
argn
]))
{
if
(
argn
<
argc
&&
JSVAL_IS_OBJECT
(
argv
[
argn
]))
{
p
->
smb_result
=
parse_file_properties
(
cx
,
JSVAL_TO_OBJECT
(
argv
[
argn
]),
&
file
,
&
extdesc
);
p
->
smb_result
=
parse_file_properties
(
cx
,
JSVAL_TO_OBJECT
(
argv
[
argn
]),
&
file
,
&
extdesc
,
&
metadata
);
if
(
p
->
smb_result
!=
SMB_SUCCESS
)
if
(
p
->
smb_result
!=
SMB_SUCCESS
)
return
JS_TRUE
;
return
JS_TRUE
;
argn
++
;
argn
++
;
...
@@ -1170,7 +1183,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
...
@@ -1170,7 +1183,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
getfilepath
(
scfg
,
&
file
,
fpath
);
getfilepath
(
scfg
,
&
file
,
fpath
);
if
(
file
.
from_ip
==
NULL
)
if
(
file
.
from_ip
==
NULL
)
file_client_hfields
(
&
file
,
client
);
file_client_hfields
(
&
file
,
client
);
p
->
smb_result
=
smb_addfile
(
&
p
->
smb
,
&
file
,
SMB_SELFPACK
,
extdesc
,
/* contents: */
NULL
,
fpath
);
p
->
smb_result
=
smb_addfile
(
&
p
->
smb
,
&
file
,
SMB_SELFPACK
,
extdesc
,
metadata
,
fpath
);
JS_SET_RVAL
(
cx
,
arglist
,
BOOLEAN_TO_JSVAL
(
p
->
smb_result
==
SMB_SUCCESS
));
JS_SET_RVAL
(
cx
,
arglist
,
BOOLEAN_TO_JSVAL
(
p
->
smb_result
==
SMB_SUCCESS
));
}
}
JS_RESUMEREQUEST
(
cx
,
rc
);
JS_RESUMEREQUEST
(
cx
,
rc
);
...
@@ -1231,10 +1244,11 @@ js_update_file(JSContext *cx, uintN argc, jsval *arglist)
...
@@ -1231,10 +1244,11 @@ js_update_file(JSContext *cx, uintN argc, jsval *arglist)
JSBool
result
=
JS_TRUE
;
JSBool
result
=
JS_TRUE
;
char
*
extdesc
=
NULL
;
char
*
extdesc
=
NULL
;
char
*
metadata
=
NULL
;
rc
=
JS_SUSPENDREQUEST
(
cx
);
rc
=
JS_SUSPENDREQUEST
(
cx
);
if
(
filename
!=
NULL
&&
fileobj
!=
NULL
if
(
filename
!=
NULL
&&
fileobj
!=
NULL
&&
(
p
->
smb_result
=
smb_loadfile
(
&
p
->
smb
,
filename
,
&
file
,
file_detail_extdesc
))
==
SMB_SUCCESS
)
{
&&
(
p
->
smb_result
=
smb_loadfile
(
&
p
->
smb
,
filename
,
&
file
,
file_detail_extdesc
))
==
SMB_SUCCESS
)
{
p
->
smb_result
=
parse_file_properties
(
cx
,
fileobj
,
&
file
,
&
extdesc
);
p
->
smb_result
=
parse_file_properties
(
cx
,
fileobj
,
&
file
,
&
extdesc
,
&
metadata
);
if
((
extdesc
==
NULL
||
use_diz_always
==
true
)
if
((
extdesc
==
NULL
||
use_diz_always
==
true
)
&&
file
.
dir
<
scfg
->
total_dirs
&&
file
.
dir
<
scfg
->
total_dirs
&&
(
scfg
->
dir
[
file
.
dir
]
->
misc
&
DIR_DIZ
))
{
&&
(
scfg
->
dir
[
file
.
dir
]
->
misc
&
DIR_DIZ
))
{
...
@@ -1258,7 +1272,7 @@ js_update_file(JSContext *cx, uintN argc, jsval *arglist)
...
@@ -1258,7 +1272,7 @@ js_update_file(JSContext *cx, uintN argc, jsval *arglist)
p
->
smb_result
=
smb_putfile
(
&
p
->
smb
,
&
file
);
p
->
smb_result
=
smb_putfile
(
&
p
->
smb
,
&
file
);
else
{
else
{
if
((
p
->
smb_result
=
smb_removefile
(
&
p
->
smb
,
&
file
))
==
SMB_SUCCESS
)
{
if
((
p
->
smb_result
=
smb_removefile
(
&
p
->
smb
,
&
file
))
==
SMB_SUCCESS
)
{
p
->
smb_result
=
smb_addfile
(
&
p
->
smb
,
&
file
,
SMB_SELFPACK
,
extdesc
,
/* contents: */
NULL
,
newfname
);
p
->
smb_result
=
smb_addfile
(
&
p
->
smb
,
&
file
,
SMB_SELFPACK
,
extdesc
,
metadata
,
newfname
);
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment