windows下添加telnet的支持

This commit is contained in:
xiongziliang
2017-08-10 16:16:42 +08:00
parent 0d03ae6cd2
commit 51eebe112e
8 changed files with 1240 additions and 35 deletions

View File

@@ -26,7 +26,7 @@ CMD::~CMD() {
CMD_help::CMD_help() {
parser.reset( new OptionParser(nullptr));
(*parser) << Option('c', "cmd", Option::ArgNone, "列出所有命令", [](OutStream *stream,const char *arg) {
(*parser) << Option('c', "cmd", Option::ArgNone, "list all command", [](OutStream *stream,const char *arg) {
_StrPrinter printer;
for (auto &pr : ShellSession::g_mapCmd) {
printer << "\t" << pr.first << ":" << pr.second.description() << "\r\n";
@@ -38,7 +38,7 @@ CMD_help::CMD_help() {
CMD_rtsp::CMD_rtsp() {
parser.reset(new OptionParser(nullptr));
(*parser) << Option('l', "list", Option::ArgNone, "列出所有媒体列表", [](OutStream *stream,const char *arg) {
(*parser) << Option('l', "list", Option::ArgNone, "list all media source of rtsp", [](OutStream *stream,const char *arg) {
_StrPrinter printer;
auto mediaSet = RtspMediaSource::getMediaSet();
for (auto &src : mediaSet) {
@@ -51,7 +51,7 @@ CMD_rtsp::CMD_rtsp() {
CMD_rtmp::CMD_rtmp() {
parser.reset(new OptionParser(nullptr));
(*parser) << Option('l', "list", Option::ArgNone, "列出所有媒体列表", [](OutStream *stream,const char *arg) {
(*parser) << Option('l', "list", Option::ArgNone, "list all media source of rtmp", [](OutStream *stream,const char *arg) {
_StrPrinter printer;
auto mediaSet = RtmpMediaSource::getMediaSet();
for (auto &src : mediaSet) {

View File

@@ -8,9 +8,11 @@
#ifndef SRC_SHELL_CMD_H_
#define SRC_SHELL_CMD_H_
#if !defined(_WIN32)
#if defined(_WIN32)
#include "win32/getopt.h"
#else
#include <getopt.h>
#endif //!defined(_WIN32)
#endif //defined(_WIN32)
#include <string>
#include <vector>
@@ -72,7 +74,7 @@ public:
typedef function< void(OutStream *stream, const unordered_multimap<char, string> &)> OptionCompleted;
OptionParser(const OptionCompleted &_cb) {
onCompleted = _cb;
helper = Option('h', "help", Option::ArgNone, "print this help", [this](OutStream *stream,const char *arg)->bool {
helper = Option('h', "help", Option::ArgNone, "print this message", [this](OutStream *stream,const char *arg)->bool {
_StrPrinter printer;
for (auto &pr : options) {
printer<<"\t-"<<pr.first<<"\t--"<<pr.second.longOpt<<"\t"<<pr.second.des<<"\r\n";
@@ -95,7 +97,7 @@ public:
struct option tmp;
for (auto &pr : options) {
//long opt
tmp.name = pr.second.longOpt.data();
tmp.name = (char *)pr.second.longOpt.data();
tmp.has_arg = pr.second.argType;
tmp.flag = NULL;
tmp.val = pr.first;
@@ -128,7 +130,7 @@ public:
while ((opt = getopt_long(argc, argv, &str_shortOpt[0], &vec_longOpt[0],NULL)) != -1) {
auto it = options.find(opt);
if (it == options.end()) {
string sendStr = StrPrinter << "\t无法识别的选项,请输入\"-h\"获取帮助.\r\n" << endl;
string sendStr = StrPrinter << "\tUnrecognized option. Enter \"-h\" to get help.\r\n" << endl;
stream->response(sendStr);
return true;
}

View File

@@ -112,8 +112,7 @@ inline bool ShellSession::onProcessLine(const string& line) {
string cmd = argv[0];
auto it = g_mapCmd.find(cmd);
if (it == g_mapCmd.end()) {
auto sendStr = StrPrinter << "\t未识别的命令\"" << cmd
<< "\",请输入\"help\"获取帮助.\r\n" << endl;
auto sendStr = StrPrinter << "\tUnrecognized option:\"" << cmd << "\",Enter \"help\" to get help.\r\n" << endl;
send(sendStr);
sendHead();
return true;