-
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.
Add confing.yaml file and parse configure information from it
- Loading branch information
Showing
5 changed files
with
68 additions
and
5 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
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,3 @@ | ||
server: | ||
listen_host: "0.0.0.0" # server 端监听的主机地址 | ||
listen_port: 2222 # 命令连接的监听的端口 |
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,32 @@ | ||
// | ||
// Created by MLee on 2019/12/31. | ||
// | ||
|
||
#include "configure.h" | ||
#include "common.h" | ||
#include "utility.h" | ||
|
||
namespace configure { | ||
const char *config_file = "config.yaml"; /* 配置文件 */ | ||
|
||
std::string SERVER_LISTEN_HOST; | ||
int SERVER_LISTEN_PORT; | ||
|
||
void parse_config_file() { | ||
YAML::Node node = YAML::LoadFile(configure::config_file); | ||
|
||
if (!node["server"].IsDefined()) { | ||
std::cerr << "Server config information isn't configured correctly" << std::endl; | ||
return; | ||
} | ||
|
||
auto server_config = node["server"]; | ||
SERVER_LISTEN_HOST = server_config["listen_host"].as<std::string>(); | ||
SERVER_LISTEN_PORT = server_config["listen_port"].as<int>(); | ||
|
||
utility::debug_info(std::string("Server listen host: ") + SERVER_LISTEN_HOST); | ||
utility::debug_info(std::string("Server listen port: ") + std::to_string(SERVER_LISTEN_PORT)); | ||
|
||
} | ||
|
||
} |
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,20 @@ | ||
// | ||
// Created by MLee on 2019/12/31. | ||
// | ||
|
||
#ifndef MINIFTPD_CONFIGURE_H | ||
#define MINIFTPD_CONFIGURE_H | ||
|
||
#include <string> | ||
#include "../include/yaml-cpp/yaml.h" | ||
|
||
namespace configure { | ||
/* 配置信息 */ | ||
extern std::string SERVER_LISTEN_HOST; | ||
extern int SERVER_LISTEN_PORT; | ||
|
||
void parse_config_file(); /* 从配置文件中解析配置信息 */ | ||
|
||
} | ||
|
||
#endif //MINIFTPD_CONFIGURE_H |
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