cake
/
libg1m
Archived
1
0
Fork 0

Slightly corrected e-act content management

This commit is contained in:
Thomas Touhey 2016-12-13 11:38:07 +01:00
parent 4a7b1b1c47
commit 0673c1c026
1 changed files with 18 additions and 8 deletions

View File

@ -31,6 +31,18 @@ static int eact_parse_content_eact(g1m_line_t *handle, uint8_t *buf,
{
int err;
/* initialize the handle */
handle->type = g1m_linetype_eact;
handle->count = 0;
handle->_size = 0;
handle->lines = NULL;
/* check if the buffer is non-empty */
if (!bufsize) {
log_info("Content was name-only.");
return (0);
}
/* get e-act subheader */
if (bufsize < sizeof(struct eact_eactheader)) return (g1m_error_eof);
struct eact_eactheader ehd;
@ -48,7 +60,6 @@ static int eact_parse_content_eact(g1m_line_t *handle, uint8_t *buf,
struct line_descriptor *lds = (void*)&buf[sizeof(struct eact_eactheader)];
/* prepare the handle */
handle->type = g1m_linetype_eact;
handle->count = 0;
handle->_size = ehd.line_count;
handle->lines = malloc(sizeof(g1m_line_t*) * handle->_size);
@ -147,17 +158,16 @@ static int eact_parse_line_content(g1m_line_t *handle, uint8_t *buf,
struct eact_contentheader hd = {};
memcpy(&hd, buf, could_read);
/* store info */
bzero(handle->name, 17);
size_t namesize = max(could_read - 8, 16);
strncpy(handle->name, (char*)hd.name, namesize);
/* log info */
log_info("Type is '%.8s'", hd.type);
log_info("Name is '%.16s'", hd.name);
/* store info */
handle->name[16] = 0;
strncpy(handle->name, (char*)hd.name, 16);
log_info("Name is '%s'", handle->name);
/* prepare for next */
if (size == could_read)
return (0);
buf += could_read;
size -= could_read;