Process message improved.
--- a/rfc3164.c Sun Mar 26 23:00:16 2006 +0200
+++ b/rfc3164.c Wed Mar 29 08:44:57 2006 +0200
@@ -1,34 +1,30 @@
#include "rfc3164.h"
-#include <unistd.h>
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
#include <stdio.h>
-int readMessage(const int fd, char * restrict buffer)
+int process_message(char * restrict buffer)
{
- int count=MESSAGE_LENGTH;
+ int i;
char lletra;
int status;
- while(count-->0 && (status = read(fd, &lletra, 1 > 0)) >= 0) {
- if (lletra == '\n') break;
- *(buffer++) = lletra;
- }
- *buffer = '\0';
-
- if (status <= 0)
+ for(i=0; i<MESSAGE_LENGTH; i++)
{
- printf("Error reading the named pipe: %s\n", strerror(errno));
- abort();
- return -1;
+ if (buffer[i] == '\n' || buffer[i] == '\0')
+ {
+ buffer[i] = '\0';
+ break;
+ }
+ else if ((buffer[i] & 128) == 128 )
+ {
+ /* Convertim de 8bits a 7bits */
+ buffer[i] = buffer[i] & ~128;
+ }
}
- return count;
+ if(i == MESSAGE_LENGTH)
+ buffer[MESSAGE_LENGTH-1] == '\0';
+ /* Debug */
+ fprintf(stderr,"M: %s\n", buffer);
+
+ return i;
}
-
-int writeMessage(const int fd, const char * restrict buffer)
-{
- return 0;
-}
--- a/rfc3164.h Sun Mar 26 23:00:16 2006 +0200
+++ b/rfc3164.h Wed Mar 29 08:44:57 2006 +0200
@@ -3,7 +3,6 @@
#define MESSAGE_LENGTH 1024
-int readMessage(const int fd, char * restrict buffer);
-int writeMessage(const int fd, const char * restrict buffer);
+int process_message(char * restrict buffer);
#endif