📄 servmgr.cpp.svn-base
字号:
servMgr->numFilters = 0; showLog = 0; if (iniFile.openReadOnly(fn)) { while (iniFile.readNext()) { // server settings if (iniFile.isName("serverPort")) servMgr->serverHost.port = iniFile.getIntValue(); else if (iniFile.isName("autoServe")) servMgr->autoServe = iniFile.getBoolValue(); else if (iniFile.isName("autoConnect")) servMgr->autoConnect = iniFile.getBoolValue(); else if (iniFile.isName("icyPassword")) // depreciated strcpy(servMgr->password,iniFile.getStrValue()); else if (iniFile.isName("forceIP")) { strcpy(servMgr->forceIP,iniFile.getStrValue()); if (strlen(servMgr->forceIP)) servMgr->serverHost.ip = ClientSocket::getIP(servMgr->forceIP); } else if (iniFile.isName("isRoot")) servMgr->isRoot = iniFile.getBoolValue(); else if (iniFile.isName("broadcastID")) chanMgr->broadcastID.fromStr(iniFile.getStrValue());
else if (iniFile.isName("htmlPath"))
strcpy(servMgr->htmlPath,iniFile.getStrValue());
else if (iniFile.isName("useIPSalt"))
servMgr->useIPSalt = iniFile.getBoolValue();
else if (iniFile.isName("maxControlConnections"))
{
servMgr->maxControl = iniFile.getIntValue();
} else if (iniFile.isName("maxBitrate")) servMgr->maxBitrate = iniFile.getIntValue(); else if (iniFile.isName("maxStreams")) servMgr->maxStreams = iniFile.getIntValue(); else if (iniFile.isName("maxStreamsPerChannel")) chanMgr->maxStreamsPerChannel = iniFile.getIntValue(); else if (iniFile.isName("firewallTimeout")) firewallTimeout = iniFile.getIntValue(); else if (iniFile.isName("forceNormal")) forceNormal = iniFile.getBoolValue(); else if (iniFile.isName("broadcastMsgInterval")) chanMgr->broadcastMsgInterval = iniFile.getIntValue(); else if (iniFile.isName("broadcastMsg")) chanMgr->broadcastMsg.set(iniFile.getStrValue(),String::T_ASCII); else if (iniFile.isName("hostUpdateInterval"))
chanMgr->hostUpdateInterval = iniFile.getIntValue();
else if (iniFile.isName("icyMetaInterval")) chanMgr->icyMetaInterval = iniFile.getIntValue();
else if (iniFile.isName("rootMsg")) rootMsg.set(iniFile.getStrValue()); else if (iniFile.isName("networkID")) networkID.fromStr(iniFile.getStrValue()); else if (iniFile.isName("authType")) { char *t = iniFile.getStrValue(); if (stricmp(t,"cookie")==0) servMgr->authType = ServMgr::AUTH_COOKIE; else if (stricmp(t,"http-basic")==0) servMgr->authType = ServMgr::AUTH_HTTPBASIC; }else if (iniFile.isName("cookiesExpire")) { char *t = iniFile.getStrValue(); if (stricmp(t,"never")==0) servMgr->cookieList.neverExpire = true; else if (stricmp(t,"session")==0) servMgr->cookieList.neverExpire = false; } // privacy settings else if (iniFile.isName("password")) strcpy(servMgr->password,iniFile.getStrValue()); else if (iniFile.isName("maxUptime")) chanMgr->maxUptime = iniFile.getIntValue(); // client settings else if (iniFile.isName("rootHost"))
servMgr->rootHost = iniFile.getStrValue(); else if (iniFile.isName("deadHitAge")) chanMgr->deadHitAge = iniFile.getIntValue(); else if (iniFile.isName("tryoutDelay")) servMgr->tryoutDelay = iniFile.getIntValue(); else if (iniFile.isName("refreshHTML")) refreshHTML = iniFile.getIntValue(); else if (iniFile.isName("relayBroadcast")) { servMgr->relayBroadcast = iniFile.getIntValue(); if (servMgr->relayBroadcast < 30) servMgr->relayBroadcast = 30; } else if (iniFile.isName("minBroadcastTTL")) chanMgr->minBroadcastTTL = iniFile.getIntValue(); else if (iniFile.isName("maxBroadcastTTL")) chanMgr->maxBroadcastTTL = iniFile.getIntValue(); else if (iniFile.isName("pushTimeout")) chanMgr->pushTimeout = iniFile.getIntValue(); else if (iniFile.isName("pushTries")) chanMgr->pushTries = iniFile.getIntValue(); else if (iniFile.isName("maxPushHops")) chanMgr->maxPushHops = iniFile.getIntValue(); else if (iniFile.isName("autoQuery")) { chanMgr->autoQuery = iniFile.getIntValue(); if ((chanMgr->autoQuery < 300) && (chanMgr->autoQuery > 0)) chanMgr->autoQuery = 300; } else if (iniFile.isName("queryTTL")) { servMgr->queryTTL = iniFile.getIntValue(); } // debug else if (iniFile.isName("logDebug")) showLog |= iniFile.getBoolValue() ? 1<<LogBuffer::T_DEBUG:0; else if (iniFile.isName("logErrors")) showLog |= iniFile.getBoolValue() ? 1<<LogBuffer::T_ERROR:0; else if (iniFile.isName("logNetwork")) showLog |= iniFile.getBoolValue() ? 1<<LogBuffer::T_NETWORK:0; else if (iniFile.isName("logChannel")) showLog |= iniFile.getBoolValue() ? 1<<LogBuffer::T_CHANNEL:0; else if (iniFile.isName("pauseLog")) pauseLog = iniFile.getBoolValue(); else if (iniFile.isName("idleSleepTime")) sys->idleSleepTime = iniFile.getIntValue(); else if (iniFile.isName("[Server1]")) allowServer1 = readServerSettings(iniFile,allowServer1); else if (iniFile.isName("[Server2]")) allowServer2 = readServerSettings(iniFile,allowServer2); else if (iniFile.isName("[Filter]")) { readFilterSettings(iniFile,filters[numFilters]); if (numFilters < (MAX_FILTERS-1)) numFilters++; } else if (iniFile.isName("[Notify]")) { notifyMask = NT_UPGRADE; while (iniFile.readNext()) { if (iniFile.isName("[End]")) break; else if (iniFile.isName("PeerCast")) notifyMask |= iniFile.getBoolValue()?NT_PEERCAST:0; else if (iniFile.isName("Broadcasters")) notifyMask |= iniFile.getBoolValue()?NT_BROADCASTERS:0; else if (iniFile.isName("TrackInfo")) notifyMask |= iniFile.getBoolValue()?NT_TRACKINFO:0; } } else if (iniFile.isName("[RelayChannel]")) { ChanInfo info; bool stayConnected=false; String sourceURL; while (iniFile.readNext()) { if (iniFile.isName("[End]")) break; else if (iniFile.isName("name")) info.name.set(iniFile.getStrValue()); else if (iniFile.isName("id")) info.id.fromStr(iniFile.getStrValue()); else if (iniFile.isName("sourceType")) info.srcProtocol = ChanInfo::getProtocolFromStr(iniFile.getStrValue()); else if (iniFile.isName("contentType")) info.contentType = ChanInfo::getTypeFromStr(iniFile.getStrValue()); else if (iniFile.isName("stayConnected")) stayConnected = iniFile.getBoolValue(); else if (iniFile.isName("sourceURL")) sourceURL.set(iniFile.getStrValue()); else if (iniFile.isName("genre")) info.genre.set(iniFile.getStrValue()); else if (iniFile.isName("contactURL")) info.url.set(iniFile.getStrValue()); else if (iniFile.isName("bitrate")) info.bitrate = atoi(iniFile.getStrValue()); else if (iniFile.isName("tracker"))
{
ChanHit hit;
hit.init();
hit.tracker = true;
hit.host.fromStrName(iniFile.getStrValue(),DEFAULT_PORT);
hit.rhost[0] = hit.host;
hit.rhost[1] = hit.host;
chanMgr->addHit(info.id,hit);
}
} if (sourceURL.isEmpty()) { chanMgr->createRelay(info,stayConnected); }else { Channel *c = chanMgr->createChannel(info,NULL); if (c) c->startURL(sourceURL.cstr()); } } else if (iniFile.isName("[Host]")) { Host h; ServHost::TYPE type=ServHost::T_NONE;
bool firewalled=false; unsigned int time=0; while (iniFile.readNext()) { if (iniFile.isName("[End]")) break; else if (iniFile.isName("address")) h.fromStrIP(iniFile.getStrValue(),DEFAULT_PORT); else if (iniFile.isName("type")) type = ServHost::getTypeFromStr(iniFile.getStrValue()); else if (iniFile.isName("time")) time = iniFile.getIntValue(); } servMgr->addHost(h,type,time); } } } if (!numFilters) setFilterDefaults();}
// --------------------------------------------------
unsigned int ServMgr::numStreams(GnuID &cid, ChanInfo::PROTOCOL proto)
{
int cnt = 0;
Servent *sv = servents;
while (sv)
{
if (sv->isConnected())
if (sv->type == Servent::T_STREAM)
if (sv->chanID.isSame(cid))
if (sv->outputProtocol == proto)
cnt++;
sv=sv->next;
}
return cnt;
}
// --------------------------------------------------
unsigned int ServMgr::numStreams(ChanInfo::PROTOCOL proto)
{
int cnt = 0;
Servent *sv = servents;
while (sv)
{
if (sv->isConnected())
if (sv->type == Servent::T_STREAM)
if (sv->outputProtocol == proto)
cnt++;
sv=sv->next;
}
return cnt;
}
// --------------------------------------------------
bool ServMgr::getChannel(char *str,ChanInfo &info, bool relay)
{
// remove file extension (only added for winamp)
//char *ext = strstr(str,".");
//if (ext) *ext = 0;
procConnectArgs(str,info);
Channel *ch;
ch = chanMgr->findChannelByNameID(info);
if (ch)
{
if (!ch->isPlaying())
{
if (relay)
ch->info.lastPlayTime = 0; // force reconnect
else
return false;
}
info = ch->info; // get updated channel info
return true;
}else
{
if (relay)
{
ch = chanMgr->findAndRelay(info);
if (ch)
{
info = ch->info; //get updated channel info
return true;
}
}
}
return false;
}
// --------------------------------------------------int ServMgr::findChannel(ChanInfo &info){
#if 0 char idStr[64]; info.id.toStr(idStr); if (info.id.isSet()) { // if we have an ID then try and connect to known hosts carrying channel. ServHost sh = getOutgoingServent(info.id); addOutgoing(sh.host,info.id,true); } GnuPacket pack; XML xml; XML::Node *n = info.createQueryXML(); xml.setRoot(n); pack.initFind(NULL,&xml,servMgr->queryTTL); addReplyID(pack.id); int cnt = broadcast(pack,NULL); LOG_NETWORK("Querying network: %s %s - %d servents",info.name.cstr(),idStr,cnt); return cnt;
#endif
return 0;}// --------------------------------------------------// add outgoing network connection from string (ip:port format)bool ServMgr::addOutgoing(Host h, GnuID &netid, bool pri){
#if 0 if (h.ip) { if (!findServent(h.ip,h.port,netid)) { Servent *sv = allocServent(); if (sv) { if (pri) sv->priorityConnect = true; sv->networkID = netid; sv->initOutgoing(h,Servent::T_OUTGOING); return true; } } }#endif
return false;}// --------------------------------------------------
Servent *ServMgr::findConnection(Servent::TYPE t,GnuID &sid)
{
Servent *sv = servents;
while (sv)
{
if (sv->isConnected())
if (sv->type == t)
if (sv->remoteID.isSame(sid))
return sv;
sv=sv->next;
}
return NULL;
}
// --------------------------------------------------void ServMgr::procConnectArgs(char *str,ChanInfo &info){ char arg[512]; char curr[256];
char *args = strstr(str,"?");
if (args)
*args++=0;
info.initNameID(str);
if (args) { while (args=nextCGIarg(args,curr,arg)) {
LOG_DEBUG("cmd: %s, arg: %s",curr,arg);
if (strcmp(curr,"sip")==0) // sip - add network connection to client with channel
{ Host h; h.fromStrName(arg,DEFAULT_PORT); if (addOutgoing(h,servMgr->networkID,true)) LOG_NETWORK("Added connection: %s",arg); }else if (strcmp(curr,"pip")==0) // pip - add private network connection to client with channel
{ Host h; h.fromStrName(arg,DEFAULT_PORT); if (addOutgoing(h,info.id,true)) LOG_NETWORK("Added private connection: %s",arg); }else if (strcmp(curr,"ip")==0)
// ip - add hit
{
Host h;
h.fromStrName(arg,DEFAULT_PORT);
ChanHit hit;
hit.init();
hit.host = h;
hit.rhost[0] = h;
hit.rhost[1].init();
chanMgr->addHit(info.id,hit);
}else if (strcmp(curr,"tip")==0)
// tip - add tracker hit
{
Host h;
h.fromStrName(arg,DEFAULT_PORT);
ChanHit hit;
hit.init();
hit.host = h;
hit.rhost[0] = h;
hit.rhost[1].init();
hit.tracker = true;
chanMgr->addHit(info.id,hit);
}
} }}// --------------------------------------------------bool ServMgr::start(){ static ThreadInfo serverThread,clientThread,idleThread,trackerThread;
char idStr[64];
sessionID.toStr(idStr);
LOG_DEBUG("SessionID: %s",idStr);
serverThread.func = ServMgr::serverProc; if (!sys->startThread(&serverThread)) return false;// clientThread.func = ServMgr::clientProc;// if (!sys->startThread(&clientThread))// return false; idleThread.func = ServMgr::idleProc; if (!sys->startThread(&idleThread)) return false;
// trackerThread.func = ServMgr::trackerProc;
// if (!sys->startThread(&trackerThread))
// return false;
return true;}// --------------------------------------------------int ServMgr::clientProc(ThreadInfo *thread){
#if 0 thread->lock(); GnuID netID; netID = servMgr->networkID; while(thread->active) { if (servMgr->autoConnect) { if (servMgr->needConnections() || servMgr->forceLookup) { if (servMgr->needHosts() || servMgr->forceLookup) { // do lookup to find some hosts Host lh; lh.fromStrName(servMgr->connectHost,DEFAULT_PORT); if (!servMgr->findServent(lh.ip,lh.port,netID)) { Servent *sv = servMgr->allocServent(); if (sv) { LOG_DEBUG("Lookup: %s",servMgr->connectHost);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -