⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin.cpp

📁 可用该程序将avi的电影文件转化为TS流
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** admin.cpp:*-------------------------------------------------------------------------------* (c)1999-2001 VideoLAN* $Id: admin.cpp,v 1.15 2002/09/30 15:17:53 jpsaman Exp $** Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>** 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 2* 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, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.**-------------------------------------------------------------------------------********************************************************************************///------------------------------------------------------------------------------// Preamble//------------------------------------------------------------------------------#include "../core/defs.h"#ifdef HAVE_CRYPT_H#include <crypt.h>#endif#include "config.h"#include "../core/core.h"#include "../core/network.h"#include "request.h"#include "admin.h"#include "telnet.h"#include "nativeadmin.h"#include "../core/network.cpp"/******************************************************************************** C_C_CommandDesc class****************************************************************************************************************************************************************///------------------------------------------------------------------------------// Constructor//------------------------------------------------------------------------------C_CommandDesc::C_CommandDesc(const C_String& strName,                             const C_String& strHelp,                             const C_String& strLongHelp) :                     m_strName(strName),                     m_strHelp(strHelp),                     m_strLongHelp(strLongHelp){  m_bExtendedOptions = false;}//------------------------------------------------------------------------------// Usage's auto-build from the current description//------------------------------------------------------------------------------void C_CommandDesc::BuildUsage(){  m_strUsage = "Usage: " + m_strName;  unsigned int ui;    for(ui = 0; ui < m_vMandatoryArgs.Size(); ui++)    m_strUsage += " <" + m_vMandatoryArgs[ui] + ">";  for(ui = 0; ui < m_vOptionalArgs.Size(); ui++)    m_strUsage += " [" + m_vOptionalArgs[ui] + "]";  for(ui = 0; ui < m_vOptions.Size(); ui++)    m_strUsage += " [--" + m_vOptions[ui] + " value]";  for(ui = 0; ui < m_vBooleans.Size(); ui++)    m_strUsage += " [--" + m_vBooleans[ui] + "]";  if(m_bExtendedOptions)    m_strUsage += " [--... value] [--...]";}/******************************************************************************** C_AdminGroup class****************************************************************************************************************************************************************///------------------------------------------------------------------------------// Constructor//------------------------------------------------------------------------------C_AdminGroup::C_AdminGroup(const C_String& strName) : m_strName(strName){}/******************************************************************************** C_AdminUser class****************************************************************************************************************************************************************///------------------------------------------------------------------------------// Constructor//------------------------------------------------------------------------------C_AdminUser::C_AdminUser(const C_String& strLogin,                         const C_String& strEncPasswd,                         C_AdminGroup* pGroup) : m_strLogin(strLogin),                                                 m_strEncPasswd(strEncPasswd){  m_pGroup = pGroup;}/******************************************************************************** C_AdminSession class****************************************************************************************************************************************************************///------------------------------------------------------------------------------// Constructor//------------------------------------------------------------------------------C_AdminSession::C_AdminSession(C_Admin* pAdmin){  ASSERT(pAdmin);  m_pAdmin = pAdmin;}//------------------------------------------------------------------------------// Destructor//------------------------------------------------------------------------------C_AdminSession::~C_AdminSession(){  // Does nothing but has to be virtual}//------------------------------------------------------------------------------////------------------------------------------------------------------------------void C_AdminSession::Init(){  OnInit();}//------------------------------------------------------------------------------////------------------------------------------------------------------------------void C_AdminSession::Close(){  OnClose();}//------------------------------------------------------------------------------////------------------------------------------------------------------------------int C_AdminSession::Authenticate(const C_String& strLogin,                                   const C_String& strPasswd){  return m_pAdmin->Authenticate(this, strLogin, strPasswd);}/******************************************************************************** C_Admin class****************************************************************************************************************************************************************/          //------------------------------------------------------------------------------// Constructor//------------------------------------------------------------------------------C_Admin::C_Admin(handle hLogger, C_RequestHub* pRequestHub){  ASSERT(hLogger);  ASSERT(pRequestHub);  m_hLog = hLogger;  m_pRequestHub = pRequestHub;  m_bRequestsEnabled = true; // m_pNativeAdmin = new C_NativeAdmin(m_hLog, this);  m_pTelnet = new C_Telnet(m_hLog, this);}//------------------------------------------------------------------------------// Destructor//------------------------------------------------------------------------------C_Admin::~C_Admin(){//  delete m_pNativeAdmin;  delete m_pTelnet;}//------------------------------------------------------------------------------// Initialization//------------------------------------------------------------------------------int C_Admin::Init(){  C_Application* pApp = C_Application::GetApp();  int iRc = 0;  // Commands' descriptions  // -- help [command]  C_CommandDesc* pCmdDesc = new C_CommandDesc("help",        "gives help on the specified command.",        "Called with no argument, \"help\" gives the list of all the commands"                " (available or not). Called with one argument it gives"                " details about how to use the specified command.");  C_String* pStr = new C_String("command");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- browse [input]  pCmdDesc = new C_CommandDesc("browse",        "gives the program list",        "Called with one argument, \"browse\" gives all programs of inputs."                " Called with one argument it only gives the programs of the"                " specified input. Each program is given with its status.");  pStr = new C_String("input");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- show [broadcast|channel|program|input]  pCmdDesc = new C_CommandDesc("show",        "show running broadcasts, available channels, programs or inputs",        "Called with one argument, \"show\" gives information about "                " running broadcasts or available channels, programs or inputs.");  pStr = new C_String("command");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- config <filename> [--load] [--save]  pCmdDesc = new C_CommandDesc("config",        "load and save configuration file.",        "\"config\" loads or saves a configuration to a specified file."                " It stops all broadcasts before clearing the current configuration."                " After load the new configuration becomes available for broadcast.");  pStr = new C_String("load");  pCmdDesc->m_vBooleans.Add(pStr);  pStr = new C_String("save");  pCmdDesc->m_vBooleans.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- program <name> <input> <filename> <type> [--add] [--delete]  pCmdDesc = new C_CommandDesc("program",        "configure an input with programs.",        "\"program\" adds a program definition to a specified input"                " it becomes available for broadcast.");  pStr = new C_String("name");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("input");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("filename");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("type");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  // add or delete  pStr = new C_String("add");  pCmdDesc->m_vBooleans.Add(pStr);  pStr = new C_String("delete");  pCmdDesc->m_vBooleans.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- input <name> <type=local> [dir] [--add] [--delete]  // -- input <name> <type=video> [device] [format] [--add] [--delete]  // -- input <name> <type=dvb> [device number] [device type=nova] [frequency] [polarization]  //          [symbol rate] [diseqc] [lnb_lof1] [lnb_lof2] [lnb_slof] [--add] [--delete]  pCmdDesc = new C_CommandDesc("input",        "configure a new input.",        "\"input\" adds a input definition of type local, video or dvb."                " it becomes available for broadcast and program configuration.");  pStr = new C_String("name");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("type");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  // for type=local  pStr = new C_String("dir");  pCmdDesc->m_vOptionalArgs.Add(pStr);  // for type=video  pStr = new C_String("device");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("format");  pCmdDesc->m_vOptionalArgs.Add(pStr);  // for type=dvb  pStr = new C_String("device_number");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("device_type");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("frequency");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("polarization");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("symbol_rate");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("use_disecq");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("lnb_lof1");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("lnb_lof2");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("lnb_slof");  pCmdDesc->m_vOptionalArgs.Add(pStr);  // add or delete  pStr = new C_String("add");  pCmdDesc->m_vBooleans.Add(pStr);  pStr = new C_String("delete");  pCmdDesc->m_vBooleans.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- channel <name> <type> <dest_host> <dest_port> <streamtype> [domain] [ttl] [intf] [--add] [--delete]  pCmdDesc = new C_CommandDesc("channel",        "configure a new channel.",        "\"channel\" adds a channel definition."                " it becomes available for broadcast.");  pStr = new C_String("name");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("type");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("dest_host");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("dest_port");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("stream_type");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("domain");  // Optional arguments  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("ttl");  pCmdDesc->m_vOptionalArgs.Add(pStr);  pStr = new C_String("interface");  pCmdDesc->m_vOptionalArgs.Add(pStr);  // Boolean options  pStr = new C_String("add");  pCmdDesc->m_vBooleans.Add(pStr);  pStr = new C_String("delete");  pCmdDesc->m_vBooleans.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- start <program> <channel> <input> [--loop] [--end] [--rtp]  pCmdDesc = new C_CommandDesc("start",        "launches a program.",        "\"start\" launches the specified program of the specified input"                " and broadcasts it through the specified channel.");  pStr = new C_String("program");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("channel");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("input");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pStr = new C_String("loop");  pCmdDesc->m_vBooleans.Add(pStr);  pStr = new C_String("end"); // jump to end of file  pCmdDesc->m_vBooleans.Add(pStr);  pStr = new C_String("rtp");  pCmdDesc->m_vBooleans.Add(pStr);  pCmdDesc->m_bExtendedOptions = true;  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- resume <channel>  pCmdDesc = new C_CommandDesc("resume",        "resumes streaming.",        "\"resume\" resumes the broadcast to specified channel.");  pStr = new C_String("channel");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- suspend <channel>  pCmdDesc = new C_CommandDesc("suspend",        "suspends streaming.",        "\"suspend\" suspends the broadcast to the specified channel.");  pStr = new C_String("channel");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- stop <channel>  pCmdDesc = new C_CommandDesc("stop",        "stops a program.",        "\"stop\" ends the broadcast to the specified channel.");  pStr = new C_String("channel");  pCmdDesc->m_vMandatoryArgs.Add(pStr);  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- shutdown  pCmdDesc = new C_CommandDesc("shutdown",        "stops the server.",        "\"shutdown\" stops all the programs and then the VideoLAN Server"                " stops.");  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // -- logout  pCmdDesc = new C_CommandDesc("logout",        "terminates the administration session.",        "\"logout\" closes the current administration session and the remote"                " connection.");  pCmdDesc->BuildUsage();  m_cCmdDescriptions.Add(pCmdDesc->m_strName, pCmdDesc);  // Groups  C_Vector<C_Setting> vGroups = pApp->GetSettings("Groups");  for(unsigned int ui = 0; ui < vGroups.Size(); ui++)  {    C_Setting cCurrent = vGroups[ui];    C_String strGroupName = cCurrent.GetName();    if(m_cGroups.Get(strGroupName))    {      Log(m_hLog, LOG_ERROR,          "Admin group \"" + strGroupName + "\" already exists");      iRc = GEN_ERR;      break;    }    C_AdminGroup* pGroup = new C_AdminGroup(strGroupName);    ASSERT(pGroup);    C_String strCommands = cCurrent.GetValue();    C_StringTokenizer cTokenizer(strCommands, '|');    while(cTokenizer.HasMoreToken())    {      C_String strCmd = cTokenizer.NextToken();      pCmdDesc = m_cCmdDescriptions.Get(strCmd);      if(!pCmdDesc)      {        Log(m_hLog, LOG_ERROR, "Admin group \"" + strGroupName +            "\" not valid (the command \"" + strCmd + "\" doesn't exist)");        delete pGroup;        iRc = GEN_ERR;        break;      }      C_String* pstrCmd = new C_String(strCmd);      pGroup->m_vCommands.Add(pstrCmd);    }    Log(m_hLog, LOG_NOTE, "New admin group \"" + strGroupName + "\" is ok");    m_cGroups.Add(strGroupName, pGroup);  }  // Users  if(!iRc)  {    C_Vector<C_Setting> vUsers = pApp->GetSettings("Users");    for(unsigned int ui = 0; ui < vUsers.Size(); ui++)    {      C_Setting cCurrent = vUsers[ui];      C_String strUserLogin = cCurrent.GetName();      if(m_cUsers.Get(strUserLogin))      {        Log(m_hLog, LOG_ERROR,            "Admin user \"" + strUserLogin + "\" already exists");        iRc = GEN_ERR;        break;      }      C_String strUserInfo = cCurrent.GetValue();      C_StringTokenizer cTokenizer(strUserInfo, ':');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -