Skip to content
Snippets Groups Projects
Commit e719d289 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Include all properties in getter when detail is MAX

Adds from/tags/desc/extdesc properties, even when absent or blank.

When parsing a file object, set the from, desc, tags and cost properties only if they already have been set or the new values is non-blank/0.
parent 112526fe
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #1866 passed
......@@ -180,7 +180,7 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de
|| !JS_DefineProperty(cx, obj, "name", STRING_TO_JSVAL(js_str), NULL, NULL, flags))
return false;
if(f->from != NULL
if(f->from != NULL || detail > file_detail_extdesc
&& ((js_str = JS_NewStringCopyZ(cx, f->from)) == NULL
|| !JS_DefineProperty(cx, obj, "from", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
......@@ -190,12 +190,17 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de
&& !JS_DefineProperty(cx, obj, "anon", val, NULL, NULL, flags))
return false;
if(f->desc != NULL
if(f->tags != NULL || detail > file_detail_extdesc
&& ((js_str = JS_NewStringCopyZ(cx, f->tags)) == NULL
|| !JS_DefineProperty(cx, obj, "tags", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(f->desc != NULL || detail > file_detail_extdesc
&& ((js_str = JS_NewStringCopyZ(cx, f->desc)) == NULL
|| !JS_DefineProperty(cx, obj, "desc", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(f->extdesc != NULL && *f->extdesc != '\0'
if((f->extdesc != NULL && *f->extdesc != '\0') || detail > file_detail_extdesc
&& ((js_str = JS_NewStringCopyZ(cx, f->extdesc)) == NULL
|| !JS_DefineProperty(cx, obj, "extdesc", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
......@@ -249,10 +254,6 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de
|| !JS_DefineProperty(cx, obj, "sha1", STRING_TO_JSVAL(js_str), NULL, NULL, flags))
return false;
}
if(f->tags != NULL
&& ((js_str = JS_NewStringCopyZ(cx, f->tags)) == NULL
|| !JS_DefineProperty(cx, obj, "tags", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
return true;
}
......@@ -356,7 +357,7 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
JS_ReportError(cx, "Invalid '%s' string in file object", prop_name);
return SMB_FAILURE;
}
if((result = smb_new_hfield_str(file, SMB_FILEUPLOADER, cp)) != SMB_SUCCESS) {
if((file->from != NULL || *cp != '\0') && (result = smb_new_hfield_str(file, SMB_FILEUPLOADER, cp)) != SMB_SUCCESS) {
free(cp);
JS_ReportError(cx, "Error %d adding '%s' property to file object", result, prop_name);
return result;
......@@ -371,7 +372,7 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
JS_ReportError(cx, "Invalid '%s' string in file object", prop_name);
return SMB_FAILURE;
}
if((result = smb_new_hfield_str(file, SMB_FILEDESC, cp)) != SMB_SUCCESS) {
if((file->desc != NULL || *cp != '\0') && (result = smb_new_hfield_str(file, SMB_FILEDESC, cp)) != SMB_SUCCESS) {
free(cp);
JS_ReportError(cx, "Error %d adding '%s' property to file object", result, prop_name);
return result;
......@@ -397,7 +398,7 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
JS_ReportError(cx, "Invalid '%s' string in file object", prop_name);
return SMB_FAILURE;
}
if((result = smb_new_hfield_str(file, SMB_TAGS, cp)) != SMB_SUCCESS) {
if((file->tags != NULL || *cp != '\0') && (result = smb_new_hfield_str(file, SMB_TAGS, cp)) != SMB_SUCCESS) {
free(cp);
JS_ReportError(cx, "Error %d adding '%s' property to file object", result, prop_name);
return result;
......@@ -411,7 +412,7 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
JS_ReportError(cx, "Error converting adding '%s' property to Uint32", prop_name);
return SMB_FAILURE;
}
if((result = smb_new_hfield(file, SMB_COST, sizeof(cost), &cost)) != SMB_SUCCESS) {
if((file->cost != 0 || cost != 0) && (result = smb_new_hfield(file, SMB_COST, sizeof(cost), &cost)) != SMB_SUCCESS) {
free(cp);
JS_ReportError(cx, "Error %d adding '%s' property to file object", result, prop_name);
return result;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment