Browse Source

update: global help message

master
dnomd343 2 years ago
parent
commit
798e0f8b84
  1. 11
      include/help.h
  2. 66
      src/help.c
  3. 56
      src/local.c
  4. 50
      src/server.c

11
include/help.h

@ -0,0 +1,11 @@
#ifndef _HELP_H_
#define _HELP_H_
#define VERSION "0.9.0"
extern char *local_help_msg;
extern char *server_help_msg;
void is_show_help(int argc, char **argv, char *help_msg);
#endif

66
src/help.c

@ -0,0 +1,66 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "help.h"
char *server_help_msg = "\n\
ss-bootstrap-server\n\
\n\
A simple program to make the original shadowsocks support SIP003 plugins.\n\
\n\
-s <server_host> Host name or IP address of your remote server.\n\
-p <server_port> Port number of your remote server.\n\
-b <local_address> Local address to bind.\n\
-l <local_port> Port number of your local server.\n\
\n\
-c <config_file> Path to JSON config file.\n\
-k <password> Password of your remote server.\n\
-m <method> Encrypt method.\n\
-t <timeout> Socket timeout in seconds.\n\
--fast-open Enable TCP fast open (with Linux kernel 3.7+).\n\
--plugin <name> Enable SIP003 plugin.\n\
--plugin-opts <options> Set SIP003 plugin options.\n\
--shadowsocks <ssservre> Set shadowsocks server program.\n\
--no-udp Do not use UDP proxy.\n\
-h, --help Print this message.\n\
\n\
";
char *local_help_msg = "\n\
ss-bootstrap-local\n\
\n\
A simple program to make the original shadowsocks support SIP003 plugins.\n\
\n\
-s <server_host> Host name or IP address of your remote server.\n\
-p <server_port> Port number of your remote server.\n\
-b <local_address> Local address to bind.\n\
-l <local_port> Port number of your local server.\n\
\n\
-c <config_file> Path to JSON config file.\n\
-k <password> Password of your remote server.\n\
-m <method> Encrypt method.\n\
-t <timeout> Socket timeout in seconds.\n\
--fast-open Enable TCP fast open (with Linux kernel 3.7+).\n\
--plugin <name> Enable SIP003 plugin.\n\
--plugin-opts <options> Set SIP003 plugin options.\n\
--shadowsocks <sslocal> Set shadowsocks local program.\n\
--no-udp Do not use UDP proxy.\n\
-h, --help Print this message.\n\
\n\
";
void show_help(char *help_msg) {
printf("%s", help_msg);
exit(0); // exit normally
}
void is_show_help(int argc, char **argv, char *help_msg) { // output help when necessary
if (argc <= 1) { // with only one argument
show_help(help_msg);
}
for (int i = 0; i < argc; ++i) {
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { // include `-h` or `--help`
show_help(help_msg);
}
}
}

56
src/local.c

@ -3,59 +3,15 @@
#include <string.h>
#include "common.h"
#include "process.h"
#include "help.h"
#include "log.h"
#define SHADOWSOCKS_DEFAULT "sslocal"
char *help_msg =
"\
\n\
ss-bootstrap-local\n\
\n\
A simple program to make the original shadowsocks support SIP003 plugins.\n\
\n\
-s <server_host> Host name or IP address of your remote server.\n\
-p <server_port> Port number of your remote server.\n\
-b <local_address> Local address to bind.\n\
-l <local_port> Port number of your local server.\n\
\n\
-c <config_file> Path to JSON config file.\n\
-k <password> Password of your remote server.\n\
-m <method> Encrypt method.\n\
-t <timeout> Socket timeout in seconds.\n\
--fast-open Enable TCP fast open (with Linux kernel 3.7+).\n\
--plugin <name> Enable SIP003 plugin.\n\
--plugin-opts <options> Set SIP003 plugin options.\n\
--shadowsocks <sslocal> Set shadowsocks local program.\n\
--no-udp Do not use UDP proxy.\n\
-h, --help Print this message.\n\
\n\
";
void show_help() { // show help message
printf("%s", help_msg);
exit(0); // exit normally
}
int main(int argc, char *argv[]) {
int i;
log_debug("%s", "shadowsocks-bootstrap log level debug");
log_info("%s", "shadowsocks-bootstrap log level info");
log_warn("%s", "shadowsocks-bootstrap log level warn");
log_error("%s", "shadowsocks-bootstrap log level error");
log_fatal("%s", "shadowsocks-bootstrap log level fatal");
is_show_help(argc, argv, local_help_msg);
log_info("Shadowsocks bootstrap local (%s)", VERSION);
// if (argc <= 1) {
// show_help();
// }
// for (i = 0; i < argc; ++i) {
// if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
// show_help();
// }
// }
// args_decode(argc, argv);
// params_load(SHADOWSOCKS_DEFAULT); // default file name
// start_bootstrap(SHADOWSOCKS_DEFAULT, is_udp_proxy); // local or server mode
args_decode(argc, argv);
params_load("sslocal"); // default file name
start_bootstrap("sslocal", is_udp_proxy); // local or server mode
return 0;
}

50
src/server.c

@ -3,51 +3,15 @@
#include <string.h>
#include "common.h"
#include "process.h"
#define SHADOWSOCKS_DEFAULT "ssserver"
char *help_msg =
"\
\n\
ss-bootstrap-server\n\
\n\
A simple program to make the original shadowsocks support SIP003 plugins.\n\
\n\
-s <server_host> Host name or IP address of your remote server.\n\
-p <server_port> Port number of your remote server.\n\
-b <local_address> Local address to bind.\n\
-l <local_port> Port number of your local server.\n\
\n\
-c <config_file> Path to JSON config file.\n\
-k <password> Password of your remote server.\n\
-m <method> Encrypt method.\n\
-t <timeout> Socket timeout in seconds.\n\
--fast-open Enable TCP fast open (with Linux kernel 3.7+).\n\
--plugin <name> Enable SIP003 plugin.\n\
--plugin-opts <options> Set SIP003 plugin options.\n\
--shadowsocks <ssservre> Set shadowsocks server program.\n\
--no-udp Do not use UDP proxy.\n\
-h, --help Print this message.\n\
\n\
";
void show_help() { // show help message
printf("%s", help_msg);
exit(0); // exit normally
}
#include "help.h"
#include "log.h"
int main(int argc, char *argv[]) {
int i;
if (argc <= 1) {
show_help();
}
for (i = 0; i < argc; ++i) {
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
show_help();
}
}
is_show_help(argc, argv, server_help_msg);
log_info("Shadowsocks bootstrap server (%s)", VERSION);
args_decode(argc, argv);
params_load(SHADOWSOCKS_DEFAULT); // default file name
start_bootstrap(SHADOWSOCKS_DEFAULT, is_udp_proxy); // local or server mode
params_load("ssserver"); // default file name
start_bootstrap("ssserver", is_udp_proxy); // local or server mode
return 0;
}

Loading…
Cancel
Save