コード例 #1
0
ファイル: FileSystemEnumerator.c プロジェクト: ebichu/dd-wrt
int FSE_LocalFilePathToRelativePath(void *fseObj, const char* localFilePath, int localFilePathLen, char **relativePath)
{
	struct FSE_State* fse = (struct FSE_State*) fseObj;
	char *lfp = ILibString_Replace(localFilePath,localFilePathLen,"\\",1,"/",1);
	int RetVal = localFilePathLen - fse->RootPathLen;

	*relativePath = (char*)malloc(RetVal+1);
	memcpy(*relativePath,lfp+fse->RootPathLen,localFilePathLen-fse->RootPathLen);
	(*relativePath)[RetVal] = 0;

	free(lfp);
	return(RetVal);
}
コード例 #2
0
ファイル: FileSystemEnumerator.c プロジェクト: ebichu/dd-wrt
int FSE_RelativePathToLocalFilePath(void *fseObj, const char *relativePath, int relativePathLen, char *localFilePath)
{
	struct FSE_State* fse = (struct FSE_State*) fseObj;
	int RetVal;
	char *tempString;

	tempString = ILibString_Replace(relativePath,relativePathLen,"/",1,"\\",1);
	relativePath = (const char*)tempString;
	if(ILibString_StartsWith(relativePath,relativePathLen,"\\",1)!=0)
	{
		relativePath += 1;
		relativePathLen -= 1;
	}
	
	RetVal = relativePathLen+fse->RootPathLen;
	memcpy(localFilePath,fse->RootPath,fse->RootPathLen);
	memcpy(localFilePath+fse->RootPathLen,relativePath,relativePathLen);
	localFilePath[RetVal]=0;
	free(tempString);
	return(RetVal);
}
コード例 #3
0
void PassiveCandidateSink(ILibWrapper_WebRTC_Connection connection, struct sockaddr_in6* candidate)
{
	printf("While generating an offer?\n"rst);
	SimpleRendezvousServer sender;
	SimpleRendezvousServerToken token;
	char *offer;
	char *encodedOffer;
	int encodedOfferLen;
	char *h1;

	ILibWrapper_WebRTC_Connection_GetUserData(connection, &sender, &token, (void**)&h1);

	offer = ILibWrapper_WebRTC_Connection_AddServerReflexiveCandidateToLocalSDP(connection, candidate);
	printf(green"ofer: \n %s\n"rst,offer);
	encodedOfferLen = ILibBase64Encode((unsigned char*)offer, strlen(offer),(unsigned char**)&encodedOffer);

	h1 = ILibString_Replace(passiveHtmlBody, passiveHtmlBodyLength, "/*{{{SDP}}}*/", 13, encodedOffer, encodedOfferLen);

	free(offer);
	free(encodedOffer);
	SimpleRendezvousServer_Respond(sender, token, 1, h1, strlen(h1), ILibAsyncSocket_MemoryOwnership_CHAIN); // Send the SDP to the remote side
}
コード例 #4
0
// This gets called When the browser hits one of the two URLs
void Rendezvous_OnGet(SimpleRendezvousServer sender, SimpleRendezvousServerToken token, char* path, char* receiver)
{
	printf(green"on Get\n"rst);
	if(strcmp(path, "/active")==0)
	{
		if(mConnection != NULL) { ILibWrapper_WebRTC_Connection_Disconnect(mConnection); mConnection = NULL; }

#ifdef MICROSTACK_TLS_DETECT
		if(SimpleRendezvousServer_IsTLS(token)!=0)
		{
			printf(" Received Client Request: [TLS]\r\n");
		}
		else
		{
			printf(" Received Client Request: [No-TLS]\r\n");
		}
#endif

		SimpleRendezvousServer_Respond(sender, token, 1, htmlBody, htmlBodyLength, ILibAsyncSocket_MemoryOwnership_USER);  // Send the HTML to the Browser
	}
	else if(strcmp(path, "/websocket")==0)
	{
		printf(red"/websocket\n"rst);
		int v = SimpleRendezvousServer_WebSocket_IsRequest(token);

		if(SimpleRendezvousServer_IsAuthenticated(token, "www.meshcentral.com", 19)!=0)
		{
			char* name = SimpleRendezvousServer_GetUsername(token);
			if(SimpleRendezvousServer_ValidatePassword(token, "bryan", 5)!=0)
			{
				printf(red"rendevous respond\n"rst);
				SimpleRendezvousServer_Respond(sender, token, 1, wshtmlbody, wshtmlBodyLength, ILibAsyncSocket_MemoryOwnership_USER);  // Send the HTML to the Browser
			}
		}
	}
	else if(strcmp(path, "/websocketInit")==0)
	{
		printf(green"/websocketInit\n"rst);
		int v = SimpleRendezvousServer_WebSocket_IsRequest(token);
		SimpleRendezvousServer_UpgradeWebSocket(token, 65535, &OnWebSocket, &OnWebSocketClosed);
	}
	else if(strcmp(path, "/passive")==0)
	{
		printf("/passive\n");
		char* offer;
		char* encodedOffer = NULL;
		int encodedOfferLen;
		char *h1;
		
		if(mConnection != NULL){ ILibWrapper_WebRTC_Connection_Disconnect(mConnection); mConnection = NULL; }

		mConnection = ILibWrapper_WebRTC_ConnectionFactory_CreateConnection(mConnectionFactory, &WebRTCConnectionSink, &WebRTCDataChannelSink, &WebRTCConnectionSendOkSink);
		ILibWrapper_WebRTC_Connection_SetStunServers(mConnection, stunServerList, 9);

		if(useStun==0)
		{
			//
			// If STUN was not enabled, then we just generate an offer, and encode it as Base64 into the HTML file to send to the browser
			//
			printf("Generating Offer...\r\n");
			offer = ILibWrapper_WebRTC_Connection_GenerateOffer(mConnection, NULL);
			printf("Encoding Offer...\r\n");
			encodedOfferLen = ILibBase64Encode((unsigned char*)offer, strlen(offer),(unsigned char**)&encodedOffer);
			h1 = ILibString_Replace(passiveHtmlBody, passiveHtmlBodyLength, "/*{{{SDP}}}*/", 13, encodedOffer, encodedOfferLen);

			printf("Sending Offer...\r\n");

			free(offer);
			free(encodedOffer);
			SimpleRendezvousServer_Respond(sender, token, 1, h1, strlen(h1), ILibAsyncSocket_MemoryOwnership_CHAIN); // Send the HTML/OFFER to the browser
		}
		else
		{
			//
			// If STUN was enabled, to simplify this sample app, we'll generate the offer, but we won't do anything with it, as we'll wait until
			printf(red"we get called back saying that candidate gathering was done\n"rst);
			//
			ILibWrapper_WebRTC_Connection_SetUserData(mConnection, sender, token, NULL);
			free(ILibWrapper_WebRTC_Connection_GenerateOffer(mConnection, &PassiveCandidateSink));
			// We're immediately freeing, becuase we're going to re-generate the offer when we get the candidate callback
			// It would be better if we sent this offer, and just passed along the candidates separately, but that is for another sample, since that requires more complex logic.
		}
	}
	else
	{
		printf(red"If we got a GET request for something other than ACTIVE or PASSIVE, we'll just return an error\n"rst);
		SimpleRendezvousServer_Respond(sender, token, 0, NULL, 0, ILibAsyncSocket_MemoryOwnership_CHAIN); 
	}
}
コード例 #5
0
ファイル: FileSystemEnumerator.c プロジェクト: ebichu/dd-wrt
void* FSE_HandleQuery(void *fseObj, struct MSA_CdsQuery *cdsQuery, unsigned int filter, /*OUT*/ enum Enum_CdsErrors *cdsErrorCode)
{
	int objIdLen;
	struct FSE_State *fse = (struct FSE_State*) fseObj;
	struct FSE_QueryState *qs = NULL;
	char ProcessPath[MAX_FILENAME_SIZE ];
	char* tempPtr;

	/*
	*	SOLUTION_REFERENCE#3.6.3.2b
	*/

	*cdsErrorCode = CdsError_None;

	qs = (struct FSE_QueryState*) malloc (sizeof(struct FSE_QueryState));
	memset(qs, 0, sizeof(struct FSE_QueryState));

	/*
	 *	Set qs->FilePath
	 */
	objIdLen = (int) strlen(cdsQuery->ObjectID);
	qs->FilePath = (char*) malloc(fse->RootPathLen + objIdLen + 10);
	if (objIdLen > 2)
	{
		switch (cdsQuery->QueryType)
		{
		case MSA_Query_BrowseMetadata:
			sprintf(qs->FilePath, "%s%s", fse->RootPath, cdsQuery->ObjectID+2);
			break;

		default:
			sprintf(qs->FilePath, "%s%s", fse->RootPath, cdsQuery->ObjectID+2);
			break;
		}
	}
	else
	{
		sprintf(qs->FilePath, "%s", fse->RootPath);
	}

	qs->FilePathLen = (int) strlen(qs->FilePath);
	tempPtr = qs->FilePath;
	qs->FilePath = ILibString_Replace(tempPtr, qs->FilePathLen, &fse->BadDirDelimiterChr, 1, &fse->DirDelimiterChr, 1);
	qs->FilePathLen = (int) strlen(qs->FilePath);
	free(tempPtr);

	/* check to see what type of file system entry this is */
	qs->ObjectType = ILibFileDir_GetType(qs->FilePath);

	switch(qs->ObjectType)
	{
	case FSE_OT_NoExist:

		/* Item not found, could be looking for incomplete CDS objects that didn't finish upload,
		 * these items are saved in temp files in a .tmp extension, try locating those and if not
		 * found, then return object id not exist error */
		tempPtr = malloc(qs->FilePathLen + EXTENSION_UPLOAD_TEMP_LEN + 1);
		sprintf(tempPtr, "%s%s", qs->FilePath, EXTENSION_UPLOAD_TEMP);
		qs->ObjectType = ILibFileDir_GetType(tempPtr);
		if(qs->ObjectType == FSE_OT_File)
		{
			/* temp file availble */
			strcpy(qs->ProcessPath, tempPtr);
			qs->ProcessObjectType = qs->ObjectType;
			qs->CdsObjectType = FSE_CDS_TEMPOPRARY;
			free(tempPtr);
			return qs;
			break;
		}
		else
		{
			/* file not exist or */
			*cdsErrorCode = CDS_EC_OBJECT_ID_NO_EXIST;
			free(tempPtr);
			break;
		}
	
	case FSE_OT_File:
		switch (cdsQuery->QueryType)
		{
		case MSA_Query_BrowseMetadata:
			qs->ProcessIndex = 0;
			qs->ProcessObjectType  = qs->ObjectType;
			strcpy(qs->ProcessPath, qs->FilePath);
			return qs;
			break;
		
		case MSA_Query_BrowseDirectChildren:
		case MSA_Query_Search:
			*cdsErrorCode = CDS_EC_NO_SUCH_CONTAINER;
			break;
		}
		break;

	case FSE_OT_Directory:
		/*
		 *	If it's a directory, ensure it has
		 *	a trailing delimiter.
		 */
		if (qs->FilePath[qs->FilePathLen-1] != fse->DirDelimiterChr)
		{
			qs->FilePath[qs->FilePathLen] = fse->DirDelimiterChr;
			qs->FilePathLen++;
			qs->FilePath[qs->FilePathLen] = '\0';
		}

		/*
		 *	If the query is on the rootpath,
		 *	allow the CDS to report "." entries.
		 */
		if (
			(cdsQuery->QueryType == MSA_Query_BrowseMetadata) &&
			(strcmp(qs->FilePath, fse->RootPath) == 0)
			)
		{
			qs->Flags |= FSE_FLAG_ShowDot;
		}

		switch (cdsQuery->QueryType)
		{
		case MSA_Query_BrowseMetadata:
			qs->ProcessIndex = 0;
			qs->ProcessObjectType  = qs->ObjectType;
			strcpy(qs->ProcessPath, qs->FilePath);
			return qs;
			break;

		case MSA_Query_BrowseDirectChildren:
			qs->ProcessIndex = 0;
			qs->ProcessDirHandle = ILibFileDir_GetDirFirstFile(qs->FilePath, ProcessPath, MAX_FILENAME_SIZE, &(qs->ProcessFileSize));
			
			if(qs->ProcessDirHandle == NULL)
			{
				sprintf(qs->ProcessPath, "%s", "");
			}
			else if ( !
				((strcmp(ProcessPath, ".") == 0) ||
				(strcmp(ProcessPath, "..") == 0))
				)
			{
				sprintf(qs->ProcessPath, "%s%s", qs->FilePath, ProcessPath);
				qs->ProcessObjectType = ILibFileDir_GetType(qs->ProcessPath);
				if(
					(qs->ProcessObjectType==ILibFileDir_Type_FILE) &&
					(ILibString_EndsWith(qs->ProcessPath, (int) strlen(qs->ProcessPath), EXTENSION_UPLOAD_TEMP, EXTENSION_UPLOAD_TEMP_LEN)!=0)
				)
				{
					/* treat incomplete upload files as CDS items. */
					qs->CdsObjectType = FSE_CDS_TEMPOPRARY;
				}
			}
			else
			{
				sprintf(qs->ProcessPath, "%s", ProcessPath);
				qs->ProcessObjectType = ILibFileDir_GetType(qs->ProcessPath);
			}


			return qs;
			break;

		case MSA_Query_Search:
			return _FSE_HandleQuery_Search(fse, qs, cdsQuery, filter, cdsErrorCode);
			break;
		}
		break;

	default:
		*cdsErrorCode = CDS_EC_ACTION_FAILED;
		break;
	}

	/* return NULL with the nonzero *cdsErrorCode */
	return NULL;
}
コード例 #6
0
ファイル: FileSystemEnumerator.c プロジェクト: ebichu/dd-wrt
int FSE_HandleCreateObject(void *fseObj, struct MSA_CdsCreateObj *createObjArg, struct DLNAProtocolInfo* protocolInfo, struct CdsObject *newCdsObject)
{

	struct FSE_State* fse = (struct FSE_State*)fseObj;

	char* id = NULL;
	char* parentId = NULL;
	char* title = NULL;
	int size;
	int retVal = 0;
	int parentIdLen = 0;

	if(newCdsObject != NULL)
	{
		parentId = DecodeFromUTF8(newCdsObject->ParentID);
		parentIdLen = (int) strlen(parentId);

		if((newCdsObject->MediaClass & CDS_CLASS_MASK_OBJECT_TYPE) == CDS_CLASS_MASK_CONTAINER)
		{
			/* this is a container, so the file system will create a new folder */
			char* rootPath = NULL;
			int i, len = 0;
			char* folder = NULL;

			if(newCdsObject->Title != NULL)
			{

				rootPath = fse->RootPath;
				title = DecodeFromUTF8(newCdsObject->Title);
				len = (int)strlen(title) + (int)strlen(rootPath) + parentIdLen;

				folder = malloc(len + 1);
				strcpy(folder, rootPath);
				if(ILibString_StartsWith(parentId, parentIdLen, "0\\", 2)!=0 && parentIdLen>2)
				{
					strcat(folder, parentId + 2);		// skip directory 0
				}
				else if(strnicmp(parentId, CDS_STRING_DLNA_ANYCONTAINER, CDS_STRING_DLNA_ANYCONTAINER_LEN)==0)
				{
					// ToDo: how to handle AnyContainer uploads
					// for now it reset to the root directory of the CDS.
					free(parentId);
					parentId = ILibString_Copy("0\\", -1);
				}

				strcat(folder, title);

				for(i = 0; i < len; i++)
				{
					if(folder[i] == '/')
					{
						folder[i] = '\\';
					}
				}

				retVal = ILibFileDir_CreateDir(folder);

				free(folder);
			}
		}
		else
		{
			/* this is an item, the file system will map the item to a local file, and return the corresponding object ID */
			char* rootPath = NULL;
			char* fileExtension = NULL;
			char* extension = NULL;
			int i, len = 0;
			char* file = NULL;
			char* tmp = NULL;

			rootPath = fse->RootPath;
			if(newCdsObject->Title != NULL)
			{
				title = DecodeFromUTF8(newCdsObject->Title);
			}
			else
			{
				int num = rand() % 1000000000;
				title = (char*) malloc(15);
				sprintf(title, "file%d", num);
			}
			/* we cannot rely on the title of the Cds Item to determine its media type, but rather its DLNA Profile */

			switch(newCdsObject->MediaClass & CDS_CLASS_MASK_MAJOR)
			{
				case CDS_CLASS_MASK_MAJOR_AUDIOITEM:

					if(strcmp(protocolInfo->Profile, DLNAPROFILE_LPCM)==0)
					{
						extension = EXTENSION_AUDIO_LPCM;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_MP3)==0)
					{
						extension = EXTENSION_AUDIO_MPEG;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_AMR_3GPP)==0)
					{
						extension = EXTENSION_AUDIO_3GPP;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_AAC_ISO_320)==0)
					{
						extension = EXTENSION_AUDIO_AAC;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_WMABASE)==0)
					{
						extension = EXTENSION_AUDIO_WMA;
					}
					else
					{
						/* not supported */

					}
					break;
				case CDS_CLASS_MASK_MAJOR_IMAGEITEM:
					if(strcmp(protocolInfo->Profile, DLNAPROFILE_JPEG_SM)==0)
					{
						extension = EXTENSION_IMAGE_JPG;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_JPEG_MED)==0)
					{
						extension = EXTENSION_IMAGE_JPG;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_JPEG_LRG)==0)
					{
						extension = EXTENSION_IMAGE_JPG;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_PNG_LRG)==0)
					{
						extension = EXTENSION_IMAGE_PNG;
					}
					else
					{
						/* not supported */
					}
					break;
				case CDS_CLASS_MASK_MAJOR_VIDEOITEM:
					if(strcmp(protocolInfo->Profile, DLNAPROFILE_MPEG_PS_NTSC)==0)
					{
						extension = EXTENSION_VIDEO_MPEG2;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_AVC_MP4_BL_CIF15_AAC_520)==0)
					{
						extension = EXTENSION_VIDEO_AAC;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_MPEG_PS_NTSC)==0)
					{
						extension = EXTENSION_VIDEO_MPEG2;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_MPEG4_P2_ASF_SP_G726)==0)
					{
						extension = EXTENSION_VIDEO_ASF;
					}
					else if(strcmp(protocolInfo->Profile, DLNAPROFILE_WMVMED_BASE)==0)
					{
						extension = EXTENSION_VIDEO_WMV;
					}
					else
					{
						/* not supported */
					}
					break;
			}

			if(extension == NULL)
			{
				/* no valid extension found, not a valid media item */
				return -1;
			}

			/* replace file extension with the valid extension found */
			fileExtension = FilePathToFileExtension(title, 0);

			if(fileExtension != NULL)
			{
				tmp = title;

				/* replace old title with new title with correct extension */
				title = ILibString_Replace(
					title,
					(int) strlen(title),
					fileExtension,
					(int) strlen(fileExtension),
					extension,
					(int) strlen(extension));

				free(fileExtension);
				free(tmp);
			}
			else
			{
				tmp = (char*) malloc((int) strlen(title) + (int) strlen(extension) + 1);
				strcpy(tmp, title);
				strcat(tmp, extension);
				free(title);
				title = tmp;
			}

			/* replace old title with UTF-8 encoded title */
			if (newCdsObject->DeallocateThese & CDS_ALLOC_Title)
			{
				free(newCdsObject->Title);
			}
			newCdsObject->Title = EncodeToUTF8(title);

			len = (int)strlen(title) + (int)strlen(rootPath) + parentIdLen;

			file = malloc(len + 1);
			strcpy(file, rootPath);
			if(ILibString_StartsWith(parentId, parentIdLen, "0\\", 2)!=0 && parentIdLen>2)
			{
				strcat(file, parentId + 2);		// skip directory 0
			}
			else if(strnicmp(parentId, CDS_STRING_DLNA_ANYCONTAINER, CDS_STRING_DLNA_ANYCONTAINER_LEN)==0)
			{
				// ToDo: how to handle AnyContainer uploads
				// for now it reset to the root directory of the CDS.
				free(parentId);
				parentId = ILibString_Copy("0\\", -1);
			}
			strcat(file, title);

			for(i = 0; i < len; i++)
			{
				if(file[i] == '/')
				{
					file[i] = '\\';
				}
			}

			/* Finds out if there's already a uploaded object */
			tmp = (char*) malloc(strlen(file) + EXTENSION_UPLOAD_TEMP_LEN + 1);
			strcpy(tmp, file);
			strcat(tmp, EXTENSION_UPLOAD_TEMP);
			if(ILibFileDir_GetType(tmp) == FSE_OT_NoExist)
			{
				/* temp file does not exists, no file is currently being uploaded */
				retVal = 0;

				/* overwriting the file, remove the old file in order to avoid duplicates in CDS*/
				ILibFileDir_DeleteFile(file);
				newCdsObject->Source = ILibString_Copy(tmp,-1);
			}
			else
			{
				retVal = -1;
			}
			free(file);
			free(tmp);
		}
	}

	// replace requested object ID with the correct object ID;
	if ((newCdsObject->ParentID != NULL) && (newCdsObject->DeallocateThese & CDS_ALLOC_ParentID))
	{
		// free previous parentId
		free(newCdsObject->ParentID);
	}
	newCdsObject->ParentID = EncodeToUTF8(parentId);

	if((newCdsObject->ID != NULL) && (newCdsObject->DeallocateThese & CDS_ALLOC_ID))
	{
		free(newCdsObject->ID);
	}

	size = parentIdLen + (int) strlen(title) + 2;
	id = (char*) malloc (size);
	strcpy(id, parentId);
	if(ILibString_EndsWith(parentId, parentIdLen, "\\", 1)!=0)
	{
		strcat(id, "\\");
	}
	strcat(id, title);
	newCdsObject->ID = EncodeToUTF8(id);
	newCdsObject->DeallocateThese |= CDS_ALLOC_ParentID;
	newCdsObject->DeallocateThese |= CDS_ALLOC_ID;

	if(id!=NULL) free(id);
	if(parentId!=NULL) free(parentId);
	if(title!=NULL) free(title);

	return retVal;
}
コード例 #7
0
ファイル: FileSystemEnumerator.c プロジェクト: ebichu/dd-wrt
void* FSE_InitFSEState(void *chain, const char *rootDir, const char* virtualDir)
{
	struct FSE_State* fse = (struct FSE_State*) malloc (sizeof(struct FSE_State));
	int i;
	char* tempPtr;

	memset(fse, 0, sizeof(struct FSE_State));

	fse->Destroy = FSE_DestroyFSE;
	fse->RootPath = (char*)malloc((int)strlen(rootDir) + 2);	/* add 2 extra bytes for delimiter and null */
	strcpy(fse->RootPath, rootDir);
	fse->RootPathLen = (int) strlen(fse->RootPath);
	fse->VirtualDirPath = (char*)malloc((int)strlen(virtualDir) + 2);
	strcpy(fse->VirtualDirPath, virtualDir);
	fse->VirtualDirPathLen = (int) strlen(fse->VirtualDirPath);

	fse->DirDelimiter = NULL;

	/*
	 *	Set fse->DirDelimiter
	 */
	for (i = 0; i < fse->RootPathLen; i++)
	{
		if (FSE_BACKSLASH_CHR == fse->RootPath[i])
		{
			fse->DirDelimiter = FSE_BACKSLASH_STR;
			fse->DirDelimiterChr = FSE_BACKSLASH_CHR;
			fse->BadDirDelimiterChr = FSE_FORSLASH_CHR;
		}
		else if (FSE_FORSLASH_CHR == fse->RootPath[i])
		{
			fse->DirDelimiter = FSE_FORSLASH_STR;
			fse->DirDelimiterChr = FSE_FORSLASH_CHR;
			fse->BadDirDelimiterChr = FSE_BACKSLASH_CHR;
		}
	}
	if (fse->DirDelimiter == NULL)
	{
		fse->DirDelimiter = FSE_FORSLASH_STR;
		fse->DirDelimiterChr = FSE_FORSLASH_CHR;
		fse->BadDirDelimiterChr = FSE_BACKSLASH_CHR;
	}

	#ifdef WIN32
	fse->DirDelimiter = FSE_BACKSLASH_STR;
	fse->DirDelimiterChr = FSE_BACKSLASH_CHR;
	fse->BadDirDelimiterChr = FSE_FORSLASH_CHR;
	#endif

	/*
	 *	Ensure all directory delimiters are consistent.
	 */

	tempPtr = ILibString_Replace(fse->RootPath, fse->RootPathLen, &fse->BadDirDelimiterChr, 1, &fse->DirDelimiterChr, 1);
	strcpy(fse->RootPath, tempPtr);
	free(tempPtr);

	/*
	 *	Appropriately acquire the root path with a trailing delimiter.
	 */
	if (fse->RootPath[fse->RootPathLen-1] != fse->DirDelimiterChr)
	{
		/* no traling delimiter, so go ahead and add one */
		fse->RootPath[fse->RootPathLen] = fse->DirDelimiterChr;
		fse->RootPathLen++;
		fse->RootPath[fse->RootPathLen] = '\0';
	}

	ILibAddToChain(chain, fse);

	return fse;
}
コード例 #8
0
ファイル: ILibWrapperWebRTC.c プロジェクト: PearLtd/iWebRTC
int ILibWrapper_SdpToBlock(char* sdp, int sdpLen, int *isActive, char **username, char **password, char **block)
{
	struct parser_result *pr;
	struct parser_result_field *f;

	int ptr;
	int blockLen;
	void* candidates = NULL;
	char* lines;
	char* dtlshash = NULL;
	int dtlsHashLen = 0;
	int candidatecount = 0;
	int BlockFlags = 0;
	*isActive = 0;
	*username = NULL;
	*password = NULL;


	ILibCreateStack(&candidates);

	lines = ILibString_Replace(sdp, sdpLen, "\n", 1, "\r", 1);
	pr = ILibParseString(lines, 0, sdpLen, "\r", 1);
	f = pr->FirstResult;
	while(f!=NULL)
	{
		if(f->datalength == 0) { f = f->NextResult; continue; }

		f->data[f->datalength] = 0;
		if(strcmp(f->data, "a=setup:passive")==0)
        {			
			BlockFlags |= ILibWebRTC_SDP_Flags_DTLS_SERVER;
        }
		else if(strcmp(f->data, "a=setup:active")==0 || strcmp(f->data, "a=setup:actpass")==0)
		{
			*isActive = 1;
		}

		if(f->datalength > 12 && strncmp(f->data, "a=ice-ufrag:", 12)==0) {*username = f->data + 12;} 
		if(f->datalength > 10 && strncmp(f->data, "a=ice-pwd:", 10)==0) {*password = f->data + 10;} 

		if(f->datalength > 22 && strncmp(f->data, "a=fingerprint:sha-256 ", 22)==0)
		{
			char* tmp = ILibString_Replace(f->data + 22, f->datalength - 22, ":", 1, "", 0);
			dtlsHashLen = util_hexToBuf(tmp, strlen(tmp), tmp);
			dtlshash = tmp;
		}

		if(f->datalength > 12 && strncmp(f->data, "a=candidate:", 12)==0)
        {
			struct parser_result* pr2 = ILibParseString(f->data, 0, f->datalength, " ", 1);

			if(pr2->FirstResult->NextResult->datalength == 1 && pr2->FirstResult->NextResult->data[0] == '1' && pr2->FirstResult->NextResult->NextResult->datalength == 3 && strncasecmp(pr2->FirstResult->NextResult->NextResult->data, "UDP", 3)==0)
			//if(pr2->FirstResult->NextResult->NextResult->datalength == 3 && strncasecmp(pr2->FirstResult->NextResult->NextResult->data, "UDP", 3)==0)
			{
				char* candidateData;
				struct parser_result *pr3;
				char *tmp = pr2->FirstResult->NextResult->NextResult->NextResult->NextResult->NextResult->data;
				unsigned short port;

				tmp[pr2->FirstResult->NextResult->NextResult->NextResult->NextResult->NextResult->datalength] = 0;
				port = atoi(tmp);
				
				pr3 = ILibParseString(pr2->FirstResult->NextResult->NextResult->NextResult->NextResult->data, 0, pr2->FirstResult->NextResult->NextResult->NextResult->NextResult->datalength, ".", 1);					
				if (pr3->NumResults == 4)
				{
					candidateData = pr3->FirstResult->data;
					pr3->FirstResult->data[pr3->FirstResult->datalength] = 0;
					candidateData[0] = (char)atoi(pr3->FirstResult->data);
					pr3->FirstResult->NextResult->data[pr3->FirstResult->NextResult->datalength] = 0;
					candidateData[1] = (char)atoi(pr3->FirstResult->NextResult->data);
					pr3->FirstResult->NextResult->NextResult->data[pr3->FirstResult->NextResult->NextResult->datalength] = 0;
					candidateData[2] = (char)atoi(pr3->FirstResult->NextResult->NextResult->data);
					pr3->FirstResult->NextResult->NextResult->NextResult->data[pr3->FirstResult->NextResult->NextResult->NextResult->datalength] = 0;
					candidateData[3] = (char)atoi(pr3->FirstResult->NextResult->NextResult->NextResult->data);

					((unsigned short*)candidateData)[2] = htons(port);
					candidateData[6] = 0;

					ILibPushStack(&candidates, candidateData);
					++candidatecount;
				}
				ILibDestructParserResults(pr3);
			}

			ILibDestructParserResults(pr2);
        }
		f = f->NextResult;
    }

	if (*username == NULL || *password == NULL || dtlshash == NULL || candidatecount == 0)
    {
		*block = NULL;
		return(0);
    }

	
	blockLen = 6 + strlen(*username)+1 + strlen(*password)+1  + dtlsHashLen + 1 + (candidatecount*6)+1;
	if((*block = (char*)malloc(blockLen))==NULL){ILIBCRITICALEXIT(254);}
	ptr = 0;

	((unsigned short*)*block+ptr)[0] = htons(1);
	ptr += 2;

	((unsigned int*)(*block+ptr))[0] = htonl(BlockFlags);
	ptr += 4;

	(*block)[ptr] = (char)strlen(*username);
	ptr += 1;
	memcpy(*block+ptr, *username, strlen(*username));
	ptr += strlen(*username);

	(*block)[ptr] = (char)strlen(*password);
	ptr += 1;
	memcpy(*block+ptr, *password, strlen(*password));
	ptr += strlen(*password);

	(*block)[ptr] = (char)dtlsHashLen;
	ptr += 1;
	memcpy(*block+ptr, dtlshash, dtlsHashLen);
	ptr += dtlsHashLen;

	(*block)[ptr] = (char)candidatecount;
	ptr += 1;
	while(ILibPeekStack(&candidates)!=NULL)
	{
		memcpy(*block+ptr, ILibPopStack(&candidates), 6);
		ptr += 6;
	}

	ILibDestructParserResults(pr);
	free(lines);
	if(dtlshash!=NULL) {free(dtlshash);}
	return(ptr);
}