[client] project restructure part 1/2

This commit is contained in:
Geoffrey McRae
2019-03-28 11:02:36 +11:00
parent 7cbaf8b5be
commit db398d41a0
39 changed files with 164 additions and 53 deletions

56
client/src/kb.h Normal file
View File

@@ -0,0 +1,56 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
static uint32_t usb_to_ps2[] =
{
0x000000, 0x000000, 0x000000, 0x000000, 0x00001e, 0x000030, 0x00002e,
0x000020, 0x000012, 0x000021, 0x000022, 0x000023, 0x000017, 0x000024,
0x000025, 0x000026, 0x000032, 0x000031, 0x000018, 0x000019, 0x000010,
0x000013, 0x00001f, 0x000014, 0x000016, 0x00002f, 0x000011, 0x00002d,
0x000015, 0x00002c, 0x000002, 0x000003, 0x000004, 0x000005, 0x000006,
0x000007, 0x000008, 0x000009, 0x00000a, 0x00000b, 0x00001c, 0x000001,
0x00000e, 0x00000f, 0x000039, 0x00000c, 0x00000d, 0x00001a, 0x00001b,
0x00002b, 0x00002b, 0x000027, 0x000028, 0x000029, 0x000033, 0x000034,
0x000035, 0x00003a, 0x00003b, 0x00003c, 0x00003d, 0x00003e, 0x00003f,
0x000040, 0x000041, 0x000042, 0x000043, 0x000044, 0x000057, 0x000058,
0x00e037, 0x000046, 0x00e046, 0x00e052, 0x00e047, 0x00e049, 0x00e053,
0x00e04f, 0x00e051, 0x00e04d, 0x00e04b, 0x00e050, 0x00e048, 0x000045,
0x00e035, 0x000037, 0x00004a, 0x00004e, 0x00e01c, 0x00004f, 0x000050,
0x000051, 0x00004b, 0x00004c, 0x00004d, 0x000047, 0x000048, 0x000049,
0x000052, 0x000053, 0x000056, 0x00e05d, 0x000000, 0x000059, 0x00005d,
0x00005e, 0x00005f, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x00007e, 0x000000, 0x000073, 0x000070, 0x00007d, 0x000079, 0x00007b,
0x00005c, 0x000000, 0x000000, 0x000000, 0x0000f2, 0x0000f1, 0x000078,
0x000077, 0x000076, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x00001d, 0x00002a, 0x000038, 0x00e05b, 0x00e01d, 0x000036, 0x00e038,
0x00e05c
};

31
client/src/lg-fonts.c Normal file
View File

@@ -0,0 +1,31 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lg-fonts.h"
#include <stdlib.h>
extern const LG_Font LGF_SDL;
const LG_Font * LG_Fonts[] =
{
&LGF_SDL,
NULL // end of array sentinal
};
#define LG_FONT_COUNT ((sizeof(LG_Fonts) / sizeof(LG_Font *)) - 1)

49
client/src/lg-renderer.c Normal file
View File

@@ -0,0 +1,49 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdbool.h>
#include <string.h>
bool LG_RendererValidatorBool(const char * value)
{
if (!value)
return false;
return
(strcasecmp(value, "1" ) == 0) ||
(strcasecmp(value, "0" ) == 0) ||
(strcasecmp(value, "true" ) == 0) ||
(strcasecmp(value, "false" ) == 0) ||
(strcasecmp(value, "yes" ) == 0) ||
(strcasecmp(value, "no" ) == 0) ||
(strcasecmp(value, "on" ) == 0) ||
(strcasecmp(value, "off" ) == 0) ||
(strcasecmp(value, "enable" ) == 0) ||
(strcasecmp(value, "disable") == 0);
}
bool LG_RendererValueToBool(const char * value)
{
return
(strcasecmp(value, "1" ) == 0) ||
(strcasecmp(value, "true" ) == 0) ||
(strcasecmp(value, "yes" ) == 0) ||
(strcasecmp(value, "on" ) == 0) ||
(strcasecmp(value, "enable" ) == 0);
}

