⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commandlineshell.c

📁 intel upnp stack source code
💻 C
📖 第 1 页 / 共 3 页
字号:
	{		key = NULL;		keyLength = 0;		data = NULL;		charData = NULL;		ILibHashTree_GetValue(enumerator, &key, &keyLength, &data);		charData = (char*)data;		if(0 != keyLength)		{			char * tmp = malloc(keyLength + 1);			memcpy(tmp, key, keyLength);			tmp[keyLength] = '\0';			tmppath = tmp;			ignoreRoot(&tmppath);			changeDelimiter(tmppath, DEFAULTDELIMITER);			printf("%d)\t%s (%s)\n", ++numDevices, charData, tmppath);			free(tmp);		}	}	while(!ILibHashTree_MoveNext(enumerator));	ILibHashTree_DestroyEnumerator(enumerator);	if(numDevices == 0)	{		printf("None available\n");		retVal = MakeStrcpy(NULL);;	}	else	{		attemptsLeft = 3;		while(attemptsLeft > 0)		{			fgets(tmp_buffer, TMP_BUFFER_SIZE, stdin);			StrChomp(tmp_buffer);			if(1 != sscanf(tmp_buffer, "%d", &chosenIndex))			{				printf("Please enter a number\n");			}			else if(chosenIndex < 0 || chosenIndex > numDevices)			{				printf("Please choose one of the above, or 0 for none\n");				attemptsLeft--;			}			else			{					attemptsLeft = 0;			}		}		if(0 == chosenIndex)		{			retVal = MakeStrcpy(NULL);		}		else		{			enumerator = ILibHashTree_GetEnumerator(theILibHashTable);			for(i=0; i<chosenIndex; i++) ILibHashTree_MoveNext(enumerator);			key = NULL;			keyLength = 0;			data = NULL;			charData = NULL;			ILibHashTree_GetValue(enumerator, &key, &keyLength, &data);			retVal = malloc(keyLength+1);			memcpy(retVal, key, keyLength);			retVal[keyLength] = '\0';			ILibHashTree_DestroyEnumerator(enumerator);		}			}	ILibHashTree_UnLock(theILibHashTable);	return retVal;}static void handleCmd_ls(){	char * tmp, delimiter;	if(mostRecentBrowseResults != NULL)	{		unsigned int currObjectClass;		void *current_node = ILibLinkedList_GetNode_Head(mostRecentBrowseResults->LinkedList);		printf("There were %d results\n", mostRecentBrowseResults->TotalMatches);		while(current_node != NULL)		{			struct MMSCP_MediaObject *currObject = ILibLinkedList_GetDataFromNode(current_node);			currObjectClass = MMSCP_CLASS_MASK_OBJECTTYPE & currObject->MediaClass;			tmp = currObject->ID;			ignoreRoot(&tmp);			identifyDelimiter(&delimiter, tmp);			ignoreParentPath(&tmp, delimiter);			if(MMSCP_CLASS_MASK_CONTAINER == currObjectClass)			{									printf("Container: %s (%s)\n", currObject->Title, tmp);			}			else if(MMSCP_CLASS_MASK_ITEM == currObjectClass)			{				printf("Item:      %s (%s)\n", currObject->Title, tmp);				/*if (currObject->Res)				  {				  if (currObject->Res->Uri)				  printf("    %s\n", currObject->Res->Uri);				  if (currObject->Res->ProtocolInfo)				  printf("    proto : %s\n", currObject->Res->ProtocolInfo);				  }*/			}			else			{				printf("Bad Class: %s (%s)\n", currObject->Title, tmp);			}			current_node = ILibLinkedList_GetNextNode(current_node);		}		MMSCP_DestroyResultsList(mostRecentBrowseResults);		mostRecentBrowseResults = NULL;	}}// returns 0 on successstatic int DoBrowse(void (*callback)(void)){	int success = -1;	struct UPnPService *service;	struct UPnPDevice *dev = getCurrentMServer();	if(NULL != dev)	{		/* #### Begin CARDEA code #### */		if (dev->ms_upnp){			if (!(ms_device_status(dev->ms_upnp) & MS_ISAUTHORIZED)){				fprintf(stderr,"Not authorized to browse %s\n", dev->FriendlyName);				return -1;			}		}		/* #### End CARDEA code #### */		browseArgs.BrowseFlag = MMSCP_BrowseFlag_Children;		browseArgs.Filter = "res";		browseArgs.ObjectID = ILibPeekStack(&currBrowseDirectoryStack);		browseArgs.RequestedCount = 256;		browseArgs.SortCriteria = "";		browseArgs.StartingIndex = 0;		browseArgs.UserObject = callback;		service = MSCP_GetService_ContentDirectory(dev);				// send off the browse packet.  Note that this will		// only block until the browse packet is queued up for		// sending.  There is a call to waitForResponse in order		// to block until the response comes back.		MMSCP_Invoke_Browse(service, &browseArgs);				// block until the list comes back so that the 		// user doesn't get a prompt until the listing is		// done. Applies if and only if ASYNC_UI is defined.		//waitForResponse();		success = 0;	}	return success;}static void handleCmd_getms(){	struct UPnPDevice *dev = getCurrentMServer();	if(NULL != dev)	{		printf("Current media server: %s\n", dev->FriendlyName);		MSCP_Release(dev);	}	else	{		// this output is taken care of by the getCurrentMServer call	}}static void handleCmd_setms(){	// prompt the user to choose a new Media server from the 	// list of known devices, and store the UDN to currMServerUDN	free(currMServerUDN);	currMServerUDN = chooseIDFromTable(MS_KnownDevicesTable);		/* Begin PFS code */    pfs_cardea.prefetch_area = RMMalloc(PFS_BUF_SIZE);    pfs_cardea.prefetch_area_size = PFS_BUF_SIZE;    pfs_cardea.prefetch_slots = MAX_CACHEABLE_URL;    RMMemset(pfs_cardea.prefetch_area, 0x80, PFS_BUF_SIZE);	RMDBGLOG((ENABLE, "Initing PFS..."));	rmpfs_open(&pfs_cardea);	pfs_init = TRUE;	RMDBGPRINT((ENABLE, "done!\n"));	/* End PFD code */	// make sure that if we were browsing on a previous server, we pop back 	// down to the root	popDirectoryStackToRoot();}/* #### Begin CARDEA code #### *//** * Try to get a MS license for the current context of the current device * @param uri - URL to get * @param session_header - returned session header if MS DRM */static RMstatus try_get_ms_license(char *uri, char **session_header){	struct UPnPDevice *dev = getCurrentMServer();	RMint32 status;	ms_upnp_extension *ms_upnp;	if (uri == NULL)		return;		if (dev && dev->ms_upnp){		struct timeval tv1, tv2;		long int tv_sec, tv_usec;		ms_upnp = dev->ms_upnp;		/* Try to get a license for this URL */		fprintf(stderr,"MS server, try to get a license\n");		gettimeofday(&tv1, NULL);		status = get_ms_license(ms_upnp, uri, session_header);		gettimeofday(&tv2, NULL);		if (status){			fprintf(stderr,"Cannot get MS license, or no license needed : %ld\n", -status);			session_header = NULL;			if (status == -DRM_MUST_REGISTER){				/* We have to register again */				RMint32 register_status;				fprintf(stderr,"Try to register with %s\n", dev->FriendlyName);				register_status = register_ms_client(ms_upnp);				if (register_status < 0)					fprintf(stderr,"Error registering at %s : %ld\n", dev->FriendlyName, register_status);				else					fprintf(stderr,"Registration at %s started.\n", dev->FriendlyName);			}		}		tv_sec = tv2.tv_sec - tv1.tv_sec;		tv_usec = tv2.tv_usec - tv1.tv_usec;		if (tv_usec < 0) {			tv_sec--;			tv_usec = 1000000 + tv_usec;		}		printf("Time elapsed during license aquisition : %lu s %lu us\n", tv_sec, tv_usec);	}	return status ? RM_ERROR : RM_OK;}/* #### End CARDEA code #### */static void handleCmd_play(){	char *newObjID;	char *uri_buf = NULL;	char *session_header;	RMstatus prefetch_license = FALSE;	if(mostRecentBrowseResults != NULL)	{		struct ILibHashTree *items = ILibInitHashTree();		struct ILibHashTree *urls = ILibInitHashTree();		void *current_node = ILibLinkedList_GetNode_Head(mostRecentBrowseResults->LinkedList);		while(current_node != NULL)		{			struct MMSCP_MediaObject *currObject = ILibLinkedList_GetDataFromNode(current_node);			if(MMSCP_CLASS_MASK_ITEM & currObject->MediaClass)			{				ILibAddEntry(						items, 						currObject->ID, 						(int)strlen(currObject->ID), 						currObject->Title);				if (currObject->Res && currObject->Res->Uri)				{					ILibAddEntry(							urls,							currObject->ID,							(int)strlen(currObject->ID),							currObject->Res->Uri);				}			}			current_node = ILibLinkedList_GetNextNode(current_node);		}		newObjID = chooseIDFromTable(items);		if(newObjID[0] != '\0')		{			char *uri = NULL, *title = NULL;			int slot, i;			title = ILibGetEntry(items, newObjID, strlen(newObjID));			uri = ILibGetEntry(urls, newObjID, strlen(newObjID));			if (uri && title)			{				int status;				printf("Play %s (%s) from %s\n", title, newObjID, uri);					/* #### Begin CARDEA code #### */				if ( RMFAILED(prefetch_license) )					try_get_ms_license(uri, &session_header);				/* #### End CARDEA code #### */				status = start_playback(uri);				if (status < 0){					printf("Error : %d\n", status);				} else {					printf("OK\n");				}				for( i=0; i < MAX_NUMBER_OF_CACHEABLE_URL; i++) {					RMDBGLOG((ENABLE, "checking: %d, 0x%08x\n", i, pfs_cache[i]));										if ( (pfs_cache[i] != NULL) &&						(RMMatchAscii(uri, pfs_cache[i]) == 0) ) {						printf("wiping %s from pfs cache...\n", uri);						rmpfs_close_slot(i);						RMFree(pfs_cache[i]);						pfs_cache[i] = NULL;						buf_first--;						break;					}				}			}			else				printf("Cannot get %s, no URL\n", newObjID);		}		free(newObjID);		MMSCP_DestroyResultsList(mostRecentBrowseResults);		mostRecentBrowseResults = NULL;		ILibDestroyHashTree(items);		ILibDestroyHashTree(urls);	}}static void handleCmd_prebuf(){	char *newObjID;	int i = 0;	char *session_header;	RMstatus prefetch_license = FALSE;	if(mostRecentBrowseResults != NULL)	{		struct ILibHashTree *items = ILibInitHashTree();		struct ILibHashTree *urls = ILibInitHashTree();		void *current_node = ILibLinkedList_GetNode_Head(mostRecentBrowseResults->LinkedList);		while(current_node != NULL)		{			struct MMSCP_MediaObject *currObject = ILibLinkedList_GetDataFromNode(current_node);			if(MMSCP_CLASS_MASK_ITEM & currObject->MediaClass)			{				ILibAddEntry(						items, 						currObject->ID, 						(int)strlen(currObject->ID), 						currObject->Title);				if (currObject->Res && currObject->Res->Uri)				{					/*if (currObject->Res->ProtocolInfo)					  printf("    proto : %s\n", currObject->Res->ProtocolInfo);*/					ILibAddEntry(							urls,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -