Http data server Fixed binary data retrieval
This commit is contained in:
parent
90474d1523
commit
7452813da7
7 changed files with 28 additions and 13 deletions
|
|
@ -288,7 +288,7 @@ api_http_data_file(clicon_handle h,
|
|||
char *suffix;
|
||||
char *media;
|
||||
int ret;
|
||||
char *str = NULL;
|
||||
char *buf = NULL;
|
||||
size_t sz;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
|
|
@ -347,11 +347,11 @@ api_http_data_file(clicon_handle h,
|
|||
/* Unoptimized, no direct read but requires an extra copy,
|
||||
* the cligen buf API should have some mechanism for this case without the extra copy.
|
||||
*/
|
||||
if ((str = malloc(fsize + 1)) == NULL){
|
||||
if ((buf = malloc(fsize)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "malloc");
|
||||
goto done;
|
||||
}
|
||||
if ((sz = fread(str, fsize, 1, f)) < 0){
|
||||
if ((sz = fread(buf, fsize, 1, f)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "fread");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -361,8 +361,7 @@ api_http_data_file(clicon_handle h,
|
|||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
str[fsize] = 0;
|
||||
if (cbuf_append_str(cbdata, str) < 0){
|
||||
if (cbuf_append_buf(cbdata, buf, fsize) < 0){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_append_str");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -375,8 +374,8 @@ api_http_data_file(clicon_handle h,
|
|||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
if (str)
|
||||
free(str);
|
||||
if (buf)
|
||||
free(buf);
|
||||
if (f)
|
||||
fclose(f);
|
||||
if (cbfile)
|
||||
|
|
|
|||
|
|
@ -145,7 +145,6 @@ restconf_reply_send(void *req0,
|
|||
sd->sd_code = code;
|
||||
if (cb != NULL){
|
||||
if (cbuf_len(cb)){
|
||||
cprintf(cb, "\r\n");
|
||||
sd->sd_body_len = cbuf_len(cb);
|
||||
if (head){
|
||||
cbuf_free(cb);
|
||||
|
|
|
|||
|
|
@ -329,7 +329,10 @@ restconf_http1_reply(restconf_conn *rc,
|
|||
cprintf(sd->sd_outp_buf, "\r\n");
|
||||
/* Write a body */
|
||||
if (sd->sd_body){
|
||||
cbuf_append_str(sd->sd_outp_buf, cbuf_get(sd->sd_body));
|
||||
if (cbuf_append_buf(sd->sd_outp_buf, cbuf_get(sd->sd_body), cbuf_len(sd->sd_body)) < 0){
|
||||
clicon_err(OE_RESTCONF, errno, "cbuf_append_buf");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue