-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inital commit, http server working
- Loading branch information
0 parents
commit e6175e0
Showing
15 changed files
with
1,273 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### Executable ### | ||
*.app | ||
*.bat | ||
*.cgi | ||
*.com | ||
*.exe | ||
*.gadget | ||
*.jar | ||
*.pif | ||
*.vb | ||
*.wsf | ||
|
||
### Tags ### | ||
# Ignore tags created by etags, ctags, gtags (GNU global) and cscope | ||
TAGS | ||
.TAGS | ||
!TAGS/ | ||
tags | ||
.tags | ||
!tags/ | ||
gtags.files | ||
GTAGS | ||
GRTAGS | ||
GPATH | ||
GSYMS | ||
cscope.files | ||
cscope.out | ||
cscope.in.out | ||
cscope.po.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "libwebsockets"] | ||
path = libwebsockets | ||
url = https://github.com/warmcat/libwebsockets.git | ||
[submodule "libfprint"] | ||
path = libfprint | ||
url = https://github.com/eiguike/libfprint.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
project(fingerprint-client C) | ||
|
||
add_library(Server STATIC library/server.c) | ||
add_library(ServerHTTP STATIC library/protocols/http_protocol.c) | ||
|
||
include_directories("./include") | ||
|
||
set(SOURCE_FILES main.c) | ||
add_executable(fingerprint-client ${SOURCE_FILES}) | ||
|
||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/www | ||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
target_link_libraries(Server websockets) | ||
target_link_libraries(Server ServerHTTP) | ||
target_link_libraries(fingerprint-client Server) | ||
|
||
install(TARGETS fingerprint-client DESTINATION /bin) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# fingerprint-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef ABOUT_PROTOCOL_H | ||
#define ABOUT_PROTOCOL_H | ||
|
||
#include "server.h" | ||
|
||
typedef struct buffer { | ||
//unsigned char data[ LWS_SEND_BUFFER_PRE_PADDING + | ||
// EXAMPLE_RX_BUFFER_BYTES + | ||
// LWS_SEND_BUFFER_POST_PADDING ]; | ||
unsigned char * Data | ||
size_t Length; | ||
} BUFFER; | ||
|
||
typedef struct Information { | ||
char * Name; | ||
char * Linux; | ||
char * ApplicationVersion; | ||
} INFORMATION; | ||
|
||
int AboutCallback (struct lws *wsi, | ||
enum lws_callback_reasons reason, | ||
void * user, | ||
void * in, | ||
size_t len); | ||
|
||
void InitializeAboutProtocol (); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#ifndef HTTP_PROTOCOL_H | ||
#define HTTP_PROTOCOL_H | ||
|
||
/* | ||
* libwebsockets-test-server - libwebsockets test implementation | ||
* | ||
* Copyright (C) 2010-2016 Andy Green <andy@warmcat.com> | ||
* | ||
* This file is made available under the Creative Commons CC0 1.0 | ||
* Universal Public Domain Dedication. | ||
* | ||
* The person who associated a work with this deed has dedicated | ||
* the work to the public domain by waiving all of his or her rights | ||
* to the work worldwide under copyright law, including all related | ||
* and neighboring rights, to the extent allowed by law. You can copy, | ||
* modify, distribute and perform the work, even for commercial purposes, | ||
* all without asking permission. | ||
* | ||
* The test apps are intended to be adapted for use in your code, which | ||
* may be proprietary. So unlike the library itself, they are licensed | ||
* Public Domain. | ||
*/ | ||
|
||
#if defined(_WIN32) && defined(EXTERNAL_POLL) | ||
#define WINVER 0x0600 | ||
#define _WIN32_WINNT 0x0600 | ||
#define poll(fdArray, fds, timeout) WSAPoll((LPWSAPOLLFD)(fdArray), (ULONG)(fds), (INT)(timeout)) | ||
#endif | ||
|
||
#include "lws_config.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <getopt.h> | ||
#include <signal.h> | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <assert.h> | ||
|
||
#include "libwebsockets.h" | ||
|
||
#ifdef _WIN32 | ||
#include <io.h> | ||
#include "gettimeofday.h" | ||
#else | ||
#include <syslog.h> | ||
#include <sys/time.h> | ||
#include <unistd.h> | ||
#endif | ||
|
||
extern int close_testing; | ||
extern int max_poll_elements; | ||
|
||
#ifdef EXTERNAL_POLL | ||
extern struct lws_pollfd *pollfds; | ||
extern int *fd_lookup; | ||
extern int count_pollfds; | ||
#endif | ||
extern volatile int force_exit; | ||
extern struct lws_context *context; | ||
extern char *resource_path; | ||
#if defined(LWS_OPENSSL_SUPPORT) && defined(LWS_HAVE_SSL_CTX_set1_param) | ||
extern char crl_path[1024]; | ||
#endif | ||
|
||
extern void test_server_lock(int care); | ||
extern void test_server_unlock(int care); | ||
|
||
#ifndef __func__ | ||
#define __func__ __FUNCTION__ | ||
#endif | ||
|
||
typedef struct per_session_data__http_struct { | ||
lws_fop_fd_t fop_fd; | ||
#ifdef LWS_WITH_CGI | ||
struct lws_cgi_args args; | ||
#endif | ||
#if defined(LWS_WITH_CGI) || !defined(LWS_NO_CLIENT) | ||
int reason_bf; | ||
#endif | ||
unsigned int client_finished:1; | ||
|
||
|
||
struct lws_spa *spa; | ||
char result[500 + LWS_PRE]; | ||
int result_len; | ||
|
||
char filename[256]; | ||
long file_length; | ||
lws_filefd_type post_fd; | ||
} per_session_data__http ; | ||
|
||
/* | ||
* one of these is auto-created for each connection and a pointer to the | ||
* appropriate instance is passed to the callback in the user parameter | ||
* | ||
* for this example protocol we use it to individualize the count for each | ||
* connection. | ||
*/ | ||
|
||
#if !defined(DI_HANDLED_BY_PLUGIN) | ||
struct per_session_data__dumb_increment { | ||
int number; | ||
}; | ||
#endif | ||
|
||
|
||
extern int | ||
callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, | ||
void *in, size_t len); | ||
|
||
#if !defined(DI_HANDLED_BY_PLUGIN) | ||
extern int | ||
callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason, | ||
void *user, void *in, size_t len); | ||
#endif | ||
|
||
|
||
extern void | ||
dump_handshake_info(struct lws *wsi); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef SERVER_H | ||
#define SERVER_H | ||
|
||
#include <libwebsockets.h> | ||
|
||
#include "protocols/http_protocol.h" | ||
|
||
#define EXAMPLE_RX_BUFFER_BYTES (50) | ||
|
||
typedef struct WEBSOCKET_SERVER { | ||
struct lws_protocols * Protocols; | ||
struct lws_context_creation_info * ContextInfo; | ||
struct lws_context * Context; | ||
unsigned int NumbersOfProtocols; | ||
short int IsStop; | ||
|
||
int (*Start)(struct WEBSOCKET_SERVER * this); | ||
int (*Stop)(struct WEBSOCKET_SERVER * this); | ||
} SERVER; | ||
|
||
int Start (SERVER * this); | ||
int Stop (SERVER * this); | ||
SERVER * InitializeServer(int Port); | ||
SERVER * InitializeServerSSL(int Port); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "server.h" | ||
#include "protocols/about_protocol.h" | ||
|
||
#define APPLICATION_VERSION "fingerprint-client 1.0v" | ||
|
||
INFORMATION Computer; | ||
BUFFER Buffer; | ||
|
||
int | ||
CallbackAbout( | ||
struct lws *wsi, | ||
enum lws_callback_reasons reason, | ||
void *user, | ||
void *in, | ||
size_t len ) | ||
{ | ||
switch(reason) { | ||
case LWS_CALLBACK_SERVER_WRITEABLE: | ||
printf("Sending message...\n"); | ||
lws_write( wsi, | ||
&received_payload.data[LWS_SEND_BUFFER_PRE_PADDING], | ||
received_payload.len, | ||
LWS_WRITE_TEXT ); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int | ||
SizeOfInformation ( | ||
) | ||
{ | ||
int Acumulator = 0; | ||
|
||
Acumulator += strlen(Computer.Name); | ||
Acumulator += strlen(Computer.Linux); | ||
Acumulator += strlen(Computer.ApplicationVersion); | ||
|
||
return Acumulator; | ||
} | ||
|
||
void | ||
InitializeAboutProtocol ( | ||
) | ||
{ | ||
FILE *ComputerInformation = popen("uname -a", "r"); | ||
char Buffer[256]; | ||
char * Pointer = NULL; | ||
|
||
while (fgets(Buffer, sizeof(Buffer), ComputerInformation) != 0) { | ||
strtok(Buffer, " "); | ||
|
||
Pointer = strtok(NULL, " "); | ||
Computer.Name = malloc(sizeof((strlen(Pointer) + 1) * char)); | ||
strcpy (Computer.Name, Pointer); | ||
|
||
Pointer = strtok(NULL, " "); | ||
Computer.Linux = malloc(sizeof((strlen(Pointer) + 1) * char)); | ||
strcpy (Computer.Linux, Pointer); | ||
|
||
Computer.ApplicationVersion = malloc(sizeof((strlen(APPLICATION_VERSION) + 1) * char)); | ||
strcpy (Computer.ApplicationVersion, APPLICATION_VERSION); | ||
} | ||
|
||
pclose(ComputerInformation); | ||
} |
Oops, something went wrong.