160
client/src/ll.c Normal file
View File

@@ -0,0 +1,160 @@
/*
KVMGFX Client - A KVM Client for VGA Passthrough
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ll.h"
#include "utils.h"
#include <stdlib.h>
#include <assert.h>
struct ll_item
{
void * data;
struct ll_item * next;
};
struct ll
{
struct ll_item * head;
struct ll_item * tail;
struct ll_item * pos;
unsigned int count;
LG_Lock lock;
};
struct ll * ll_new()
{
struct ll * list = malloc(sizeof(struct ll));
list->head = NULL;
list->tail = NULL;
list->pos = NULL;
LG_LOCK_INIT(list->lock);
return list;
}
void ll_free(struct ll * list)
{
// never free a list with items in it!
assert(!list->head);
LG_LOCK_FREE(list->lock);
free(list);
}
void ll_push(struct ll * list, void * data)
{
struct ll_item * item = malloc(sizeof(struct ll_item));
item->data = data;
item->next = NULL;
LG_LOCK(list->lock);
if (!list->head)
{
list->head = item;
list->tail = item;
LG_UNLOCK(list->lock);
return;
}
++list->count;
list->tail->next = item;
list->tail = item;
LG_UNLOCK(list->lock);
}
bool ll_shift(struct ll * list, void ** data)
{
LG_LOCK(list->lock);
if (!list->head)
{
LG_UNLOCK(list->lock);
return false;
}
--list->count;
struct ll_item * item = list->head;
list->head = item->next;
list->pos = NULL;
LG_UNLOCK(list->lock);
if (data)
*data = item->data;
free(item);
return true;
}
bool ll_peek_head(struct ll * list, void ** data)
{
LG_LOCK(list->lock);
if (!list->head)
{
LG_UNLOCK(list->lock);
return false;
}
*data = list->head->data;
LG_UNLOCK(list->lock);
return true;
}
unsigned int ll_count(struct ll * list)
{
return list->count;
}
void ll_reset (struct ll * list)
{
LG_LOCK(list->lock);
list->pos = NULL;
LG_UNLOCK(list->lock);
}
bool ll_walk(struct ll * list, void ** data)
{
LG_LOCK(list->lock);
if (!list->pos)
{
if (!list->head)
{
LG_UNLOCK(list->lock);
return false;
}
list->pos = list->head;
}
else
{
if (!list->pos->next)
{
LG_UNLOCK(list->lock);
return false;
}
list->pos = list->pos->next;
}
*data = list->pos->data;
LG_UNLOCK(list->lock);
return true;
}

1925
client/src/main.c Normal file

File diff suppressed because it is too large Load Diff

70
client/src/utils.c Normal file
View File

@@ -0,0 +1,70 @@
/*
Looking Glass - KVM FrameRelay (KVMFR) Client
Copyright (C) 2017-2019 Geoffrey McRae <geoff@hostfission.com>
https://looking-glass.hostfission.com
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "utils.h"
#include "debug.h"
#include <stdlib.h>
#include <stdio.h>
bool file_get_contents(const char * filename, char ** buffer, size_t * length)
{
FILE * fh = fopen(filename, "r");
if (!fh)
{
DEBUG_ERROR("Failed to open the file: %s", filename);
return false;
}
if (fseek(fh, 0, SEEK_END) != 0)
{
DEBUG_ERROR("Failed to seek");
fclose(fh);
return false;
}
long fsize = ftell(fh);
if (fseek(fh, 0, SEEK_SET) != 0)
{
DEBUG_ERROR("Failed to seek");
fclose(fh);
return false;
}
*buffer = malloc(fsize + 1);
if (!*buffer)
{
DEBUG_ERROR("Failed to allocate buffer of %lu bytes", fsize + 1);
fclose(fh);
return false;
}
if (fread(*buffer, 1, fsize, fh) != fsize)
{
DEBUG_ERROR("Failed to read the entire file");
fclose(fh);
free(*buffer);
return false;
}
fclose(fh);
buffer[fsize] = 0;
*length = fsize;
return true;
}