/
ihtiandr9
/
httpserver
Обзор
Документация
Войти
/
ihtiandr9
/
httpserver
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
class-stylesheet
cpp/src/main.cpp
81 строка
2 KB
lomaster
stylesheet class
01 фев 2026, 10:19
01 фев 2026, 10:19
3f10474
Код
Авторство
О чём код?
#include <iostream> #include <getopt.h> #include <httplib.h> #include "server.h" #include "dbclient.h" static void exit_nicely(int err) { // close the connection to the database and cleanup dbclose(); exit(err); } void usage(int panic){ fprintf(stderr, "No password provided\n"); fprintf(stderr, "Usage: httpserver [ -h | --host host] -p password\n"); if (panic){ exit_nicely(-1); } } static struct option opts[] = { {"host", required_argument, 0, 'h'}, {"passwd", required_argument, 0, 'p'}, {"version", no_argument, 0, 'v'}, {0, 0, 0, 0}}; static const char *host = default_dbhost; static const char *passwd = 0; int main(int argc, char* argv[]) { httplib::Server svr; int rez; int long_index; if (argc < 2) usage(1); while (-1 != (rez = getopt_long(argc, argv, "h:p:v", opts, &long_index))) { switch (rez) { case 'h': if (optarg) { host = optarg; } break; case 'p': if (optarg) { passwd = optarg; } break; case 'v': printf("V1.0\n"); exit_nicely(0); break; default: fprintf(stderr, "Unknown option: %c\n", rez); exit_nicely(-1); } } if (!passwd) usage(1); if (!(dbopen(host, passwd) == 0)) { fprintf(stderr, "Cant open database\n"); exit_nicely(-1); } run_server(svr); exit_nicely(0); return 0; }