1999-12-09 23:15:14 +00:00
|
|
|
/*
|
|
|
|
|
client_data.c
|
|
|
|
|
|
|
|
|
|
Creates and destroys a client's data structures. These are mainly
|
|
|
|
|
its name, screen list, and menu list.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2001-05-25 03:14:27 +00:00
|
|
|
#include "shared/debug.h"
|
1999-12-09 23:15:14 +00:00
|
|
|
|
|
|
|
|
#include "client_data.h"
|
|
|
|
|
#include "screen.h"
|
|
|
|
|
#include "screenlist.h"
|
|
|
|
|
|
2001-09-21 21:08:10 +00:00
|
|
|
#define ResetScreenList(a) LL_Rewind(a)
|
|
|
|
|
#define NewScreen LL_new
|
|
|
|
|
#define NextScreen(a) (screen *)LL_Get(a)
|
|
|
|
|
#define MoreScreens(a) (LL_Next(a) == 0)
|
|
|
|
|
#define DestroyScreenList(a) LL_Destroy(a)
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
int
|
|
|
|
|
client_data_init (client_data * d)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
if (!d)
|
|
|
|
|
return -1;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
d->ack = 0;
|
|
|
|
|
d->name = NULL;
|
2001-05-11 17:55:36 +00:00
|
|
|
d->client_keys = NULL;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2001-09-21 21:08:10 +00:00
|
|
|
d->screenlist = NewScreen();
|
2000-04-03 22:13:57 +00:00
|
|
|
if (!d->screenlist) {
|
|
|
|
|
fprintf (stderr, "client_data_init: Error allocating screenlist\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
/* TODO: this section... (client menus)
|
|
|
|
|
d->menulist = LL_new();
|
|
|
|
|
if(!d->menulist)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "client_data_init: Error allocating menulist\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
return 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
2000-03-30 20:20:41 +00:00
|
|
|
int
|
|
|
|
|
client_data_destroy (client_data * d)
|
1999-12-09 23:15:14 +00:00
|
|
|
{
|
2000-04-03 22:13:57 +00:00
|
|
|
screen *s;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
debug ("client_data_destroy\n");
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
if (!d)
|
|
|
|
|
return -1;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
d->ack = 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
// Clean up the name...
|
|
|
|
|
if (d->name)
|
|
|
|
|
free (d->name);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2001-05-11 17:55:36 +00:00
|
|
|
// Clean up the key list...
|
|
|
|
|
if (d->client_keys)
|
|
|
|
|
free (d->client_keys);
|
|
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
// Clean up the screenlist...
|
|
|
|
|
debug ("client_data_destroy: Cleaning screenlist\n");
|
2001-09-21 21:08:10 +00:00
|
|
|
ResetScreenList (d->screenlist);
|
2000-04-03 22:13:57 +00:00
|
|
|
do {
|
2001-09-21 21:08:10 +00:00
|
|
|
s = NextScreen(d->screenlist);
|
2000-04-03 22:13:57 +00:00
|
|
|
if (s) {
|
|
|
|
|
debug ("client_data_destroy: removing screen %s\n", s->id);
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
// FIXME? This shouldn't be handled here...
|
|
|
|
|
// Now, remove it from the screenlist...
|
|
|
|
|
if (screenlist_remove_all (s) < 0) {
|
|
|
|
|
// Not a serious error..
|
|
|
|
|
fprintf (stderr, "client_data_destroy: Error dequeueing screen\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// Free its memory...
|
|
|
|
|
screen_destroy (s);
|
|
|
|
|
}
|
2001-09-21 21:08:10 +00:00
|
|
|
} while (MoreScreens(d->screenlist));
|
|
|
|
|
DestroyScreenList(d->screenlist);
|
2000-03-30 20:20:41 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
// TODO: clean up the rest of the data...
|
1999-12-09 23:15:14 +00:00
|
|
|
|
2000-04-03 22:13:57 +00:00
|
|
|
return 0;
|
1999-12-09 23:15:14 +00:00
|
|
|
}
|