📄 commandlineshell.c
字号:
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; /* #### Begin CARDEA code #### */ if ( buf_first >= MAX_CACHEABLE_URL ) { printf("All out of slots to prebuffer in!\n"); } else { if ( RMFAILED(try_get_ms_license(uri, &session_header))) RMDBGLOG((ENABLE, "unable to get license for uri \'%s\'.... \n", uri)); printf("Prebuffer %s (%s) from %s\n", title, newObjID, uri); // find the first available slot for(i=0; i <= MAX_CACHEABLE_URL && pfs_cache[i] != NULL; i++) {}; rmpfs_allocate_slot_to_url(uri, i); RMDBGLOG((ENABLE, "prefetching slot %d.... \n", buf_first)); if ( !RMFAILED(rmpfs_prefetch_slot(i)) ) { pfs_cache[i] = RMMallocAndDuplicateAscii(uri); RMDBGLOG((ENABLE, "putting in string: 0x%08x\n", pfs_cache[i])); buf_first++; } } /* #### End CARDEA code #### */ } free(newObjID); MMSCP_DestroyResultsList(mostRecentBrowseResults); mostRecentBrowseResults = NULL; ILibDestroyHashTree(items); ILibDestroyHashTree(urls); } }}static void handleCmd_get(){ char *newObjID; 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, 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; title = ILibGetEntry(items, newObjID, strlen(newObjID)); uri = ILibGetEntry(urls, newObjID, strlen(newObjID)); if (uri && title) { int status; char *session_header = NULL; printf("Get %s (%s) from %s\n", title, newObjID, uri); /* #### Begin CARDEA code #### */ try_get_ms_license(uri, &session_header); /* #### End CARDEA code #### */ status = http_get(uri, session_header); if (status < 0){ printf("Error : %d\n", status); } else { printf("%d: %d OK\n", __FILE__ , __LINE__); } } else printf("Cannot get %s, no URL\n", newObjID); } free(newObjID); MMSCP_DestroyResultsList(mostRecentBrowseResults); mostRecentBrowseResults = NULL; ILibDestroyHashTree(items); ILibDestroyHashTree(urls); }}static void handleCmd_cd(){ char *newObjID; if(mostRecentBrowseResults != NULL) { struct ILibHashTree *containers = 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_CONTAINER & currObject->MediaClass) { ILibAddEntry( containers, currObject->ID, (int)strlen(currObject->ID), currObject->Title); } current_node = ILibLinkedList_GetNextNode(current_node); } newObjID = chooseIDFromTable(containers); if(newObjID[0] != '\0') { ILibPushStack(&currBrowseDirectoryStack, newObjID); } else { free(newObjID); } MMSCP_DestroyResultsList(mostRecentBrowseResults); mostRecentBrowseResults = NULL; ILibDestroyHashTree(containers); }}static void handleCmd_cdup(){ // we don't want to pop the root off now.... if(strcmp("0", ILibPeekStack(&currBrowseDirectoryStack))) { free(ILibPopStack(&currBrowseDirectoryStack)); }}static void handleCmd_pwd(){ void *tempStack; char *tempStr; //There is two kinds of objectID, one provide full path, //the other just provide raletive path if(strncmp("0", ILibPeekStack(&currBrowseDirectoryStack), 1) == 0) {//full path tempStr = ILibPeekStack(&currBrowseDirectoryStack); ignoreRoot(&tempStr); changeDelimiter(tempStr, DEFAULTDELIMITER); printf("%sweb%s%c", CurrMServerURI, tempStr, DEFAULTDELIMITER); } else{//relative path ILibCreateStack(&tempStack); while(ILibPeekStack(&currBrowseDirectoryStack)) { ILibPushStack(&tempStack, ILibPopStack(&currBrowseDirectoryStack)); } printf("%sweb", CurrMServerURI); while(ILibPeekStack(&tempStack)) { tempStr = ILibPopStack(&tempStack); ILibPushStack(&currBrowseDirectoryStack, tempStr); ignoreRoot(&tempStr); changeDelimiter(tempStr, DEFAULTDELIMITER); printf("%s%c", tempStr, DEFAULTDELIMITER); } ILibClearStack(&tempStack); } printf("\n"); }static void handleCmd_help(){ printf("\n\nNone of the commands require arguments. The commands with a * \n"); printf("signify ones that will prompt the user for more information once\n"); printf("the command is called\n\n"); printf("The available commands are:\n\n"); printf(" quit - shutdown the control point\n"); printf(" exit - same as quit\n"); printf(" setms - * select a media server to become the active media server\n"); printf(" getms - print the friendly name of the active media server\n"); printf(" ls - list the contents of the current directory on the active \n"); printf(" media server\n"); printf(" cd - * traverse down one level in the content tree on the active\n"); printf(" media server\n"); printf(" cdup - traverse up one level in the content tree on the active\n"); printf(" media server\n"); printf(" pwd - print the http path from the root to your current position in the \n"); printf(" content tree on the active media server\n"); printf(" get - * get an item (HTTP only)\n"); printf(" play - * play a link (needs mono)\n"); printf(" prebuf - * prebuffer a stream\n"); printf(" help - print this help message\n\n");}int CLShell_Run(void){ int status = -1; tmp_buffer[0] = '\0';#ifdef WIN32 //_CrtCheckMemory();#endif fflush(stdout); fgets(tmp_buffer, TMP_BUFFER_SIZE, stdin); StrChomp(tmp_buffer); if(0 == strcmp(tmp_buffer, "quit") || 0 == strcmp(tmp_buffer, "exit")) { /* TODO do something to quit pollAgain = 0; */ RMFree(pfs_cardea.prefetch_area); if( pfs_init ) rmpfs_close(); return -1; } else if(0 == strcmp(tmp_buffer, "setms")) { handleCmd_setms(); } else if(0 == strcmp(tmp_buffer, "getms")) { handleCmd_getms(); } else if(0 == strcmp(tmp_buffer, "ls")) { status = DoBrowse(handleCmd_ls); } else if(0 == strcmp(tmp_buffer, "cd")) { status = DoBrowse(handleCmd_cd); } else if(0 == strcmp(tmp_buffer, "cdup")) { handleCmd_cdup(); } else if(0 == strcmp(tmp_buffer, "pwd")) { handleCmd_pwd(); } else if(0 == strcmp(tmp_buffer, "help")) { handleCmd_help(); } else if(0 == strcmp(tmp_buffer, "get")) { status = DoBrowse(handleCmd_get); } else if(0 == strcmp(tmp_buffer, "play")) { status = DoBrowse(handleCmd_play); } else if(0 == strcmp(tmp_buffer, "prebuf")) { status = DoBrowse(handleCmd_prebuf); } else if(0 == strcmp(tmp_buffer, "")) { // just prompt again } else { printf("Unrecognized command: %s\n", tmp_buffer); handleCmd_help(); } if (status < 0){ /* This means it was not a command requiring I/O and callback * or that a browse request failed, in any case, there won't * be any callback to print the prompt for us, so print it */ prompt(); } return 0;}void CLShell_Init(void *chain){ // create the stack that will be the directory where the // user is currently browsing. ILibCreateStack(&currBrowseDirectoryStack); // push the root directory onto the directory stack. ILibPushStack(&currBrowseDirectoryStack, MakeStrcpy("0")); // Initially there is no server and no renderer selected currMServerUDN = MakeStrcpy(NULL); // the most recent results from a browse. This has to be a global // variable since the results come back through a callback function // instead of being returned to the requesting function. mostRecentBrowseResults = NULL; // the table of known devices on the network. These are updated via the // device added and device removed callbacks. Note that you should lock them // whenever accessing them with the ILibHashTree_Lock and ILibHashTree_UnLock methods MS_KnownDevicesTable = ILibInitHashTree(); // Add the control points to the main chain, and keep pointers to them for use // in the API calls. MS_ControlPoint = MMSCP_Init(chain, MSCP_BrowseResponded, MSCP_DeviceAddedOrRemoved); prompt();}void CLShell_Uninit(void){ // destroy the response wait semaphore. // clear off the directory stack by first popping down so that just // the root directory is on it. popDirectoryStackToRoot(); // then free the root directory free(ILibPopStack(&currBrowseDirectoryStack)); // finally, destroy the stack itself ILibClearStack(&currBrowseDirectoryStack); free(currMServerUDN); if(mostRecentBrowseResults != NULL) { free(mostRecentBrowseResults); mostRecentBrowseResults = NULL; } // destroy the lists of known nodes and null out their pointers. // note tat the ILibDestroyHashTree function calls free on both the // key and the data values stored in the table. ILibDestroyHashTree(MS_KnownDevicesTable); MS_KnownDevicesTable = NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -