diff --git a/.gitignore b/.gitignore
index 15152b7..81af87c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,9 @@
-doc/
+doc/html
+doc/latex
+doc/man
src/match
-tests/testMatch
-tests/testParser
+test/testMatch
+test/testParser
.config
~$*
diff --git a/Doxyfile b/Doxyfile
index aa9c07c..98a81ba 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -44,7 +44,7 @@ PROJECT_BRIEF = "PSYC core library"
# exceed 55 pixels and the maximum width should not exceed 200 pixels.
# Doxygen will copy the logo to the output directory.
-PROJECT_LOGO =
+PROJECT_LOGO = doc/psyc.svg
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
@@ -875,7 +875,7 @@ HTML_FOOTER =
# the style sheet file to the HTML output directory, so don't put your own
# stylesheet in the HTML output directory as well, or it will be erased!
-HTML_STYLESHEET =
+HTML_STYLESHEET = doc/psyc.css
# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output.
# Doxygen will adjust the colors in the stylesheet and background images
diff --git a/Makefile b/Makefile
index 6ba55b6..c0c5d6f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
.PHONY: doc
-.PHONY: tests
+.PHONY: test
default:
- @/bin/echo -e "Usage:\n\tmake diet - compile with diet libc\n\tmake lib - compile with normal gnu libc\n\tmake tests\n\tmake doc"
+ @/bin/echo -e "Usage:\n\tmake diet - compile with diet libc\n\tmake lib - compile with normal gnu libc\n\tmake test\n\tmake doc"
lib:
make -C src lib
@@ -10,13 +10,13 @@ lib:
diet:
make -C src diet
-tests:
- make -C tests
+test:
+ make -C test
doc:
doxygen
clean:
make -C src clean
- make -C tests clean
- rm -rf doc
+ make -C test clean
+ rm -rf doc/html doc/latex doc/man
diff --git a/doc/psyc.css b/doc/psyc.css
new file mode 100644
index 0000000..afe3cac
--- /dev/null
+++ b/doc/psyc.css
@@ -0,0 +1,3 @@
+#projectlogo img {
+ height: 50px;
+}
diff --git a/doc/psyc.svg b/doc/psyc.svg
new file mode 100644
index 0000000..9a9dbf3
--- /dev/null
+++ b/doc/psyc.svg
@@ -0,0 +1,71 @@
+
+
+
diff --git a/include/psyc.h b/include/psyc.h
index b7f5b8f..16ad97d 100644
--- a/include/psyc.h
+++ b/include/psyc.h
@@ -30,6 +30,20 @@ typedef enum
PSYC_TRUE = 1,
} PSYC_Bool;
+/**
+ * PSYC packet parts.
+ */
+typedef enum
+{
+ PSYC_PART_RESET = -1,
+ PSYC_PART_HEADER = 0,
+ PSYC_PART_LENGTH,
+ PSYC_PART_CONTENT,
+ PSYC_PART_METHOD,
+ PSYC_PART_DATA,
+ PSYC_PART_END,
+} PSYC_Part;
+
/**
* Different types that a variable can have.
*
@@ -54,6 +68,16 @@ typedef enum
PSYC_TYPE_TIME,
} PSYC_Type;
+/**
+ * List types.
+ * Possible types are text and binary.
+ */
+typedef enum
+{
+ PSYC_LIST_TEXT = 1,
+ PSYC_LIST_BINARY = 2,
+} PSYC_ListType;
+
/**
* Get the type of variable name.
*/
@@ -64,7 +88,6 @@ PSYC_Type PSYC_getVarType(char* name, size_t len);
*/
PSYC_Bool PSYC_isRoutingVar(char* name, size_t len);
-
/**
* Checks if long keyword string inherits from short keyword string.
*/
diff --git a/include/psyc/parser.h b/include/psyc/parser.h
index edc15c7..b669ca5 100644
--- a/include/psyc/parser.h
+++ b/include/psyc/parser.h
@@ -22,7 +22,7 @@
typedef enum
{
PSYC_HEADER_ONLY = 1,
-} PSYC_ParserFlag;
+} PSYC_ParseFlag;
/**
* The return value definitions for the packet parsing function.
@@ -78,36 +78,12 @@ typedef enum
PSYC_LIST_END = 2,
/// Binary list is incomplete.
PSYC_LIST_INCOMPLETE = 3,
-} PSYC_ListRC;
-
-/**
- * PSYC packet parts.
- */
-typedef enum
-{
- PSYC_PART_RESET = -1,
- PSYC_PART_HEADER = 0,
- PSYC_PART_LENGTH,
- PSYC_PART_CONTENT,
- PSYC_PART_METHOD,
- PSYC_PART_DATA,
- PSYC_PART_END,
-} PSYC_Part;
-
-/**
- * List types.
- * Possible types are text and binary.
- */
-typedef enum
-{
- PSYC_LIST_TEXT = 1,
- PSYC_LIST_BINARY = 2,
-} PSYC_ListType;
+} PSYC_ParseListRC;
typedef struct
{
size_t length;
- const uint8_t * ptr; // just an unsigned char for opaque data
+ const uint8_t* ptr; // just an unsigned char for opaque data
} PSYC_Array; // to be renamed or solved differently..
/**
@@ -117,8 +93,8 @@ typedef struct
{
size_t cursor; ///< current position in buffer
size_t startc; ///< position where the parsing would be resumed
- PSYC_Array buffer;
- uint8_t flags; ///< flags for the parser, see PSYC_ParserFlag
+ PSYC_Array buffer; ///< buffer with data to be parsed
+ uint8_t flags; ///< flags for the parser, see PSYC_ParseFlag
PSYC_Part part; ///< part of the packet being parsed currently
size_t contentParsed; ///< number of bytes parsed from the content so far
@@ -126,7 +102,7 @@ typedef struct
PSYC_Bool contentLengthFound; ///< is there a length given for this packet?
size_t valueParsed; ///< number of bytes parsed from the value so far
size_t valueLength; ///< expected length of the value
-} PSYC_ParserState;
+} PSYC_ParseState;
/**
* Struct for keeping list parser state.
@@ -140,7 +116,7 @@ typedef struct
size_t elemParsed; ///< number of bytes parsed from the elem so far
size_t elemLength; ///< expected length of the elem
-} PSYC_ListState;
+} PSYC_ParseListState;
#ifndef PSYC_COMPILE_LIBRARY
/**
@@ -161,11 +137,11 @@ inline PSYC_Array PSYC_createArray (uint8_t* const memory, size_t length)
* Initiates the state struct with flags.
*
* @param state Pointer to the state struct that should be initiated.
- * @param flags Flags to be set for the parser, see PSYC_ParserFlag.
+ * @param flags Flags to be set for the parser, see PSYC_ParseFlag.
*/
-inline void PSYC_initState2 (PSYC_ParserState* state, uint8_t flags )
+inline void PSYC_initState2 (PSYC_ParseState* state, uint8_t flags)
{
- memset(state, 0, sizeof(PSYC_ParserState));
+ memset(state, 0, sizeof(PSYC_ParseState));
state->flags = flags;
}
@@ -174,9 +150,9 @@ inline void PSYC_initState2 (PSYC_ParserState* state, uint8_t flags )
*
* @param state Pointer to the state struct that should be initiated.
*/
-inline void PSYC_initState (PSYC_ParserState* state)
+inline void PSYC_initState (PSYC_ParseState* state)
{
- memset(state, 0, sizeof(PSYC_ParserState));
+ memset(state, 0, sizeof(PSYC_ParseState));
}
/**
@@ -184,24 +160,24 @@ inline void PSYC_initState (PSYC_ParserState* state)
*
* @param state Pointer to the list state struct that should be initiated.
*/
-inline void PSYC_initListState (PSYC_ListState* state)
+inline void PSYC_initListState (PSYC_ParseListState* state)
{
- memset(state, 0, sizeof(PSYC_ListState));
+ memset(state, 0, sizeof(PSYC_ParseListState));
}
-inline void PSYC_nextBuffer (PSYC_ParserState* state, PSYC_Array newBuf)
+inline void PSYC_nextBuffer (PSYC_ParseState* state, PSYC_Array newBuf)
{
state->buffer = newBuf;
state->cursor = 0;
}
-inline void PSYC_nextListBuffer (PSYC_ListState* state, PSYC_Array newBuf)
+inline void PSYC_nextListBuffer (PSYC_ParseListState* state, PSYC_Array newBuf)
{
state->buffer = newBuf;
state->cursor = 0;
}
-inline size_t PSYC_getContentLength (PSYC_ParserState* s)
+inline size_t PSYC_getContentLength (PSYC_ParseState* s)
{
return s->contentLength;
}
@@ -213,7 +189,7 @@ inline size_t PSYC_getContentLength (PSYC_ParserState* s)
*
* Generalized line-based packet parser.
*
- * @param state An initialized PSYC_ParserState
+ * @param state An initialized PSYC_ParseState
* @param modifier A pointer to a character. In case of a variable, it will
* be set to the modifier of that variable
* @param name A pointer to a PSYC_Array. It will point to the name of
@@ -221,12 +197,12 @@ inline size_t PSYC_getContentLength (PSYC_ParserState* s)
* @param value A pointer to a PSYC_Array. It will point to the
* value/body the variable/method and its length will be set accordingly
*/
-PSYC_ParseRC PSYC_parse(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value);
+PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value);
/**
* List value parser.
*/
-PSYC_ListRC PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem);
+PSYC_ParseListRC PSYC_parseList(PSYC_ParseListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem);
#endif // PSYC_PARSER_H
diff --git a/include/psyc/render.h b/include/psyc/render.h
index 43eb0c7..52bf0c8 100644
--- a/include/psyc/render.h
+++ b/include/psyc/render.h
@@ -1,3 +1,6 @@
+/**
+ * Struct for keeping render state.
+ */
typedef enum {
PSYC_FINE = 0,
PSYC_NEED_LENGTH = 1
@@ -5,22 +8,23 @@ typedef enum {
typedef struct {
PSYC_RenderFlag flag; ///< flags for the renderer
+ PSYC_Part part; ///< part of the packet being rendered
size_t cursor; ///< current position in buffer
size_t start; ///< position where the rendered packet starts
+ size_t contentLength; ///< length of the content part
size_t length; ///< how big is the buffer we allocated
uint8_t buffer[]; ///< OMG a C99 feature! variable size buffer!
} PSYC_RenderState;
-int PSYC_renderHeader(PSYC_RenderState render,
+int PSYC_renderHeader(PSYC_RenderState* render,
const uint8_t* name, const size_t nlength,
const uint8_t* value, const size_t vlength,
const uint8_t flags, const uint8_t modifier);
-int PSYC_renderBody(PSYC_RenderState render,
+int PSYC_renderBody(PSYC_RenderState* render,
const uint8_t* method, const size_t mlength,
const uint8_t* data, const size_t dlength,
const uint8_t flags);
-int PSYC_doneRender(PSYC_RenderState render,
+int PSYC_doneRender(PSYC_RenderState* render,
uint8_t** buf, size_t* written);
-
diff --git a/src/parser.c b/src/parser.c
index 1f3b98a..264b0d7 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -68,7 +68,7 @@ inline char isKwChar(uint8_t c)
* It should contain one or more keyword characters.
* @return PSYC_ERROR or PSYC_SUCCESS
*/
-inline PSYC_ParseRC PSYC_parseName(PSYC_ParserState* state, PSYC_Array* name)
+inline PSYC_ParseRC PSYC_parseName(PSYC_ParseState* state, PSYC_Array* name)
{
name->ptr = state->buffer.ptr + state->cursor;
name->length = 0;
@@ -92,7 +92,7 @@ inline PSYC_ParseRC PSYC_parseName(PSYC_ParserState* state, PSYC_Array* name)
*
* @return PSYC_COMPLETE or PSYC_INCOMPLETE
*/
-inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParserState* state, PSYC_Array* value, size_t* length, size_t* parsed)
+inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParseState* state, PSYC_Array* value, size_t* length, size_t* parsed)
{
size_t remaining = *length - *parsed;
value->ptr = state->buffer.ptr + state->cursor;
@@ -115,7 +115,7 @@ inline PSYC_ParseRC PSYC_parseBinaryValue(PSYC_ParserState* state, PSYC_Array* v
* Parse simple or binary variable.
* @return PSYC_ERROR or PSYC_SUCCESS
*/
-inline PSYC_ParseRC PSYC_parseVar(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
+inline PSYC_ParseRC PSYC_parseVar(PSYC_ParseState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
{
*modifier = *(state->buffer.ptr + state->cursor);
ADVANCE_CURSOR_OR_RETURN(PSYC_INSUFFICIENT);
@@ -179,7 +179,7 @@ inline PSYC_ParseRC PSYC_parseVar(PSYC_ParserState* state, uint8_t* modifier, PS
* Parse PSYC packets.
* Generalized line-based parser.
*/
-PSYC_ParseRC PSYC_parse(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
+PSYC_ParseRC PSYC_parse(PSYC_ParseState* state, uint8_t* modifier, PSYC_Array* name, PSYC_Array* value)
{
int ret; // a return value
size_t pos; // a cursor position
@@ -369,7 +369,7 @@ PSYC_ParseRC PSYC_parse(PSYC_ParserState* state, uint8_t* modifier, PSYC_Array*
* List value parser.
* @return see PSYC_ListRC.
*/
-PSYC_ListRC PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem)
+PSYC_ParseListRC PSYC_parseList(PSYC_ParseListState* state, PSYC_Array *name, PSYC_Array* value, PSYC_Array* elem)
{
if (state->cursor >= state->buffer.length)
return PSYC_LIST_INCOMPLETE;
@@ -440,7 +440,7 @@ PSYC_ListRC PSYC_parseList(PSYC_ListState* state, PSYC_Array *name, PSYC_Array*
// Start or resume parsing the binary data
if (state->elemParsed < state->elemLength)
{
- if (PSYC_parseBinaryValue((PSYC_ParserState*)state, elem, &(state->elemLength), &(state->elemParsed)) == PSYC_INCOMPLETE)
+ if (PSYC_parseBinaryValue((PSYC_ParseState*)state, elem, &(state->elemLength), &(state->elemParsed)) == PSYC_INCOMPLETE)
return PSYC_LIST_INCOMPLETE;
state->elemLength = 0;
diff --git a/src/render.c b/src/render.c
index 269fba0..2bdec60 100644
--- a/src/render.c
+++ b/src/render.c
@@ -4,21 +4,21 @@
/* render PSYC packets */
-int PSYC_renderBody(PSYC_RenderState render,
+int PSYC_renderBody(PSYC_RenderState* render,
const uint8_t* method, const size_t mlength,
const uint8_t* data, const size_t dlength,
const uint8_t flags) {
// find out if this packet needs a prepended length
if (dlength == 1 && data[0] == C_GLYPH_PACKET_DELIMITER)
- render.flag = PSYC_NEED_LENGTH;
+ render->flag = PSYC_NEED_LENGTH;
else if (dlength > 404)
- render.flag = PSYC_NEED_LENGTH;
+ render->flag = PSYC_NEED_LENGTH;
else if (memmem(data, dlength, PSYC_PACKET_DELIMITER,
sizeof(PSYC_PACKET_DELIMITER)))
- render.flag = PSYC_NEED_LENGTH;
+ render->flag = PSYC_NEED_LENGTH;
else
- render.flag = PSYC_FINE;
+ render->flag = PSYC_FINE;
// TBD
return 0;
diff --git a/tests/Makefile b/test/Makefile
similarity index 100%
rename from tests/Makefile
rename to test/Makefile
diff --git a/tests/packets/binary.txt b/test/packets/binary.txt
similarity index 100%
rename from tests/packets/binary.txt
rename to test/packets/binary.txt
diff --git a/tests/packets/enter_leave_context.txt b/test/packets/enter_leave_context.txt
similarity index 100%
rename from tests/packets/enter_leave_context.txt
rename to test/packets/enter_leave_context.txt
diff --git a/tests/packets/fake_dns.txt b/test/packets/fake_dns.txt
similarity index 100%
rename from tests/packets/fake_dns.txt
rename to test/packets/fake_dns.txt
diff --git a/tests/packets/invalid_dns.txt b/test/packets/invalid_dns.txt
similarity index 100%
rename from tests/packets/invalid_dns.txt
rename to test/packets/invalid_dns.txt
diff --git a/tests/packets/test-0-no-content b/test/packets/test-0-no-content
similarity index 100%
rename from tests/packets/test-0-no-content
rename to test/packets/test-0-no-content
diff --git a/tests/packets/test-1 b/test/packets/test-1
similarity index 100%
rename from tests/packets/test-1
rename to test/packets/test-1
diff --git a/tests/packets/test-1-length b/test/packets/test-1-length
similarity index 100%
rename from tests/packets/test-1-length
rename to test/packets/test-1-length
diff --git a/tests/packets/test-1-length-error b/test/packets/test-1-length-error
similarity index 100%
rename from tests/packets/test-1-length-error
rename to test/packets/test-1-length-error
diff --git a/tests/packets/test-1-utf8 b/test/packets/test-1-utf8
similarity index 100%
rename from tests/packets/test-1-utf8
rename to test/packets/test-1-utf8
diff --git a/tests/packets/test-2-list b/test/packets/test-2-list
similarity index 100%
rename from tests/packets/test-2-list
rename to test/packets/test-2-list
diff --git a/tests/packets/test-2-list-error b/test/packets/test-2-list-error
similarity index 100%
rename from tests/packets/test-2-list-error
rename to test/packets/test-2-list-error
diff --git a/tests/packets/test-3-list b/test/packets/test-3-list
similarity index 100%
rename from tests/packets/test-3-list
rename to test/packets/test-3-list
diff --git a/tests/packets/test-4-circuit b/test/packets/test-4-circuit
similarity index 100%
rename from tests/packets/test-4-circuit
rename to test/packets/test-4-circuit
diff --git a/tests/packets/test-4-circuit-n b/test/packets/test-4-circuit-n
similarity index 100%
rename from tests/packets/test-4-circuit-n
rename to test/packets/test-4-circuit-n
diff --git a/tests/packets/test-5-message-private b/test/packets/test-5-message-private
similarity index 100%
rename from tests/packets/test-5-message-private
rename to test/packets/test-5-message-private
diff --git a/tests/packets/test-6-message-private-remote b/test/packets/test-6-message-private-remote
similarity index 100%
rename from tests/packets/test-6-message-private-remote
rename to test/packets/test-6-message-private-remote
diff --git a/tests/testMatch.c b/test/testMatch.c
similarity index 100%
rename from tests/testMatch.c
rename to test/testMatch.c
diff --git a/tests/testParser.c b/test/testParser.c
similarity index 95%
rename from tests/testParser.c
rename to test/testParser.c
index a7fc065..c743462 100644
--- a/tests/testParser.c
+++ b/test/testParser.c
@@ -1,3 +1,4 @@
+#include
#include
#include
#include
@@ -8,8 +9,8 @@ int main(int argc, char** argv)
int index, ret;
uint8_t buffer[2048], modifier;
PSYC_Array name, value, elem;
- PSYC_ParserState state;
- PSYC_ListState listState;
+ PSYC_ParseState state;
+ PSYC_ParseListState listState;
int file = open(argv[1],O_RDONLY);
if(file < 0)