socsvn commit: r256191 - soc2013/dpl/head/lib/libzcap/zlibworker
dpl at FreeBSD.org
dpl at FreeBSD.org
Tue Aug 20 08:23:30 UTC 2013
Author: dpl
Date: Tue Aug 20 08:23:30 2013
New Revision: 256191
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256191
Log:
Improved commands, use global buffer. Improved error messages.
Modified:
soc2013/dpl/head/lib/libzcap/zlibworker/commands.c
soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c
Modified: soc2013/dpl/head/lib/libzcap/zlibworker/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/zlibworker/commands.c Tue Aug 20 08:22:24 2013 (r256190)
+++ soc2013/dpl/head/lib/libzcap/zlibworker/commands.c Tue Aug 20 08:23:30 2013 (r256191)
@@ -6,6 +6,9 @@
#include <string.h>
nvlist_t * args;
+extern int zero;
+extern void *data;
+
size_t gzsize = sizeof(struct gzFile_s);
size_t zstreamsize = sizeof(z_stream);
@@ -80,15 +83,7 @@
void
zcapcmd_deflateSetDictionary(nvlist_t *nvl, nvlist_t *result)
{
- uLong ret = -1;
-
- if ((args = nvlist_take_nvlist(nvl, "args")) == NULL) {
- nvlist_take_binary(args, "strm", &zstreamsize);
- ret = compressBound(
- nvlist_take_number(args, "sourceLen")
- );
- }
- nvlist_add_number(result, "result", ret );
+ ;
}
void
@@ -255,11 +250,9 @@
{
int ret = -1;
int len = 0;
- void * data = NULL;
if ((args = nvlist_take_nvlist(nvl, "args")) != NULL) {
len = nvlist_take_number(args, "len");
- data = malloc(len);
ret = gzread(
nvlist_take_binary(args, "file", &gzsize),
data,
@@ -269,6 +262,7 @@
nvlist_add_number(result, "result", ret);
nvlist_add_binary(result, "data", data, len);
+ zero = 1;
}
void
@@ -276,18 +270,18 @@
{
int ret = -1;
size_t len = 0;
- void * data;
if ((args = nvlist_take_nvlist(nvl, "args")) != NULL) {
len = nvlist_take_number(args, "len");
data = malloc(len);
memcpy(data, nvlist_take_binary(args, "data", &len), len);
- ret = gzread(
+ ret = gzwrite(
nvlist_take_binary(args, "file", &gzsize),
data, len);
}
nvlist_add_number(result, "result", ret);
+ zero = 1;
}
void
@@ -295,11 +289,9 @@
{
int ret = -1;
int len = 0;
- void * data;
if ((args = nvlist_take_nvlist(nvl, "args")) != NULL) {
len = nvlist_take_number(args, "len");
- data = malloc(len);
ret = gzprintf(
nvlist_take_binary(args, "file", &gzsize),
nvlist_take_string(args, "str")
@@ -459,19 +451,16 @@
zcapcmd_adler32(nvlist_t *nvl, nvlist_t *result)
{
uLong ret = -1;
- fprintf(stderr, "\nzcapcmd_adler32()\n");
if ((args = nvlist_take_nvlist(nvl, "args")) != NULL) {
size_t len = nvlist_take_number(args, "len");
uLong adler = nvlist_take_number(args, "adler");
void *buf = nvlist_take_binary(args, "buf", &len);
- fprintf(stderr, "zcapcmd_crc32: adler: %ld\n", adler);
- fprintf(stderr, "zcapcmd_crc32: buf: %p\n", &buf);
- fprintf(stderr, "zcapcmd_crc32: len: %d\n", len);
- fflush(stderr);
- ret = adler32(adler, buf, len);
+ memcpy(data, buf, len);
+ ret = adler32(adler, data, len);
}
nvlist_add_number(result, "result", ret );
+ zero = 1;
}
Modified: soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c Tue Aug 20 08:22:24 2013 (r256190)
+++ soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c Tue Aug 20 08:23:30 2013 (r256191)
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
#include "../commands.h"
@@ -65,7 +66,10 @@
extern void zcapcmd_crc32(nvlist_t *nvl, nvlist_t *result);
extern void zcapcmd_crc32_combine(nvlist_t *nvl, nvlist_t *result);
+/* Points to a 5kb buffer */
void * data;
+/* Zero == 1 when we need to zero out data */
+int zero = 0;
int
main()
@@ -75,22 +79,30 @@
/* Sandbox the process */
cap_enter();
- if ((data = malloc(5*1024)) == NULL) {
+ if ((data = calloc(5*1024, 1)) == NULL) {
perror("malloc");
abort();
}
- if ((result = nvlist_create(0)) == NULL)
- return(-1);
while(1) {
+ if ((result = nvlist_create(0)) == NULL) {
+ fprintf(stderr, "zlibworker: Can't create result.\n");
+ exit(1);
+ }
+
if ((nvl = nvlist_recv(3)) != NULL) {
- if (!nvlist_exists(nvl, "command"))
- continue;
- if (!nvlist_exists(nvl, "args"))
- continue;
+ if (!nvlist_exists(nvl, "command")) {
+ fprintf(stderr, "zlibworker: No command.\n");
+ exit(1);
+ }
+ if (!nvlist_exists(nvl, "args")) {
+ fprintf(stderr, "zlibworker: args doesn't exist\n");
+ exit(1);
+ }
} else {
- continue;
+ fprintf(stderr, "zlibworker: nvl is NULL\n");
+ exit(1);
}
// Switch for "command"
@@ -247,7 +259,7 @@
zcapcmd_adler32(nvl, result);
break;
case (ZCAPCMD_ADLER32_COMBINE):
- zcapcmd_compressBound(nvl, result);
+ zcapcmd_adler32_combine(nvl, result);
break;
case (ZCAPCMD_CRC32):
zcapcmd_crc32(nvl, result);
@@ -256,11 +268,19 @@
zcapcmd_crc32_combine(nvl, result);
break;
default:
+ perror("zlibworker: unknown command");
+ exit(1);
break;
}
- if( nvlist_send(3, result) != 0 )
+ if( nvlist_send(3, result) != 0 ) {
perror("zlibworker: Couldn't send response\n");
+ exit(1);
+ }
+
+ if (zero)
+ memset(data, 0, 5*1024);
}
+
return (0);
}
\ No newline at end of file
More information about the svn-soc-all
mailing list