Refactor wsssht.c: Split large monolithic file into modular components

- Created libwsssht/ directory with modular components:
  * utils.h/c: Utility functions (print_usage, parse_connection_string, parse_args)
  * modes.h/c: Mode-specific functions (bridge, script, daemon modes)
  * threads.h/c: Thread-related functions and structures
  * wsssht.h: Main header with includes and declarations

- Reduced wsssht.c from 2769 lines to 674 lines (main function only)
- Updated Makefile and configure.sh to handle new modular structure
- Maintained exact same functionality and command-line interface
- Improved code maintainability and organization

All functionality preserved, build successful, and wsssht binary works correctly.
parent 8b1388b8
......@@ -56,7 +56,7 @@ CFLAGS = -Wall -Wextra -O2 -D_GNU_SOURCE $(shell pkg-config --cflags openssl)
LDFLAGS = $(shell pkg-config --libs openssl)
# Source files
LIB_SRCS = wssshlib.c websocket.c wssh_ssl.c tunnel.c
LIB_SRCS = wssshlib.c websocket.c wssh_ssl.c tunnel.c libwsssht/utils.c libwsssht/modes.c libwsssht/threads.c
LIB_OBJS = $(LIB_SRCS:.c=.o)
SRCS = wssshc.c wsssh.c wsscp.c wsssht.c
OBJS = $(SRCS:.c=.o)
......@@ -69,13 +69,13 @@ MANPAGES = man/wssshc.1 man/wsssh.1 man/wsscp.1 man/wsssht.1
all: $(TARGETS)
# Individual targets
wssshc: wssshc.o $(LIB_OBJS)
wssshc: wssshc.o wssshlib.o websocket.o wssh_ssl.o tunnel.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
wsssh: wsssh.o $(LIB_OBJS)
wsssh: wsssh.o wssshlib.o websocket.o wssh_ssl.o tunnel.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
wsscp: wsscp.o $(LIB_OBJS)
wsscp: wsscp.o wssshlib.o websocket.o wssh_ssl.o tunnel.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
wsssht: wsssht.o $(LIB_OBJS)
......@@ -87,7 +87,7 @@ wsssht: wsssht.o $(LIB_OBJS)
# Clean
clean:
rm -f $(OBJS) $(LIB_OBJS) $(TARGETS)
rm -f $(OBJS) $(LIB_OBJS) $(TARGETS) libwsssht/*.o
# Install (optional)
install: all
......
This diff is collapsed.
/*
* WebSocket SSH Tunnel (wsssht) - Mode Functions
* Mode-specific functions for wsssht
*
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#ifndef MODES_H
#define MODES_H
#include "../wssshlib.h"
// Function declarations for mode-specific functions
int run_bridge_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
int run_script_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
int run_daemon_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
#endif // MODES_H
\ No newline at end of file
This diff is collapsed.
/*
* WebSocket SSH Tunnel (wsssht) - Thread Functions
* Thread-related functions for wsssht
*
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#ifndef THREADS_H
#define THREADS_H
#include "wsssht.h"
// Function declarations for thread functions
void *run_tunnel_thread(void *arg);
#endif // THREADS_H
\ No newline at end of file
This diff is collapsed.
/*
* WebSocket SSH Tunnel (wsssht) - Utility Functions
* Utility functions for wsssht
*
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#ifndef UTILS_H
#define UTILS_H
#include "../wssshlib.h"
// Function declarations for utility functions
void print_usage(const char *program_name);
int parse_connection_string(const char *conn_str, char **service, char **client_id, char **wssshd_host, int *wssshd_port);
int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_argc, char ***remaining_argv);
#endif // UTILS_H
\ No newline at end of file
/*
* WebSocket SSH Tunnel (wsssht) - C Implementation
* WebSocket tunnel setup tool for manual connections.
*
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#ifndef WSSSHT_H
#define WSSSHT_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <getopt.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <pthread.h>
#include <sys/select.h>
#include "../wssshlib.h"
#include "../websocket.h"
#include "../wssh_ssl.h"
#include "../tunnel.h"
// Thread arguments structure for concurrent tunnel handling
typedef struct {
int accepted_sock;
wsssh_config_t *config;
const char *client_id;
const char *wssshd_host;
int wssshd_port;
const char *tunnel_host;
} tunnel_thread_args_t;
// Function declarations
void print_usage(const char *program_name);
int parse_connection_string(const char *conn_str, char **service, char **client_id, char **wssshd_host, int *wssshd_port);
int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_argc, char ***remaining_argv);
int run_bridge_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
int run_script_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
int run_daemon_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
void *run_tunnel_thread(void *arg);
#endif // WSSSHT_H
\ No newline at end of file
No preview for this file type
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment