00001 #include <Parse.h>
00002
00003 #include "SlaveHandler.h"
00004 #include "InternalSocket.h"
00005 #include "ProxyOutSocket.h"
00006 #include "SlaveSocket.h"
00007 #include "ProxyBinSocket.h"
00008
00009
00010 SlaveHandler::SlaveHandler()
00011 :SocketHandler()
00012 ,m_remote_port(23)
00013 {
00014 }
00015
00016
00017 SlaveHandler::SlaveHandler(StdLog *p)
00018 :SocketHandler(p)
00019 ,m_remote_port(23)
00020 {
00021 }
00022
00023
00024 SlaveHandler::~SlaveHandler()
00025 {
00026 }
00027
00028
00029 InternalSocket *SlaveHandler::GetSock(unsigned short id)
00030 {
00031 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
00032 {
00033 Socket *p0 = (*it).second;
00034 InternalSocket *p = dynamic_cast<InternalSocket *>(p0);
00035 if (p && p -> GetID() == id)
00036 {
00037 return p;
00038 }
00039 }
00040 return NULL;
00041 }
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 SlaveSocket *SlaveHandler::GetSlaveSocket()
00073 {
00074 for (socket_m::iterator it = m_sockets.begin(); it != m_sockets.end(); it++)
00075 {
00076 Socket *p0 = (*it).second;
00077 SlaveSocket *p = dynamic_cast<SlaveSocket *>(p0);
00078 if (p)
00079 {
00080 return p;
00081 }
00082 }
00083 return NULL;
00084 }
00085
00086
00087 void SlaveHandler::LoadConfig()
00088 {
00089 FILE *fil = fopen("slave.conf", "rt");
00090 if (fil)
00091 {
00092 char slask[1000];
00093 fgets(slask, 1000, fil);
00094 while (!feof(fil))
00095 {
00096 slask[strlen(slask) - 1] = 0;
00097 if (*slask && *slask != '#')
00098 {
00099 Parse pa(slask);
00100 std::string key = pa.getword();
00101 std::string value = pa.getrest();
00102 if (key == "remote_host")
00103 m_remote_host = value;
00104 else
00105 if (key == "remote_port")
00106 m_remote_port = atoi(value.c_str());
00107 }
00108
00109 fgets(slask, 1000, fil);
00110 }
00111 fclose(fil);
00112 }
00113 }
00114
00115
00116 void SlaveHandler::SaveConfig()
00117 {
00118 FILE *fil = fopen("slave.conf", "wt");
00119 if (fil)
00120 {
00121 fprintf(fil, "remote_host %s\n", m_remote_host.c_str());
00122 fprintf(fil, "remote_port %u\n", m_remote_port);
00123 fclose(fil);
00124 }
00125 }
00126
00127