mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-23 20:15:41 -04:00
Fix indent style. :)
This commit is contained in:
parent
58b7043acd
commit
cfe3c7675a
238
src/daap-proto.c
238
src/daap-proto.c
@ -40,93 +40,93 @@ DAAP_BLOCK *daap_add_formatted(DAAP_BLOCK *parent, char *tag,
|
|||||||
|
|
||||||
|
|
||||||
GZIP_STREAM *gzip_alloc(void) {
|
GZIP_STREAM *gzip_alloc(void) {
|
||||||
GZIP_STREAM *gz = malloc(sizeof(GZIP_STREAM));
|
GZIP_STREAM *gz = malloc(sizeof(GZIP_STREAM));
|
||||||
gz->in_size = GZIP_CHUNK;
|
gz->in_size = GZIP_CHUNK;
|
||||||
gz->in = malloc(gz->in_size);
|
gz->in = malloc(gz->in_size);
|
||||||
gz->bytes_in = 0;
|
gz->bytes_in = 0;
|
||||||
gz->out = NULL;
|
gz->out = NULL;
|
||||||
gz->bytes_out = 0;
|
gz->bytes_out = 0;
|
||||||
return gz;
|
return gz;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t gzip_write(GZIP_STREAM *gz, void *buf, size_t size) {
|
ssize_t gzip_write(GZIP_STREAM *gz, void *buf, size_t size) {
|
||||||
int next_size;
|
int next_size;
|
||||||
char *in2;
|
char *in2;
|
||||||
int new_size;
|
int new_size;
|
||||||
|
|
||||||
if (gz->in == NULL)
|
if (gz->in == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* make sure input buffer is big enough */
|
/* make sure input buffer is big enough */
|
||||||
while (gz->in_size <= gz->bytes_in + size) {
|
while (gz->in_size <= gz->bytes_in + size) {
|
||||||
new_size = 2*gz->in_size;
|
new_size = 2*gz->in_size;
|
||||||
in2 = malloc(new_size);
|
in2 = malloc(new_size);
|
||||||
if (in2 == NULL) {
|
if (in2 == NULL) {
|
||||||
DPRINTF(E_LOG,L_WS|L_DAAP,"out of memory for input buffer\n");
|
DPRINTF(E_LOG,L_WS|L_DAAP,"out of memory for input buffer\n");
|
||||||
free(gz->in);
|
free(gz->in);
|
||||||
gz->in = NULL;
|
gz->in = NULL;
|
||||||
gz->bytes_in = gz->in_size = 0;
|
gz->bytes_in = gz->in_size = 0;
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy(in2, gz->in, gz->in_size);
|
||||||
|
free(gz->in);
|
||||||
|
gz->in = in2;
|
||||||
|
gz->in_size = new_size;
|
||||||
}
|
}
|
||||||
memcpy(in2, gz->in, gz->in_size);
|
memcpy(gz->in + gz->bytes_in, buf, size);
|
||||||
free(gz->in);
|
gz->bytes_in += size;
|
||||||
gz->in = in2;
|
return size;
|
||||||
gz->in_size = new_size;
|
|
||||||
}
|
|
||||||
memcpy(gz->in + gz->bytes_in, buf, size);
|
|
||||||
gz->bytes_in += size;
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int gzip_compress(GZIP_STREAM *gz) {
|
int gzip_compress(GZIP_STREAM *gz) {
|
||||||
int out_size;
|
int out_size;
|
||||||
int status;
|
int status;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
|
|
||||||
if (gz->in == NULL)
|
if (gz->in == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
out_size = (int)(1.05*gz->in_size) + 20;
|
out_size = (int)(1.05*gz->in_size) + 40;
|
||||||
gz->out = malloc(out_size);
|
gz->out = malloc(out_size);
|
||||||
if (gz->out == NULL) {
|
if (gz->out == NULL) {
|
||||||
DPRINTF(E_INF,L_WS|L_DAAP,"out of memory for output buffer\n");
|
DPRINTF(E_INF,L_WS|L_DAAP,"out of memory for output buffer\n");
|
||||||
gz->bytes_out = 0;
|
gz->bytes_out = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strm.zalloc = Z_NULL;
|
strm.zalloc = Z_NULL;
|
||||||
strm.zfree = Z_NULL;
|
strm.zfree = Z_NULL;
|
||||||
strm.opaque = Z_NULL;
|
strm.opaque = Z_NULL;
|
||||||
strm.next_in = gz->in;
|
strm.next_in = gz->in;
|
||||||
strm.avail_in = gz->bytes_in;
|
strm.avail_in = gz->bytes_in;
|
||||||
strm.next_out = gz->out;
|
strm.next_out = gz->out;
|
||||||
strm.avail_out = out_size;
|
strm.avail_out = out_size;
|
||||||
deflateInit2(&strm,GZIP_COMPRESSION_LEVEL,Z_DEFLATED,31,8,Z_DEFAULT_STRATEGY);
|
deflateInit2(&strm,GZIP_COMPRESSION_LEVEL,Z_DEFLATED,31,8,Z_DEFAULT_STRATEGY);
|
||||||
while ((status = deflate(&strm,Z_FINISH)) == Z_OK)
|
while ((status = deflate(&strm,Z_FINISH)) == Z_OK)
|
||||||
;
|
;
|
||||||
if (status != Z_STREAM_END) {
|
if (status != Z_STREAM_END) {
|
||||||
DPRINTF(E_LOG,L_WS|L_DAAP,"unable to compress data\n");
|
DPRINTF(E_LOG,L_WS|L_DAAP,"unable to compress data: %s (%d)\n",strm.msg,status);
|
||||||
gz->bytes_out = 0;
|
gz->bytes_out = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
gz->bytes_out = strm.total_out;
|
gz->bytes_out = strm.total_out;
|
||||||
deflateEnd(&strm);
|
deflateEnd(&strm);
|
||||||
|
|
||||||
return gz->bytes_out;
|
return gz->bytes_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gzip_close(GZIP_STREAM *gz, int fd) {
|
int gzip_close(GZIP_STREAM *gz, int fd) {
|
||||||
int bytes_written = gz->bytes_out;
|
int bytes_written = gz->bytes_out;
|
||||||
if (r_write(fd,gz->out,gz->bytes_out) != gz->bytes_out) {
|
if (r_write(fd,gz->out,gz->bytes_out) != gz->bytes_out) {
|
||||||
DPRINTF(E_LOG,L_WS|L_DAAP,"unable to write gzipped data\n");
|
DPRINTF(E_LOG,L_WS|L_DAAP,"unable to write gzipped data\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (gz->in != NULL)
|
if (gz->in != NULL)
|
||||||
free(gz->in);
|
free(gz->in);
|
||||||
if (gz->out != NULL)
|
if (gz->out != NULL)
|
||||||
free(gz->out);
|
free(gz->out);
|
||||||
free(gz);
|
free(gz);
|
||||||
return bytes_written;
|
return bytes_written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -338,46 +338,46 @@ int daap_serialize(DAAP_BLOCK *root, int fd, GZIP_STREAM *gz) {
|
|||||||
char size[4];
|
char size[4];
|
||||||
|
|
||||||
while(root) {
|
while(root) {
|
||||||
if (gz == NULL)
|
if (gz == NULL)
|
||||||
r_write(fd,root->tag,4);
|
r_write(fd,root->tag,4);
|
||||||
else
|
else
|
||||||
gzip_write(gz,root->tag,4);
|
gzip_write(gz,root->tag,4);
|
||||||
|
|
||||||
size[0] = (root->reported_size >> 24) & 0xFF;
|
size[0] = (root->reported_size >> 24) & 0xFF;
|
||||||
size[1] = (root->reported_size >> 16) & 0xFF;
|
size[1] = (root->reported_size >> 16) & 0xFF;
|
||||||
size[2] = (root->reported_size >> 8 ) & 0xFF;
|
size[2] = (root->reported_size >> 8 ) & 0xFF;
|
||||||
size[3] = (root->reported_size) & 0xFF;
|
size[3] = (root->reported_size) & 0xFF;
|
||||||
|
|
||||||
if (gz == NULL)
|
if (gz == NULL)
|
||||||
r_write(fd,&size,4);
|
r_write(fd,&size,4);
|
||||||
else
|
else
|
||||||
gzip_write(gz,&size,4);
|
gzip_write(gz,&size,4);
|
||||||
|
|
||||||
if(root->size) {
|
if(root->size) {
|
||||||
if(root->free) {
|
if(root->free) {
|
||||||
if (gz == NULL) {
|
if (gz == NULL) {
|
||||||
r_write(fd,root->value,root->size);
|
r_write(fd,root->value,root->size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gzip_write(gz,root->value,root->size);
|
gzip_write(gz,root->value,root->size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (gz == NULL) {
|
||||||
|
r_write(fd,root->svalue,root->size);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gzip_write(gz,root->svalue,root->size);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if (gz == NULL) {
|
if(root->children) {
|
||||||
r_write(fd,root->svalue,root->size);
|
if(daap_serialize(root->children,fd,gz))
|
||||||
}
|
return -1;
|
||||||
else {
|
|
||||||
gzip_write(gz,root->svalue,root->size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(root->children) {
|
root=root->next;
|
||||||
if(daap_serialize(root->children,fd,gz))
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
root=root->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -393,25 +393,25 @@ void daap_remove(DAAP_BLOCK* node)
|
|||||||
DAAP_BLOCK* parent = node->parent;
|
DAAP_BLOCK* parent = node->parent;
|
||||||
|
|
||||||
if(0 != parent)
|
if(0 != parent)
|
||||||
{
|
{
|
||||||
DAAP_BLOCK** ptr = &parent->children;
|
DAAP_BLOCK** ptr = &parent->children;
|
||||||
|
|
||||||
while(*ptr && *ptr != node)
|
while(*ptr && *ptr != node)
|
||||||
ptr = &(**ptr).next;
|
ptr = &(**ptr).next;
|
||||||
|
|
||||||
assert(0 != *ptr);
|
assert(0 != *ptr);
|
||||||
|
|
||||||
// remove us from the chain
|
// remove us from the chain
|
||||||
*ptr = node->next;
|
*ptr = node->next;
|
||||||
|
|
||||||
// update sizes in parent chain
|
// update sizes in parent chain
|
||||||
for(parent = node->parent ; parent ; parent = parent->parent)
|
for(parent = node->parent ; parent ; parent = parent->parent)
|
||||||
parent->reported_size -= (8 + node->reported_size);
|
parent->reported_size -= (8 + node->reported_size);
|
||||||
|
|
||||||
// clear parent and next pointers so daap_free doesn't get ambitious
|
// clear parent and next pointers so daap_free doesn't get ambitious
|
||||||
node->parent = 0;
|
node->parent = 0;
|
||||||
node->next = 0;
|
node->next = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
daap_free(node);
|
daap_free(node);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user