v0.5 kick-off
This commit is contained in:
+40
-38
@@ -6,7 +6,6 @@
|
||||
* COPYING file distributed with this package.
|
||||
*
|
||||
* Copyright (c) 1999, William Ferrell, Scott Scriven
|
||||
* 2001, Joris Robijn
|
||||
*
|
||||
*
|
||||
* Inits/shuts down client system,
|
||||
@@ -31,7 +30,7 @@
|
||||
|
||||
LinkedList *clients;
|
||||
|
||||
// Initialize and kill client list...
|
||||
/* Initialize and kill client list...*/
|
||||
int
|
||||
client_init ()
|
||||
{
|
||||
@@ -53,9 +52,10 @@ client_shutdown ()
|
||||
|
||||
debug (RPT_INFO, "client_shutdown()");
|
||||
|
||||
// Free all client structures...
|
||||
// Note that the regular list loop doesn't work here, because
|
||||
// client_destroy() calls LL_Remove()
|
||||
/* Free all client structures...
|
||||
* Note that the regular list loop doesn't work here, because
|
||||
* client_destroy() calls LL_Remove()
|
||||
*/
|
||||
for (c = LL_Pop (clients); c; c = LL_Pop (clients)) {
|
||||
debug (RPT_DEBUG, "client_shutdown: ...");
|
||||
if (c) {
|
||||
@@ -70,7 +70,7 @@ client_shutdown ()
|
||||
}
|
||||
}
|
||||
|
||||
// Then, free the list...
|
||||
/* Then, free the list...*/
|
||||
LL_Destroy (clients);
|
||||
|
||||
debug (RPT_DEBUG, "client_shutdown: done");
|
||||
@@ -78,10 +78,11 @@ client_shutdown ()
|
||||
return 0;
|
||||
}
|
||||
|
||||
// A client is identified by the file descriptor
|
||||
// associated with it.
|
||||
//
|
||||
// Create and destroy clients....
|
||||
/* A client is identified by the file descriptor
|
||||
+ associated with it.
|
||||
*
|
||||
* Create and destroy clients....
|
||||
*/
|
||||
client *
|
||||
client_create (int sock)
|
||||
{
|
||||
@@ -89,28 +90,28 @@ client_create (int sock)
|
||||
|
||||
debug (RPT_DEBUG, "client_create(%i)", sock);
|
||||
|
||||
// Allocate new client...
|
||||
/* Allocate new client...*/
|
||||
c = malloc (sizeof (client));
|
||||
if (!c) {
|
||||
report (RPT_ERR, "client_create: error allocating new client");
|
||||
return NULL;
|
||||
}
|
||||
// Init struct members
|
||||
/* Init struct members*/
|
||||
c->sock = 0;
|
||||
c->data = NULL;
|
||||
c->messages = NULL;
|
||||
|
||||
c->sock = sock;
|
||||
c->backlight_state = backlight; //By default we get the server setting
|
||||
c->backlight_state = backlight; /*By default we get the server setting*/
|
||||
|
||||
// Set up message list...
|
||||
/*Set up message list...*/
|
||||
c->messages = LL_new ();
|
||||
if (!c->messages) {
|
||||
report (RPT_ERR, "client_create: error allocating message list");
|
||||
free (c);
|
||||
return NULL;
|
||||
}
|
||||
// TODO: allocate and init client data...
|
||||
/*TODO: allocate and init client data...*/
|
||||
c->data = malloc (sizeof (client_data));
|
||||
if (!c->data) {
|
||||
report (RPT_ERR, "client_create: error allocating client data");
|
||||
@@ -120,7 +121,7 @@ client_create (int sock)
|
||||
} else if (client_data_init (c->data) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
// TODO: Check for errors while adding the client to the list?
|
||||
/*TODO: Check for errors while adding the client to the list?*/
|
||||
LL_Push (clients, (void *) c);
|
||||
|
||||
return c;
|
||||
@@ -138,7 +139,7 @@ client_destroy (client * c)
|
||||
if (!c)
|
||||
return -1;
|
||||
|
||||
// Eat the rest of the incoming requests...
|
||||
/*Eat the rest of the incoming requests...*/
|
||||
debug (RPT_DEBUG, "client_destroy: get_messages");
|
||||
while ((str = client_get_message (c))) {
|
||||
if (str) {
|
||||
@@ -147,19 +148,19 @@ client_destroy (client * c)
|
||||
}
|
||||
}
|
||||
|
||||
// close socket...
|
||||
/*close socket...*/
|
||||
if (c->sock) {
|
||||
// sock_send_string (c->sock, "bye\n");
|
||||
/*sock_send_string (c->sock, "bye\n");*/
|
||||
close(c->sock);
|
||||
report(RPT_NOTICE, "closed socket for #%d", c->sock);
|
||||
}
|
||||
|
||||
err = LL_Destroy (c->messages);
|
||||
|
||||
// Free client's other data
|
||||
/*Free client's other data*/
|
||||
client_data_destroy (c->data);
|
||||
|
||||
// Remove the client from the clients list...
|
||||
/*Remove the client from the clients list...*/
|
||||
LL_Remove (clients, c);
|
||||
|
||||
free (c);
|
||||
@@ -167,7 +168,7 @@ client_destroy (client * c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add and remove messages from the client's queue...
|
||||
/*Add and remove messages from the client's queue...*/
|
||||
int
|
||||
client_add_message (client * c, char *message)
|
||||
{
|
||||
@@ -175,7 +176,7 @@ client_add_message (client * c, char *message)
|
||||
char *dup;
|
||||
char *str, *cp;
|
||||
char delimiters[] = "\n\r\0";
|
||||
// int len;
|
||||
/* int len;*/
|
||||
|
||||
debug(RPT_DEBUG, "client_add_message(%s)", message);
|
||||
|
||||
@@ -184,31 +185,32 @@ client_add_message (client * c, char *message)
|
||||
if (!message)
|
||||
return -1;
|
||||
|
||||
// len = strlen(message);
|
||||
// if(len < 1) return 0;
|
||||
/* len = strlen(message);
|
||||
* if(len < 1) return 0;
|
||||
*/
|
||||
|
||||
// Copy the string to avoid overwriting the original...
|
||||
/* Copy the string to avoid overwriting the original...*/
|
||||
dup = strdup (message);
|
||||
if (!dup) {
|
||||
report(RPT_ERR, "client_add_message: Error allocating new string");
|
||||
return -1;
|
||||
}
|
||||
// Now split the string into lines and enqueue each one...
|
||||
/* Now split the string into lines and enqueue each one...*/
|
||||
for (str = strtok (dup, delimiters); str; str = strtok (NULL, delimiters)) {
|
||||
cp = strdup (str);
|
||||
debug (RPT_DEBUG, "client_add_message: %s", cp);
|
||||
err += LL_Enqueue (c->messages, (void *) cp);
|
||||
}
|
||||
|
||||
//debug(RPT_DEBUG, "client_add_message(%s): %i errors", message, err);
|
||||
free (dup); // Fixed memory leak...
|
||||
/*debug(RPT_DEBUG, "client_add_message(%s): %i errors", message, err);*/
|
||||
free (dup); /* Fixed memory leak...*/
|
||||
|
||||
// Err is the number of errors encountered...
|
||||
/* Err is the number of errors encountered...*/
|
||||
return err;
|
||||
|
||||
}
|
||||
|
||||
// Woo-hoo! A simple function. :)
|
||||
/* Woo-hoo! A simple function. :)*/
|
||||
char *
|
||||
client_get_message (client * c)
|
||||
{
|
||||
@@ -221,23 +223,23 @@ client_get_message (client * c)
|
||||
|
||||
str = (char *) LL_Dequeue (c->messages);
|
||||
|
||||
//debug(RPT_DEBUG, "client_get_message: \"%s\"", str);
|
||||
/*debug(RPT_DEBUG, "client_get_message: \"%s\"", str);*/
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
// Get and set the client's data...
|
||||
/* Get and set the client's data...*/
|
||||
int
|
||||
client_set (client * c, void *data)
|
||||
{
|
||||
// You know, I really doubt this function will be useful...
|
||||
/* You know, I really doubt this function will be useful...*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
client_get (client * c)
|
||||
{
|
||||
// But this one might be handy...
|
||||
/* But this one might be handy...*/
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -247,14 +249,14 @@ client_find_sock (int sock)
|
||||
{
|
||||
client *c;
|
||||
|
||||
// debug(RPT_INFO, "client_find_sock(%i)", sock);
|
||||
/* debug(RPT_INFO, "client_find_sock(%i)", sock);*/
|
||||
|
||||
LL_Rewind (clients);
|
||||
do {
|
||||
c = (client *) LL_Get (clients);
|
||||
// debug(RPT_DEBUG, "client_find_sock: ... %i ...", c->sock);
|
||||
/* debug(RPT_DEBUG, "client_find_sock: ... %i ...", c->sock);*/
|
||||
if (c->sock == sock) {
|
||||
// debug(RPT_DEBUG, "client_find_sock: ..! %i !..", c->sock);
|
||||
/* debug(RPT_DEBUG, "client_find_sock: ..! %i !..", c->sock);*/
|
||||
return c;
|
||||
}
|
||||
} while (LL_Next (clients) == 0);
|
||||
|
||||
Reference in New Issue
Block a user