void ILibWebServer_Destroy(void *object) { struct ILibWebServer_StateModule *s = (struct ILibWebServer_StateModule*)object; void *en; void *data; char *key; int keyLength; if(s->VirtualDirectoryTable!=NULL) { en = ILibHashTree_GetEnumerator(s->VirtualDirectoryTable); while(ILibHashTree_MoveNext(en)==0) { ILibHashTree_GetValue(en,&key,&keyLength,&data); free(data); } ILibHashTree_DestroyEnumerator(en); ILibDestroyHashTree(s->VirtualDirectoryTable); } }
char *DLNAProtocolInfo_Serialize(struct DLNAProtocolInfo *protocolInfo) { char *RetVal; int RetValLength = 0; unsigned long flags = 0; int i; void *en; char *key; int keyLength; void *data; // http-get:*:audio/mpeg:DLNA.ORG_PN=MPEG_PS_NTSC;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=05100000000000000000000000000000 switch(protocolInfo->Protocol) { case DLNAProtocolInfo_ProtocolType_RTP: RetValLength += 12; break; case DLNAProtocolInfo_ProtocolType_HTTP: RetValLength += 8; break; default: break; } RetValLength += 3; // :*: if(protocolInfo->MimeType!=NULL) { RetValLength += (int)strlen(protocolInfo->MimeType); } RetValLength += 1; // : if(protocolInfo->SupportedPlaySpeedsLength>0) { RetValLength += 12; // DLNA.ORG_PS= for(i=0;i<protocolInfo->SupportedPlaySpeedsLength;++i) { if(i!=0) { RetValLength += 1; // , } RetValLength += (int)strlen(protocolInfo->SupportedPlaySpeeds[i]); } RetValLength += 1; // ; } if(protocolInfo->IsConvertedContent!=0) { RetValLength += 14; // DLNA.ORG_CI=1; } if(protocolInfo->MaxSpeed_Major+protocolInfo->MaxSpeed_Minor!=0) { RetValLength += 32; //DLNA.ORG_MAXSP=xxx.xxx; } // // Fourth Field Stuff // if(protocolInfo->Profile!=NULL) { RetValLength += (13 + (int)strlen(protocolInfo->Profile)); } RetValLength += 15; // DLNA.ORG_OP=01; RetValLength += 48; // DLNA.ORG_FLAGS=05100000000000000000000000000000 if(protocolInfo->NameValueTable!=NULL) { en = ILibHashTree_GetEnumerator(protocolInfo->NameValueTable); while(ILibHashTree_MoveNext(en)==0) { ILibHashTree_GetValue(en,&key,&keyLength,&data); if( !(keyLength==14&&memcmp(key,"DLNA.ORG_FLAGS",keyLength)==0) && !(keyLength==14&&memcmp(key,"DLNA.ORG_MAXSP",keyLength)==0) && !(keyLength==11&&memcmp(key,"DLNA.ORG_CI",keyLength)==0) && !(keyLength==11&&memcmp(key,"DLNA.ORG_PS",keyLength)==0) && !(keyLength==11&&memcmp(key,"DLNA.ORG_OP",keyLength)==0) && !(keyLength==11&&memcmp(key,"DLNA.ORG_PN",keyLength)==0) ) { RetValLength += (keyLength+(int)strlen((char*)data)+2); // key=value; } } ILibHashTree_DestroyEnumerator(en); } // // Lets actually serialize the structure // RetVal = (char*)malloc(RetValLength+1); memset(RetVal,0,RetValLength+1); RetValLength = 0; switch(protocolInfo->Protocol) { case DLNAProtocolInfo_ProtocolType_RTP: RetValLength = sprintf(RetVal,"rtsp-rtp-udp"); break; case DLNAProtocolInfo_ProtocolType_HTTP: RetValLength = sprintf(RetVal,"http-get"); break; default: break; } RetValLength += sprintf(RetVal+RetValLength,":*:"); RetValLength += sprintf(RetVal+RetValLength,"%s:",protocolInfo->MimeType); // // Fourth Field Stuff // if(protocolInfo->Profile!=NULL) { RetValLength += sprintf(RetVal+RetValLength,"DLNA.ORG_PN=%s;",protocolInfo->Profile); } switch(protocolInfo->Protocol) { case DLNAProtocolInfo_ProtocolType_RTP: RetValLength += sprintf(RetVal+RetValLength,"DLNA.ORG_OP=0%d;",protocolInfo->SupportsTimeBasedSeek); break; case DLNAProtocolInfo_ProtocolType_HTTP: RetValLength += sprintf(RetVal+RetValLength,"DLNA.ORG_OP=%d%d;",protocolInfo->SupportsTimeBasedSeek,protocolInfo->SupportsByteBasedSeek); break; default: break; } // // Supported Play Speeds // if(protocolInfo->SupportedPlaySpeedsLength>0) { RetValLength += sprintf(RetVal+RetValLength,"DLNA.ORG_PS="); for(i=0;i<protocolInfo->SupportedPlaySpeedsLength;++i) { if(i!=0) { RetValLength += sprintf(RetVal+RetValLength,","); } RetValLength += sprintf(RetVal+RetValLength,"%s",protocolInfo->SupportedPlaySpeeds[i]); } RetValLength += sprintf(RetVal+RetValLength,";"); } // // Conversion Indication // if(protocolInfo->IsConvertedContent!=0) { RetValLength += sprintf(RetVal+RetValLength,"DLNA.ORG_CI=1;"); } // // Max Speed // if(protocolInfo->MaxSpeed_Major + protocolInfo->MaxSpeed_Minor != 0) { RetValLength += sprintf(RetVal+RetValLength,"DLNA.ORG_MAXSP=%d.%d;",protocolInfo->MaxSpeed_Major,protocolInfo->MaxSpeed_Minor); } if(protocolInfo->DLNA_Major_Version==1 && protocolInfo->DLNA_Minor_Version==5) { DLNA_Bits(&flags)->Bit20 = 1; } if(protocolInfo->DLNA_Major_Version==1 && protocolInfo->DLNA_Minor_Version>=5) { DLNA_Bits(&flags)->Bit31 = protocolInfo->SenderPaced; DLNA_Bits(&flags)->Bit30 = protocolInfo->LimitedOperations_TimeBasedSeek; DLNA_Bits(&flags)->Bit29 = protocolInfo->LimitedOperations_ByteBasedSeek; DLNA_Bits(&flags)->Bit28 = protocolInfo->DLNAPlayContainer; DLNA_Bits(&flags)->Bit27 = protocolInfo->S0_Increasing; DLNA_Bits(&flags)->Bit26 = protocolInfo->SN_Increasing; DLNA_Bits(&flags)->Bit25 = protocolInfo->RTSP_Pause; DLNA_Bits(&flags)->Bit24 = protocolInfo->TM_S; DLNA_Bits(&flags)->Bit23 = protocolInfo->TM_I; DLNA_Bits(&flags)->Bit22 = protocolInfo->TM_B; DLNA_Bits(&flags)->Bit21 = protocolInfo->HTTP_Stalling; } RetValLength += sprintf(RetVal+RetValLength,"DLNA.ORG_FLAGS=%08lX%024d;",flags,0); if(protocolInfo->NameValueTable!=NULL) { en = ILibHashTree_GetEnumerator(protocolInfo->NameValueTable); while(ILibHashTree_MoveNext(en)==0) { ILibHashTree_GetValue(en,&key,&keyLength,&data); if( !(keyLength==14&&memcmp(key,"DLNA.ORG_FLAGS",keyLength)==0) && !(keyLength==14&&memcmp(key,"DLNA.ORG_MAXSP",keyLength)==0) && !(keyLength==11&&memcmp(key,"DLNA.ORG_CI",keyLength)==0) && !(keyLength==11&&memcmp(key,"DLNA.ORG_PS",keyLength)==0) && !(keyLength==11&&memcmp(key,"DLNA.ORG_OP",keyLength)==0) && !(keyLength==11&&memcmp(key,"DLNA.ORG_PN",keyLength)==0) ) { key[keyLength]=0; RetValLength += sprintf(RetVal+RetValLength,"%s=%s;",key,(char*)data); } } ILibHashTree_DestroyEnumerator(en); } if(RetVal[RetValLength-1]==';') { RetVal[RetValLength-1]=0; } return(RetVal); }