QTSS_Error RedisGetAssociatedDarwin(QTSS_GetAssociatedDarwin_Params* inParams) { OSMutexLocker mutexLock(&sMutex); if (!RedisConnect()) { return QTSS_NotConnected; } QTSS_Error theRet = QTSS_NoErr; do { string exists = Format("exists %s:%s/%s", string(EASY_REDIS_LIVE), string(inParams->inSerial), string(inParams->inChannel)); auto reply = static_cast<redisReply*>(redisCommand(redisContext_, exists.c_str())); RedisReplyObjectDeleter replyDeleter(reply); if (!reply) { theRet = QTSS_NotConnected; break; } if (reply->integer == 1) { string strTemp = Format("hmget %s:%s/%s %s", string(EASY_REDIS_LIVE), string(inParams->inSerial), string(inParams->inChannel), string(EASY_REDIS_EASYDARWIN)); auto replyHmget = static_cast<redisReply*>(redisCommand(redisContext_, strTemp.c_str())); RedisReplyObjectDeleter replyHmgetDeleter(replyHmget); if (!replyHmget) { theRet = QTSS_NotConnected; break; } string easydarwin = Format("%s:", string(EASY_REDIS_EASYDARWIN)); easydarwin += replyHmget->element[0]->str; strTemp = Format("hmget %s %s %s %s", easydarwin, string(EASY_REDIS_IP), string(EASY_REDIS_HTTP), string(EASY_REDIS_RTSP)); auto replyHmgetEasyDarwin = static_cast<redisReply*>(redisCommand(redisContext_, strTemp.c_str())); RedisReplyObjectDeleter replyHmgetEasyDarwinDeleter(replyHmgetEasyDarwin); if (!replyHmgetEasyDarwin) { theRet = QTSS_NotConnected; break; } if (replyHmgetEasyDarwin->type == EASY_REDIS_REPLY_NIL) { theRet = QTSS_RequestFailed; break;; } if (replyHmgetEasyDarwin->type == EASY_REDIS_REPLY_ARRAY && replyHmgetEasyDarwin->elements == 3) { bool ok = true; for (int i = 0; i < replyHmgetEasyDarwin->elements; ++i) { if (replyHmgetEasyDarwin->element[i]->type == EASY_REDIS_REPLY_NIL) { ok = ok && false; } } if (ok) { string ip(replyHmgetEasyDarwin->element[0]->str); string httpPort(replyHmgetEasyDarwin->element[1]->str); string rtspPort(replyHmgetEasyDarwin->element[2]->str); memcpy(inParams->outDssIP, ip.c_str(), ip.size()); memcpy(inParams->outHTTPPort, httpPort.c_str(), httpPort.size()); memcpy(inParams->outDssPort, rtspPort.c_str(), rtspPort.size()); inParams->isOn = true; } else { theRet = QTSS_RequestFailed; break; } } } else { string keys = Format("keys %s:*", string(EASY_REDIS_EASYDARWIN)); auto replyKeys = static_cast<redisReply*>(redisCommand(redisContext_, keys.c_str())); RedisReplyObjectDeleter replyKeysDeleter(replyKeys); if (!replyKeys) { theRet = QTSS_NotConnected; break; } if (replyKeys->elements > 0) { int eleIndex = -1, eleLoad = 0; for (size_t i = 0; i < replyKeys->elements; ++i) { auto replyTemp = replyKeys->element[i]; if (replyTemp->type == EASY_REDIS_REPLY_NIL) { continue; } string strTemp = Format("hmget %s %s %s %s %s ", string(replyTemp->str), string(EASY_REDIS_LOAD), string(EASY_REDIS_IP), string(EASY_REDIS_HTTP), string(EASY_REDIS_RTSP)); auto replyHmget = static_cast<redisReply*>(redisCommand(redisContext_, strTemp.c_str())); RedisReplyObjectDeleter replyHmgetDeleter(replyHmget); if (!replyHmget) { theRet = QTSS_NotConnected; break; } if (replyHmget->type == EASY_REDIS_REPLY_NIL) { continue; } auto loadReply = replyHmget->element[0]; auto ipReply = replyHmget->element[1]; auto httpReply = replyHmget->element[2]; auto rtspReply = replyHmget->element[3]; auto load = stoi(loadReply->str); string ip(ipReply->str); string http(httpReply->str); string rtsp(rtspReply->str); if (eleIndex == -1) { eleIndex = i; eleLoad = load; strncpy(inParams->outDssIP, ip.c_str(), ip.size()); strncpy(inParams->outHTTPPort, http.c_str(), http.size()); strncpy(inParams->outDssPort, rtsp.c_str(), rtsp.size()); } else { if (load < eleLoad)//find better { eleIndex = i; eleLoad = load; strncpy(inParams->outDssIP, ip.c_str(), ip.size()); strncpy(inParams->outHTTPPort, http.c_str(), http.size()); strncpy(inParams->outDssPort, rtsp.c_str(), rtsp.size()); } } } if (eleIndex == -1)//no one live { theRet = QTSS_Unimplemented; break; } else { inParams->isOn = false; } } else { theRet = QTSS_Unimplemented; break; } } } while (0); if (theRet != QTSS_NoErr) { RedisErrorHandler(); } return theRet; }
/* void CWebServerEng::ReadConfigFileL() { // Read Config File. TRAP(err,iServerEnv->ReadConfigFileL(CFG_FILENAME)); if ((err == KErrNotFound) || (err == KErrPathNotFound)) { iObserver->ShowWarningL(R_CONFIG_FILE_MISSING_WAR); iServerEnv->CheckAndSetDefaultL(); } else { User::LeaveIfError(err); } } void CWebServerEng::ReadHttpTypesFileL() { // Read Http types files TRAP(err,iHttpTypes.ReadHttpTypesFileL(HTTP_TYPES_FILENAME)); if ((err == KErrNotFound) || (err == KErrPathNotFound)) { iObserver->ShowWarningL(R_TYPES_FILE_MISSING_WAR); iHttpTypes.SetDefaultHttpTypesL(); } else { User::LeaveIfError(err); } } */ void CWebServerEng::StartWebServerL() // This function starts the WebServer. { TInt err; /* // *** TEST of the Security Database. CWebServerSecDB SecDb; // ----> Must be menber of the object. //TRAP(err,SecDb.OpenSecDBL(_L("WebServer"))); //if (err == KErrNotFound) //{ SecDb.CreateSecDB(_L("webserver.db")); SecDb.OpenSecDBL(_L("webserver.db")); SecDb.InsertUserL(_L("Litos"),_L("Groo"),_L("GrooWorld")); SecDb.InsertUserL(_L("Rufferto"),_L("Groo"),_L("RuffertoWorld")); TInt ruffertotwice = SecDb.InsertUserL(_L("Rufferto"),_L("Groonan"),_L("RuffertoWorld")); SecDb.InsertRealmL(_L("GrooWorld"),_L("Basic")); SecDb.InsertResourceDirL(_L("\\ws\\laetitia\\"),_L("GrooWorld"),SEC_GET); SecDb.CloseSecDB(); SecDb.OpenSecDBL(_L("webserver.db")); TBool boolean1 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet); TBool boolean2 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EPut); TBool boolean3 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EDelete); TBool boolean4 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EOptions); TBool boolean5 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EPost); TBool boolean6 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet); TBool boolean7 = SecDb.GrantAccessL(_L("Litos5"),_L("Groo"),_L("\\ws\\laetitia\\"),EPost); TBool boolean8 = SecDb.GrantAccessL(_L("Litos"),_L("Groonan"),_L("\\ws\\laetitia\\"),EPost); TBool boolean9 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\lala\\laetitia\\"),EPost); TBool boolean10 = SecDb.GrantAccessL(_L("Rufferto"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet); TInt deluser = SecDb.DeleteUserL(_L("Litos"),_L("RuffertoWorld")); SecDb.DeleteUserL(_L("Litos"),_L("GrooWorld")); TInt dellit = SecDb.DeleteUserL(_L("Litos"),_L("GrooWorld")); TBool boolean11 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet); SecDb.InsertUserL(_L("Litos"),_L("Groo"),_L("GrooWorld")); SecDb.DeleteRealm(_L("GrooWorld")); TBool boolean12 = SecDb.GrantAccessL(_L("Litos"),_L("Groo"),_L("\\ws\\laetitia\\"),EGet); SecDb.CloseSecDB(); //} */ //*********************************** #ifdef IPV4_ORIG iStatusText = _L("************* IPV4 STACK ****************\n\n"); #else iStatusText=_L("*************** DUAL STACK IPV4/IPV6 ****************\n\n"); #endif NotifyStatus(); // Setting up the dial connection. iStatusText=_L("Setting up net connection.\n"); NotifyStatus(); // Make a connection to the Socket Server. iStatusText=_L("Connecting to the Socket Server.\n"); NotifyStatus(); err = iSocketServer.Connect(201); User::LeaveIfError(err); #if EPOC_SDK >= 0x07010000 User::LeaveIfError(iRConnection.Open(iSocketServer)); err = iRConnection.Start(); if (err != KErrAlreadyExists) User::LeaveIfError(err); #elif EPOC_SDK >= 0x06010000 User::LeaveIfError(iGenericAgent.Open()); err = iGenericAgent.StartOutgoing(); err = iGenericAgent.DisableTimers(); if (err != KErrAlreadyExists) User::LeaveIfError(err); #else User::LeaveIfError(iNetdial.Open()); err = iNetdial.DisableTimers(); if (err != KErrAlreadyExists) User::LeaveIfError(err); err = iNetdial.StartDialOut(); if (err != KErrAlreadyExists) User::LeaveIfError(err); #endif // EPOC_SDK >= 0x06010000 // Open a socket to listen on. iStatusText=_L("Opening the Socket.\n"); NotifyStatus(); err = iSocket.Open(iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); User::LeaveIfError(err); // Reuse the port iSocket.SetOpt(KSoReuseAddr, KProtocolInetIp, 1); // Bind the socket to the http port. iStatusText=_L("Binding the Socket.\n"); NotifyStatus(); TInetAddr httpPort(KInetAddrAny, iServerEnv->iPort); httpPort.SetFamily(0); // Listen both IPV4 and IPV6. (Dual-Stack). err = iSocket.Bind(httpPort); User::LeaveIfError(err); // Listen for incoming connections. iStatusText=_L("Listening through the Socket.\n"); NotifyStatus(); err = iSocket.Listen(100); User::LeaveIfError(err); // The Socket for the "real" connection.(between the client and the WebServer) iStatusText=_L("Waiting for a Connection.\n"); NotifyStatus(); CreateSocketAndConnectionL(); iWebServerState = EWaitingForConnections; iSocket.Accept(*iConnection,iStatus); iCurrentNumberConnections = 0; iTotalNumberConnections = 0; SetActive(); }