3c4f8f48 |
/* |
2023340a |
* Copyright (C) 2007-2008 Sourcefire, Inc.
*
* Authors: Nigel Horne |
3c4f8f48 |
*
* This program is free software; you can redistribute it and/or modify |
2023340a |
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. |
3c4f8f48 |
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software |
48b7b4a7 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. |
3c4f8f48 |
*
* $Log: line.c,v $ |
95e11e5a |
* Revision 1.11 2007/02/12 20:46:08 njh
* Various tidy
* |
48b7b4a7 |
* Revision 1.10 2006/04/09 19:59:27 kojm
* update GPL headers with new address for FSF
* |
9c107190 |
* Revision 1.9 2005/03/10 08:53:33 nigelhorne
* Tidy
* |
3b33d46a |
* Revision 1.8 2005/03/01 11:38:11 nigelhorne
* Fix typo
* |
4c4eb464 |
* Revision 1.7 2004/12/08 20:07:23 nigelhorne
* Fix compilation error on Solaris
* |
86355dc2 |
* Revision 1.6 2004/10/14 17:45:55 nigelhorne
* Try to reclaim some memory if it becomes low when decoding
* |
381b67a7 |
* Revision 1.5 2004/09/30 08:58:56 nigelhorne
* Remove empty lines
* |
420df63c |
* Revision 1.4 2004/09/21 14:55:26 nigelhorne
* Handle blank lines in text/plain messages
* |
9fb5ab3a |
* Revision 1.3 2004/08/25 12:30:36 nigelhorne
* Use memcpy rather than strcpy
* |
b2223aad |
* Revision 1.2 2004/08/21 11:57:57 nigelhorne
* Use line.[ch]
* |
3c4f8f48 |
* Revision 1.1 2004/08/20 11:58:20 nigelhorne
* First draft
*
*/
|
95e11e5a |
static char const rcsid[] = "$Id: line.c,v 1.11 2007/02/12 20:46:08 njh Exp $"; |
3c4f8f48 |
#if HAVE_CONFIG_H
#include "clamav-config.h"
#endif
#include <stdio.h>
#include <string.h> |
420df63c |
#include <assert.h> |
3c4f8f48 |
#include "line.h"
#include "others.h"
|
b2223aad |
line_t *
lineCreate(const char *data)
{ |
9fb5ab3a |
const size_t size = strlen(data);
line_t *ret = (line_t *)cli_malloc(size + 2); |
b2223aad |
if(ret == NULL) |
9c107190 |
return (line_t *)NULL; |
b2223aad |
ret[0] = (char)1; |
9fb5ab3a |
/*strcpy(&ret[1], data);*/
memcpy(&ret[1], data, size);
ret[size + 1] = '\0'; |
b2223aad |
return ret;
}
line_t *
lineLink(line_t *line)
{ |
420df63c |
assert(line != NULL); |
9c107190 |
if((unsigned char)line[0] == (unsigned char)255) { |
381b67a7 |
cli_dbgmsg("lineLink: linkcount too large (%s)\n", lineGetData(line));
return lineCreate(lineGetData(line)); |
b2223aad |
}
line[0]++; |
381b67a7 |
/*printf("%d:\n\t'%s'\n", (int)line[0], &line[1]);*/ |
b2223aad |
return line;
}
line_t *
lineUnlink(line_t *line)
{
/*printf("%d:\n\t'%s'\n", (int)line[0], &line[1]);*/
if(--line[0] == 0) { |
3c4f8f48 |
free(line);
return NULL;
}
return line;
}
const char *
lineGetData(const line_t *line)
{ |
b2223aad |
return line ? &line[1] : NULL; |
3c4f8f48 |
} |