diff --git a/debian/Manifest b/debian/Manifest index 27314c1..d7fcae4 100644 --- a/debian/Manifest +++ b/debian/Manifest @@ -2,6 +2,7 @@ Package: gem-graph-server Version: 0.0.1 Section: custom Priority: optional +Depends: libxml2 Architecture: amd64 Essential: no Installed-Size: 1049 diff --git a/src/server.c b/src/server.c index c898066..40219c4 100644 --- a/src/server.c +++ b/src/server.c @@ -87,7 +87,7 @@ void *serverCommunicationInstance(void *server) clientPort, receiveBuff); - if (receiveBuff[0] == '\0') + if (receiveBuff[0] == '\0') //XXX break; // get args in an array @@ -222,10 +222,10 @@ static void *serverMain(void *server) clientIP, socklen); printLog("Client accepted from %s:%d\n", clientIP, - ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); + ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread // Populate communicator slot - serverSlots[serverSlotIndex].socklen = socklen; + serverSlots[serverSlotIndex].socklen = socklen; // XXX serverSlots[serverSlotIndex].sockfd = connfd; serverSlots[serverSlotIndex].parent = args; diff --git a/src/tests/getchar b/src/tests/getchar new file mode 100755 index 0000000..79b5550 Binary files /dev/null and b/src/tests/getchar differ diff --git a/src/tests/getchar.c b/src/tests/getchar.c new file mode 100644 index 0000000..37ae5d0 --- /dev/null +++ b/src/tests/getchar.c @@ -0,0 +1,104 @@ +#include "../../include/base.h" +#include +#include +#include +#include + +#define KEY_ESCAPE 27 +#define KEY_DIRECTIONS 91 +#define KEY_ARROW_UP 65 +#define KEY_ARROW_DOWN 66 +#define KEY_ARROW_RIGHT 67 +#define KEY_ARROW_LEFT 68 +#define KEY_DELETE 127 + +#define C_CLEARSCREEN "\e[2J" +#define C_CLEARLINE "\e[2K" +#define C_CURSORLEFT "\e[1D" +#define C_CURSORRIGHT "\e[1C" +#define C_SAVE_CURSORPOS "\e7" +#define C_RESTORE_CURSORPOS "\e8" +#define C_COLOR_RED "\e[01;31m" +#define C_COLOR_YELLOW "\e[00;33m" +#define C_COLOR_GREEN "\e[00;32m" +#define C_COLOR_BLUE "\e[01;34m" +#define C_COLOR_REVERSE "\e[7m" +#define C_COLOR_NORMAL "\e[0m" + +// +// Get a character code from the keyboard +// +static inline int getch(bool nonBlocking) +{ + int buf = 0; + // old terminal + struct termios old = {0}; + + // force flush stdout + fflush(stdout); + + // Set non-blocking mode if asked + if(nonBlocking) + fcntl(0, F_SETFL, O_NONBLOCK); + + if(tcgetattr(0, &old) < 0) { + printLog("%sError getting terminal settings! (%s)\n", + C_COLOR_RED, + strerror(errno)); + return -1; + } + + old.c_lflag &= ~ICANON; // disable buffered I/O + old.c_lflag &= ~ECHO; // set no echo mode + + if(tcsetattr(0, TCSANOW, &old) < 0) { + printLog("%sError setting terminal settings! (%s)\n", + C_COLOR_RED, + strerror(errno)); + return -1; + } + + buf = getchar(); + if(buf < 0) { + // Check target busy (try again) + if(errno == EAGAIN) + return 0; + + printLog("%sError reading character! (%s)\n", + C_COLOR_RED, + strerror(errno)); + return -1; + } + + old.c_lflag |= ICANON; // enable buffered I/O + old.c_lflag |= ECHO; // set echo mode + + if(tcsetattr(0, TCSADRAIN, &old) < 0) { + printLog("%sError resetting terminal settings! (%s)\n", + C_COLOR_RED, + strerror(errno)); + return -1; + } + + // Reset blocking mode + if(nonBlocking) + fcntl(0, F_SETFL, 0); + + return buf; + } + + +int main(void) +{ + + + while(1) { + int c = getch(1); + + if (c > 0) + printf("touche %d\n", c); + + } + + return 0; +} diff --git a/src/tests/xml b/src/tests/xml new file mode 100755 index 0000000..04cd32f Binary files /dev/null and b/src/tests/xml differ diff --git a/src/tests/xml.c b/src/tests/xml.c new file mode 100644 index 0000000..bcba914 --- /dev/null +++ b/src/tests/xml.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include + +void parseStory (xmlDocPtr doc, xmlNodePtr cur) +{ + cur = cur->xmlChildrenNode; + while (cur != NULL) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))) { + printf("keyword: %s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); + } + cur = cur->next; + } + return; +} + +static void parseDoc(char *docname) +{ + xmlDocPtr doc; + xmlNodePtr cur; + doc = xmlParseFile(docname); + if (doc == NULL ) { + fprintf(stderr,"Document not parsed successfully. \n"); + xmlFreeDoc(doc); + return; + } + + cur = xmlDocGetRootElement(doc); + if (cur == NULL) { + fprintf(stderr,"empty document\n"); + xmlFreeDoc(doc); + return; + } + if (xmlStrcmp(cur->name, (const xmlChar *) "story")) { + fprintf(stderr,"document of the wrong type, root node != story"); + xmlFreeDoc(doc); + return; + } + cur = cur->xmlChildrenNode; + while (cur != NULL) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){ + parseStory (doc, cur); + } + cur = cur->next; + } + xmlFreeDoc(doc); + return; +} + +int main(int argc, char **argv) +{ + char *docname; + if (argc <= 1) { + printf("Usage: %s docname\n", argv[0]); + return 1; + } + + docname = argv[1]; + parseDoc (docname); + + return 0; +} + diff --git a/src/tests/xml.xml b/src/tests/xml.xml new file mode 100644 index 0000000..748e53c --- /dev/null +++ b/src/tests/xml.xml @@ -0,0 +1,15 @@ + + + + John Fleck + June 2, 2002 + example keyword + + + + This is the headline + This is the body text. + + + +