int MP3Broadcaster::ConnectToServer() { UInt32 addr; addr = SocketUtils::ConvertStringToAddr(mIPAddr); if (addr == INADDR_NONE) { struct hostent* theHostent = ::gethostbyname(mIPAddr); if (theHostent != NULL) addr = ntohl(*(UInt32*)(theHostent->h_addr_list[0])); else qtss_printf("Couldn't resolve address %s\n", mIPAddr); } OS_Error err = mSocket.Open(); err = mSocket.Connect(addr, mPort); if (err == 0) { char buffer1[512]; char buffer2[512]; UInt32 len; StringTranslator::EncodeURL(mMountPoint, strlen(mMountPoint) + 1, buffer1, sizeof(buffer1)); if (strlen(buffer1) + strlen(mPassword) + 12 <= 512) { if (mUseICY) { // in the ICY protocol there is no mountpoint // the reflector assumes a default mountpoint of "/" qtss_sprintf(buffer2, "%s\n", mPassword); } else { // if the mountpoint does not start with a "/" we prepend one for the // reflector before we send the broadcast request. if (buffer1[0] == '/') qtss_sprintf(buffer2, "SOURCE %s %s\n\n", mPassword, buffer1); else qtss_sprintf(buffer2, "SOURCE %s /%s\n\n", mPassword, buffer1); } mSocket.Send(buffer2, strlen(buffer2), &len); } else return -1; char buffer3[3]; len = 0; mSocket.Read(buffer3, 2, &len); buffer3[2] = '\0'; if (::strcmp(buffer3, "OK") != 0) err = EACCES; } return err; }
int MP3Broadcaster::SendXAudioCastHeaders() { char buffer[1024]; char temp[256]; UInt32 len; if (mUseICY) { qtss_sprintf(buffer, "icy-name:%s\n", mName); qtss_sprintf(temp, "icy-genre:%s\n", mGenre); strcat(buffer, temp); qtss_sprintf(temp, "icy-pub:%s\n", "0"); strcat(buffer, temp); qtss_sprintf(temp, "icy-url:%s\n", mURL); strcat(buffer, temp); } else { qtss_sprintf(buffer, "x-audiocast-name:%s\n", mName); qtss_sprintf(temp, "x-audiocast-genre:%s\n", mGenre); strcat(buffer, temp); qtss_sprintf(temp, "x-audiocast-public:%s\n", "0"); strcat(buffer, temp); qtss_sprintf(temp, "x-audiocast-description:%s\n", ""); strcat(buffer, temp); } mSocket.Send(buffer, strlen(buffer), &len); return 0; }
void* OSCodeFragment::GetSymbol(const char* inSymbolName) { if (fFragmentP == NULL) return NULL; #if defined(HPUX) || defined(HPUX10) void *symaddr = NULL; int status; errno = 0; status = shl_findsym((shl_t *)&fFragmentP, symname, TYPE_PROCEDURE, &symaddr); if (status == -1 && errno == 0) /* try TYPE_DATA instead */ status = shl_findsym((shl_t *)&fFragmentP, inSymbolName, TYPE_DATA, &symaddr); return (status == -1 ? NULL : symaddr); #elif defined(DLSYM_NEEDS_UNDERSCORE) char *symbol = (char*)malloc(sizeof(char)*(strlen(inSymbolName)+2)); void *retval; qtss_sprintf(symbol, "_%s", inSymbolName); retval = dlsym(fFragmentP, symbol); free(symbol); return retval; #elif defined(__Win32__) return ::GetProcAddress(fFragmentP, inSymbolName); #elif defined(__MacOSX__) CFStringRef theString = CFStringCreateWithCString( kCFAllocatorDefault, inSymbolName, kCFStringEncodingASCII); void* theSymbol = (void*)CFBundleGetFunctionPointerForName( fFragmentP, theString ); CFRelease(theString); return theSymbol; #else return dlsym(fFragmentP, inSymbolName); #endif }
UInt32 RTCPSRPacket::GetACName(char* ioCNameBuffer) { static char* sCNameBase = "QTSS"; //clear out the whole buffer ::memset(ioCNameBuffer, 0, kMaxCNameLen); //cName identifier ioCNameBuffer[0] = 1; //Unique cname is constructed from the base name and the current time qtss_sprintf(&ioCNameBuffer[1], " %s%"_64BITARG_"d", sCNameBase, OS::Milliseconds() / 1000); UInt32 cNameLen = ::strlen(ioCNameBuffer); //2nd byte of CName should be length ioCNameBuffer[1] = (UInt8) (cNameLen - 2);//don't count indicator or length byte // This function assumes that the cName is the only item in this SDES chunk // (see RTP rfc for details). // The RFC says that the item (the cName) should not be NULL terminated, but // the chunk *must* be NULL terminated. And padded to a 32-bit boundary. // // qtss_sprintf already put a NULL terminator in the cName buffer. So all we have to // do is pad out to the boundary. cNameLen += 1; //add on the NULL character UInt32 paddedLength = cNameLen + (4 - (cNameLen % 4)); // Pad, and zero out as we pad. for (; cNameLen < paddedLength; cNameLen++) ioCNameBuffer[cNameLen] = '\0'; Assert((cNameLen % 4) == 0); return cNameLen; }
void HTTPRequest::AppendContentLengthHeader(UInt32 length_32bit) { char* contentLength = NEW char[256]; qtss_sprintf(contentLength, "%lu", length_32bit); StrPtrLen contentLengthPtr(contentLength); AppendResponseHeader(httpContentLengthHeader, &contentLengthPtr); }
void HTTPRequest::AppendContentLengthHeader(UInt64 length_64bit) { char* contentLength = NEW char[256]; qtss_sprintf(contentLength, "%"_64BITARG_"d", length_64bit); StrPtrLen contentLengthPtr(contentLength); AppendResponseHeader(httpContentLengthHeader, &contentLengthPtr); }
time_t MP3BroadcasterLog::WriteLogHeader(FILE *inFile) { // Write a W3C compatable log header time_t calendarTime = ::time(NULL); Assert(-1 != calendarTime); if (-1 == calendarTime) return -1; struct tm timeResult; struct tm* theLocalTime = qtss_localtime(&calendarTime, &timeResult); Assert(NULL != theLocalTime); if (NULL == theLocalTime) return -1; char tempBuffer[1024] = { 0 }; qtss_strftime(tempBuffer, sizeof(tempBuffer), "#Log File Created On: %m/%d/%Y %H:%M:%S\n", theLocalTime); this->WriteToLog(tempBuffer, !kAllowLogToRoll); tempBuffer[0] = '\0'; // format a date for the startup time char theDateBuffer[QTSSRollingLog::kMaxDateBufferSizeInBytes] = { 0 }; Bool16 result = QTSSRollingLog::FormatDate(theDateBuffer, false); if (result) { qtss_sprintf(tempBuffer, sLogHeader, "MP3Broadcaster" , kVersionString, theDateBuffer, sLogTimeInGMT ? "GMT" : "local time"); this->WriteToLog(tempBuffer, !kAllowLogToRoll); } return calendarTime; }
void MP3BroadcasterLog::LogInfo( const char* infoStr ) { // log a generic comment char strBuff[1024] = ""; char dateBuff[80] = ""; if ( this->FormatDate( dateBuff, false ) ) { if ( (NULL != infoStr) && ( ( strlen(infoStr) + strlen(strBuff) + strlen(dateBuff) ) < 800) ) { qtss_sprintf(strBuff,"#Remark: %s %s\n",dateBuff, infoStr); this->WriteToLog( strBuff, kAllowLogToRoll ); } else { ::strcat(strBuff,dateBuff); ::strcat(strBuff," internal error in LogInfo\n"); this->WriteToLog( strBuff, kAllowLogToRoll ); } } }
void QTSSModuleUtils::SendDescribeResponse(QTSS_RTSPRequestObject inRequest, QTSS_ClientSessionObject inSession, iovec* describeData, UInt32 inNumVectors, UInt32 inTotalLength) { //write content size header char buf[32]; qtss_sprintf(buf, "%"_S32BITARG_"", inTotalLength); (void)QTSS_AppendRTSPHeader(inRequest, qtssContentLengthHeader, &buf[0], ::strlen(&buf[0])); (void)QTSS_SendStandardRTSPResponse(inRequest, inSession, 0); // On solaris, the maximum # of vectors is very low (= 16) so to ensure that we are still able to // send the SDP if we have a number greater than the maximum allowed, we coalesce the vectors into // a single big buffer #ifdef __solaris__ if (inNumVectors > IOV_MAX ) { char* describeDataBuffer = QTSSModuleUtils::CoalesceVectors(describeData, inNumVectors, inTotalLength); (void)QTSS_Write(inRequest, (void *)describeDataBuffer, inTotalLength, NULL, qtssWriteFlagsNoFlags); // deleting memory allocated by the CoalesceVectors call delete [] describeDataBuffer; } else (void)QTSS_WriteV(inRequest, describeData, inNumVectors, inTotalLength, NULL); #else (void)QTSS_WriteV(inRequest, describeData, inNumVectors, inTotalLength, NULL); #endif }
void RTPSessionInterface::CreateDigestAuthenticationNonce() { // Calculate nonce: MD5 of sessionid:timestamp SInt64 curTime = OS::Milliseconds(); char* curTimeStr = new char[128]; qtss_sprintf(curTimeStr, "%" _64BITARG_ "d", curTime); // Delete old nonce before creating a new one if (fAuthNonce.Ptr != NULL) delete[] fAuthNonce.Ptr; MD5_CTX ctxt; unsigned char nonceStr[16]; unsigned char colon[] = ":"; MD5_Init(&ctxt); StrPtrLen* sesID = this->GetValue(qtssCliSesRTSPSessionID); MD5_Update(&ctxt, (unsigned char *)sesID->Ptr, sesID->Len); MD5_Update(&ctxt, (unsigned char *)colon, 1); MD5_Update(&ctxt, (unsigned char *)curTimeStr, ::strlen(curTimeStr)); MD5_Final(nonceStr, &ctxt); HashToString(nonceStr, &fAuthNonce); delete[] curTimeStr; // No longer required once nonce is created // Set the nonce count value to zero // as a new nonce has been created fAuthNonceCount = 0; }
QTSS_Error QTSSModuleUtils::SendErrorResponseWithMessage( QTSS_RTSPRequestObject inRequest, QTSS_RTSPStatusCode inStatusCode, StrPtrLen* inErrorMessagePtr) { static Bool16 sFalse = false; //set RTSP headers necessary for this error response message (void)QTSS_SetValue(inRequest, qtssRTSPReqStatusCode, 0, &inStatusCode, sizeof(inStatusCode)); (void)QTSS_SetValue(inRequest, qtssRTSPReqRespKeepAlive, 0, &sFalse, sizeof(sFalse)); StrPtrLen theErrorMessage(NULL, 0); if (sEnableRTSPErrorMsg) { Assert(inErrorMessagePtr != NULL); //Assert(inErrorMessagePtr->Ptr != NULL); //Assert(inErrorMessagePtr->Len != 0); theErrorMessage.Set(inErrorMessagePtr->Ptr, inErrorMessagePtr->Len); char buff[32]; qtss_sprintf(buff,"%"_U32BITARG_"",inErrorMessagePtr->Len); (void)QTSS_AppendRTSPHeader(inRequest, qtssContentLengthHeader, buff, ::strlen(buff)); } //send the response header. In all situations where errors could happen, we //don't really care, cause there's nothing we can do anyway! (void)QTSS_SendRTSPHeaders(inRequest); // // Now that we've formatted the message into the temporary buffer, // write it out to the request stream and the Client Session object (void)QTSS_Write(inRequest, theErrorMessage.Ptr, theErrorMessage.Len, NULL, 0); (void)QTSS_SetValue(inRequest, qtssRTSPReqRespMsg, 0, theErrorMessage.Ptr, theErrorMessage.Len); return QTSS_RequestFailed; }
void RTPSessionInterface::UpdateDigestAuthChallengeParams(bool newNonce, bool createOpaque, UInt32 qop) { if (newNonce || (fAuthNonce.Ptr == NULL)) this->CreateDigestAuthenticationNonce(); if (createOpaque) { // Generate a random UInt32 and convert it to a string // The base64 encoded form of the string is made the opaque value SInt64 theMicroseconds = OS::Microseconds(); ::srand((unsigned int)theMicroseconds); UInt32 randomNum = ::rand(); char* randomNumStr = new char[128]; qtss_sprintf(randomNumStr, "%" _U32BITARG_ "", randomNum); int len = ::strlen(randomNumStr); fAuthOpaque.Len = Base64encode_len(len); char *opaqueStr = new char[fAuthOpaque.Len]; (void)Base64encode(opaqueStr, randomNumStr, len); delete[] randomNumStr; // Don't need this anymore if (fAuthOpaque.Ptr != NULL) // Delete existing pointer before assigning new delete[] fAuthOpaque.Ptr; // one fAuthOpaque.Ptr = opaqueStr; fAuthOpaque.Len = ::strlen(opaqueStr); } else { if (fAuthOpaque.Ptr != NULL) delete[] fAuthOpaque.Ptr; fAuthOpaque.Len = 0; } fAuthNonceCount++; fAuthQop = qop; }
OS_Error HTTPClientSocket::SendV(iovec* inVec, UInt32 inNumVecs) { // // Bring up the POST connection if we need to if (fPostSocket == NULL) fPostSocket = NEW TCPSocket(NULL, fSocketType); if (!fPostSocket->IsConnected()) { #if CLIENT_SOCKET_DEBUG qtss_printf("HTTPClientSocket::Send: Sending POST\n"); #endif qtss_sprintf(fSendBuffer.Ptr, "POST %s HTTP/1.0\r\nX-SessionCookie: %" _U32BITARG_ "\r\nAccept: application/x-rtsp-rtp-interleaved\r\nUser-Agent: QTSS/2.0\r\n\r\n", fURL.Ptr, fCookie); fSendBuffer.Len = ::strlen(fSendBuffer.Ptr); this->encodeVec(inVec, inNumVecs); } OS_Error theErr = this->Connect(fPostSocket); if (theErr != OS_NoErr) return theErr; // // If we have nothing to send currently, this should be a new message, in which case // we can encode it and send it if (fSendBuffer.Len == 0) this->encodeVec(inVec, inNumVecs); #if CLIENT_SOCKET_DEBUG //qtss_printf("HTTPClientSocket::Send: Sending data\n"); #endif return this->SendSendBuffer(fPostSocket); }
void LogStr(char *str) { *gLogBuff = 0; int size = strlen(str) + gBuffUsed; if ( size <= gBuffMaxStr ) qtss_sprintf(gLogBuff, "%s%s",gLogBuff, str); gBuffUsed = strlen(gLogBuff); }
void LogNum(char *str1,char *str2,char *str3) { int size = strlen(str1) + strlen(str2) + strlen(str3); if ( size < gBuffMaxStr ) qtss_sprintf(gLogBuff, "%s%s%s%s",gLogBuff, str1, str2,str3); gBuffUsed = strlen(gLogBuff); }
void HTTPRequest::AppendContentLengthHeader(UInt32 length_32bit) { //char* contentLength = NEW char[256]; char contentLength[256] = { 0 }; qtss_sprintf(contentLength, "%"_U32BITARG_"", length_32bit); StrPtrLen contentLengthPtr(contentLength); AppendResponseHeader(httpContentLengthHeader, &contentLengthPtr); }
StrPtrLen* Socket::GetLocalPortStr() { if (fPortStr.Len == kPortBufSizeInBytes) { int temp = ntohs(fLocalAddr.sin_port); qtss_sprintf(fPortBuffer, "%d", temp); fPortStr.Len = ::strlen(fPortBuffer); } return &fPortStr; }
QTSServerInterface::QTSServerInterface() : QTSSDictionary(QTSSDictionaryMap::GetMap(QTSSDictionaryMap::kServerDictIndex), &fMutex), fSrvrPrefs(NULL), fSrvrMessages(NULL), fServerState(qtssStartingUpState), fDefaultIPAddr(0), fListeners(NULL), fNumListeners(0), fStartupTime_UnixMilli(0), fGMTOffset(0), fNumHTTPSessions(0), fCPUPercent(0), fCPUTimeUsedInSec(0), fSigInt(false), fSigTerm(false), fDebugLevel(0), fDebugOptions(0), fMaxLate(0), fTotalLate(0), fCurrentMaxLate(0), fTotalQuality(0), fNumThinned(0), fNumThreads(0), fIfConSucess(false)//add { for (UInt32 y = 0; y < QTSSModule::kNumRoles; y++) { sModuleArray[y] = NULL; sNumModulesInRole[y] = 0; } this->SetVal(qtssSvrState, &fServerState, sizeof(fServerState)); this->SetVal(qtssServerAPIVersion, &sServerAPIVersion, sizeof(sServerAPIVersion)); this->SetVal(qtssSvrDefaultIPAddr, &fDefaultIPAddr, sizeof(fDefaultIPAddr)); this->SetVal(qtssSvrServerName, sServerNameStr.Ptr, sServerNameStr.Len); this->SetVal(qtssSvrServerVersion, sServerVersionStr.Ptr, sServerVersionStr.Len); this->SetVal(qtssSvrServerBuildDate, sServerBuildDateStr.Ptr, sServerBuildDateStr.Len); this->SetVal(qtssSvrHTTPServerHeader, sServerHeaderPtr.Ptr, sServerHeaderPtr.Len); this->SetVal(qtssCurrentSessionCount, &fNumHTTPSessions, sizeof(fNumHTTPSessions)); this->SetVal(qtssSvrStartupTime, &fStartupTime_UnixMilli, sizeof(fStartupTime_UnixMilli)); this->SetVal(qtssSvrGMTOffsetInHrs, &fGMTOffset, sizeof(fGMTOffset)); this->SetVal(qtssSvrCPULoadPercent, &fCPUPercent, sizeof(fCPUPercent)); this->SetVal(qtssSvrServerBuild, sServerBuildStr.Ptr, sServerBuildStr.Len); this->SetVal(qtssSvrHTTPServerComment, sServerCommentStr.Ptr, sServerCommentStr.Len); this->SetVal(qtssSvrServerPlatform, sServerPlatformStr.Ptr, sServerPlatformStr.Len); this->SetVal(qtssSvrNumThinned, &fNumThinned, sizeof(fNumThinned)); this->SetVal(qtssSvrNumThreads, &fNumThreads, sizeof(fNumThreads)); qtss_sprintf(fDMSServiceID, "EasyCMS%s", "Config EasyCMS Uid"); sServer = this; }
void InstallService(char* inServiceName) { SC_HANDLE theService; SC_HANDLE theSCManager; TCHAR thePath[512]; TCHAR theQuotedPath[522]; BOOL theErr = ::GetModuleFileName(NULL, thePath, 512); if (!theErr) return; qtss_sprintf(theQuotedPath, "\"%s\"", thePath); theSCManager = ::OpenSCManager( NULL, // machine (NULL == local) NULL, // database (NULL == default) SC_MANAGER_ALL_ACCESS // access required ); if (!theSCManager) { qtss_printf("Failed to install EasyCMS Service\n"); return; } theService = CreateService( theSCManager, // SCManager database inServiceName, // name of service inServiceName, // name to display SERVICE_ALL_ACCESS, // desired access SERVICE_WIN32_OWN_PROCESS, // service type SERVICE_AUTO_START, // start type SERVICE_ERROR_NORMAL, // error control type theQuotedPath, // service's binary NULL, // no load ordering group NULL, // no tag identifier NULL, // dependencies NULL, // LocalSystem account NULL); // no password if (theService) { ::CloseServiceHandle(theService); qtss_printf("Installed EasyCMS Service\n"); } else qtss_printf("Failed to install EasyCMS Service\n"); ::CloseServiceHandle(theSCManager); }
void GenerateHotHitSMIL(char* buffer) { char smilTemplate[8192] = {}; char* templateCursor = smilTemplate; char* bufferCursor = buffer; FILE* smilTemplateFile = fopen("template.smil", "r"); if (smilTemplateFile != NULL) { int len = fread(smilTemplate, sizeof(char), sizeof(smilTemplate), smilTemplateFile); smilTemplate[len] = '\0'; fclose(smilTemplateFile); } else { strcpy(smilTemplate, "<smil>\n" " <head>\n" " <layout>\n" " </layout>\n" " </head>\n" " <body>\n" " <seq>\n" " <video src=\"%s\" />\n" " </seq>\n" " </body>\n" "</smil>\n"); } int hitNum = 0; char* p = NULL; while ( (p = strstr(templateCursor, "%s")) != 0 ) { char saveCh = p[2]; p[2] = '\0'; int len = qtss_sprintf(bufferCursor, templateCursor, gHitcountArray[hitNum++].url); p[2] = saveCh; bufferCursor += len; templateCursor = &p[2]; } strcat(bufferCursor, templateCursor); #if HTTP_FILE_DEBUGGING qtss_printf("smil generated:\n%s\n", buffer); #endif }
void RTConnectionManager::GenericSessionId(std::string& strId) { SInt64 curTime = OS::Microseconds(); MD5_CTX context; StrPtrLen hashStr; OSMutexLocker locker(&s_mutex); memset(s_curMicroSecStr, 0, 128); memset(s_digest, 0, 16); qtss_sprintf(s_curMicroSecStr, "%lld", curTime); MD5_Init(&context); MD5_Update(&context, (unsigned char*)s_curMicroSecStr, (unsigned int)strlen((const char*)s_curMicroSecStr)); MD5_Update(&context, (unsigned char*)m_lastUpdateTime.c_str(), (unsigned int)m_lastUpdateTime.length()); MD5_Final(s_digest, &context); HashToString(s_digest, &hashStr); strId = hashStr.GetAsCString(); m_lastUpdateTime = s_curMicroSecStr; }
void MP3BroadcasterLog::LogMediaError( const char* path, const char* errStr , const char* messageStr) { // log movie play info char strBuff[1024] = ""; char dateBuff[80] = ""; if ( this->FormatDate( dateBuff, false ) ) { if ( (NULL != path) && ( (strlen(path) + strlen(dateBuff) ) < 800) ) { qtss_sprintf(strBuff,"#Remark: %s %s ",dateBuff, path); if ( errStr ) { if ( (strlen(strBuff) + strlen(errStr) ) < 1000 ) { ::strcat(strBuff,"Error:"); ::strcat(strBuff,errStr); } } else if ( (NULL != messageStr) && ( (strlen(strBuff) + strlen(messageStr) ) < 1000 ) ) { ::strcat(strBuff,messageStr); } else ::strcat(strBuff,"OK"); ::strcat(strBuff,"\n"); this->WriteToLog(strBuff, kAllowLogToRoll ); } else { ::strcat(strBuff,dateBuff); ::strcat(strBuff," internal error in LogMediaError\n"); this->WriteToLog( strBuff, kAllowLogToRoll ); } } }
HTTPSessionInterface::HTTPSessionInterface() : QTSSDictionary(QTSSDictionaryMap::GetMap(QTSSDictionaryMap::kRTSPSessionDictIndex)), Task(), fTimeoutTask(NULL, QTSServerInterface::GetServer()->GetPrefs()->GetSessionTimeoutInSecs() * 1000), fInputStream(&fSocket), fOutputStream(&fSocket, &fTimeoutTask), fSessionMutex(), fSocket(NULL, Socket::kNonBlockingSocketType), fOutputSocketP(&fSocket), fInputSocketP(&fSocket), fSessionType(qtssNormalSession), fLiveSession(true), fObjectHolders(0), fRequestBodyLen(-1), fAuthenticated(false) { fStreamReqCount.clear(); fTimeoutTask.SetTask(this); fSocket.SetTask(this); //fSerial[0] = 0; //::memset(fSerial, 0, EASY_MAX_SERIAL_LENGTH); //fDevSerialPtr.Set( fSerial, ::strlen(fSerial)); //fDevRef.Set( fDevSerialPtr, this); fSessionIndex = (UInt32)atomic_add(&sSessionIndexCounter, 1); this->SetVal(qtssEasySesIndex, &fSessionIndex, sizeof(fSessionIndex)); this->SetVal(qtssRTSPSesEventCntxt, &fOutputSocketP, sizeof(fOutputSocketP)); this->SetVal(qtssRTSPSesType, &fSessionType, sizeof(fSessionType)); //this->SetEmptyVal(qtssEasySesSerial, &fSerial[0], EASY_MAX_SERIAL_LENGTH); this->SetEmptyVal(qtssRTSPSesLastUserName, &fUserNameBuf[0], kMaxUserNameLen); this->SetEmptyVal(qtssRTSPSesLastUserPassword, &fUserPasswordBuf[0], kMaxUserPasswordLen); qtss_sprintf(fSessionID, "%s", EasyUtil::GetUUID().c_str()); this->SetValue(qtssEasySessionID, 0, fSessionID, ::strlen(fSessionID), QTSSDictionary::kDontObeyReadOnly); this->SetEmptyVal(qtssEasySesLastSMSSessionID, &fLastSMSSessionID[0], QTSS_MAX_SESSION_ID_LENGTH); fInputStream.ShowMSG(QTSServerInterface::GetServer()->GetPrefs()->GetMSGDebugPrintfs()); fOutputStream.ShowMSG(QTSServerInterface::GetServer()->GetPrefs()->GetMSGDebugPrintfs()); }
void RTPSessionInterface::SetChallengeParams(QTSS_AuthScheme scheme, UInt32 qop, bool newNonce, bool createOpaque) { // Set challenge params // Set authentication scheme fAuthScheme = scheme; if (fAuthScheme == qtssAuthDigest) { // Set Quality of Protection // auth-int (Authentication with integrity) not supported yet fAuthQop = qop; if (newNonce || (fAuthNonce.Ptr == NULL)) this->CreateDigestAuthenticationNonce(); if (createOpaque) { // Generate a random UInt32 and convert it to a string // The base64 encoded form of the string is made the opaque value SInt64 theMicroseconds = OS::Microseconds(); ::srand((unsigned int)theMicroseconds); UInt32 randomNum = ::rand(); char* randomNumStr = new char[128]; qtss_sprintf(randomNumStr, "%" _U32BITARG_ "", randomNum); int len = ::strlen(randomNumStr); fAuthOpaque.Len = Base64encode_len(len); char *opaqueStr = new char[fAuthOpaque.Len]; (void)Base64encode(opaqueStr, randomNumStr, len); delete[] randomNumStr; // Don't need this anymore if (fAuthOpaque.Ptr != NULL) // Delete existing pointer before assigning new delete[] fAuthOpaque.Ptr; // one fAuthOpaque.Ptr = opaqueStr; } else { if (fAuthOpaque.Ptr != NULL) delete[] fAuthOpaque.Ptr; fAuthOpaque.Len = 0; } // Increase the Nonce Count by one // This number is a count of the next request the server // expects with this nonce. (Implies that the server // has already received nonce count - 1 requests that // sent authorization with this nonce fAuthNonceCount++; } }
bool BCasterTracker::IsProcessRunning( pid_t pid ) { bool isRunning=false; /* // Generic unix code char procPath[256]; qtss_sprintf( procPath, "ps -p%li | grep %li > %s ",(SInt32)pid,(SInt32)pid,gTrackerFileTempDataPath); int result = system(procPath); if (0 == result) { isRunning = true; } */ // a no-grep version to find the pid char pidStr[32]; qtss_sprintf( pidStr, "%li",(SInt32)pid); char procPath[64] = "ps -p"; ::strcat( procPath, pidStr); FILE *inPipe = ::popen(procPath, "r"); if (NULL == inPipe) return false; char inBuff[256] = ""; while (!isRunning && ::fgets(inBuff, sizeof(inBuff), inPipe) != 0) { if (::strstr(inBuff,pidStr) != NULL) { isRunning = true; break; } } (void) ::pclose(inPipe); return isRunning; }
void WriteStartupMessage() { if (sStartedUp) return; sStartedUp = true; //format a date for the startup time char theDateBuffer[QTSSRollingLog::kMaxDateBufferSizeInBytes]; bool result = QTSSRollingLog::FormatDate(theDateBuffer, false); char tempBuffer[1024]; if (result) qtss_sprintf(tempBuffer, "#Remark: Streaming beginning STARTUP %s\n", theDateBuffer); // log startup message to error log as well. if ((result) && (sAccessLog != NULL)) sAccessLog->WriteToLog(tempBuffer, kAllowLogToRoll); }
void WriteShutdownMessage() { if (!sStartedUp) return; sStartedUp = false; //log shutdown message //format a date for the shutdown time char theDateBuffer[QTSSRollingLog::kMaxDateBufferSizeInBytes]; bool result = QTSSRollingLog::FormatDate(theDateBuffer, false); char tempBuffer[1024]; if (result) qtss_sprintf(tempBuffer, "#Remark: Streaming beginning SHUTDOWN %s\n", theDateBuffer); if (result && sAccessLog != NULL) sAccessLog->WriteToLog(tempBuffer, kAllowLogToRoll); }
static void CallEndSession(QTSS_ClientSessionObject* theClientSession) { // action=listener_remove&server=myserver.com&port=8000&client=1&mount=/live&user=&pass=&duration=3600 // the duration SInt64* connectedTime = NULL; UInt32 connectedTimeLen = sizeof(connectedTime); (void)QTSS_GetValuePtr(*theClientSession, qtssCliSesTimeConnectedInMsec, 0, (void**)&connectedTime, &connectedTimeLen); qtss_printf("QTSSIcecastAuthModule::CallEndSession connected time in seconds %li\n", (*connectedTime / 1000)); long duration = (long)*connectedTime / 1000; // the mount point char mountPoint[128] = {0}; StrPtrLen mountPointStr(mountPoint,sizeof(mountPoint)); (void)QTSS_GetValue(*theClientSession, attrClientSessionMountPoint, 0, (void*)mountPointStr.Ptr, &mountPointStr.Len); printf("QTSSIcecastAuthModule::CallEndSession: mount point: %s\n", mountPoint); // TODO - we don't use this data on the remote end (yet), but implement - will probably need to copy // credentials into the client session from the RTSP session (annoying, but both aren't visible at all times) // // username and password // char* username = NULL; // (void)QTSS_GetValueAsString(theRTSPSession, attrRtspSessionProvidedUsername, 0, &username); // printf("QTSSIcecastAuthModule::CallEndSession: Provided username extracted from client session: %s\n", username); // // char* password = NULL; // (void)QTSS_GetValueAsString(theRTSPSession, attrRtspSessionProvidedPassword, 0, &password); // printf("QTSSIcecastAuthModule::CallEndSession: Provided password extracted from client session: %s\n", password); // ice session id char* iceSessID = NULL; QTSS_Error getSessErr = QTSS_GetValueAsString(*theClientSession, attrClientSessionFullSessionID, 0, &iceSessID); char postdata[512]; qtss_sprintf(postdata, "action=listener_remove&server=%s&port=554&client=%s&mount=%s&user=%s&pass=%s&duration=%li", hostname, iceSessID, mountPoint, "", "", duration); printf("QTSSIcecastAuthModule::CallAuthorizeSession: generated postdata: %s\n", postdata); printf("QTSSIcecastAuthModule::CallAuthorizeSession: i would post this to: %s\n", sEndSessionEndpoint); }
time_t QTSSAccessLog::WriteLogHeader(FILE *inFile) { time_t calendarTime = QTSSRollingLog::WriteLogHeader(inFile); //format a date for the startup time char theDateBuffer[QTSSRollingLog::kMaxDateBufferSizeInBytes] = { 0 }; bool result = QTSSRollingLog::FormatDate(theDateBuffer, false); char tempBuffer[1024] = { 0 }; if (result) { StrPtrLen serverName; (void)QTSS_GetValuePtr(sServer, qtssSvrServerName, 0, (void**)&serverName.Ptr, &serverName.Len); StrPtrLen serverVersion; (void)QTSS_GetValuePtr(sServer, qtssSvrServerVersion, 0, (void**)&serverVersion.Ptr, &serverVersion.Len); qtss_sprintf(tempBuffer, sLogHeader, serverName.Ptr, serverVersion.Ptr, theDateBuffer, sLogTimeInGMT ? "GMT" : "local time"); this->WriteToLog(tempBuffer, !kAllowLogToRoll); } return calendarTime; }
static bool SaveElement( PLDoubleLinkedListNode<TrackingElement>* ten, void* userData) { FILE* fp = (FILE*) userData; char buff[512]; /* used by ForEachUntil to find a SaveElement each element to the tracking file. userData is a pointer to the FILE of our open tracking file. */ qtss_sprintf( buff, "%li \"%s\"\n", (SInt32)ten->fElement->mPID, ten->fElement->mName ); // linux version of fputs returns <0 for err, or num bytes written // mac os X version of fputs returns <0 for err, or 0 for no err if (::fputs( buff, fp ) < 0 ) return true; return false; }