/*---------------------------------------------------------------------- | main +---------------------------------------------------------------------*/ int main(int, char**) { NPT_LogManager::GetDefault().Configure("plist:.level=ALL;"); NPT_LOG_L(MyLogger, NPT_LOG_LEVEL_WARNING, "blabla"); NPT_LOG_L2(MyLogger, NPT_LOG_LEVEL_WARNING, "blabla %d %d", 8, 9); NPT_LOG(NPT_LOG_LEVEL_WARNING, "blibli"); NPT_LOG_2(NPT_LOG_LEVEL_INFO, "fofo %d %d", 5, 7); NPT_LOG_SEVERE("this is severe!"); NPT_LOG_SEVERE_1("this is severe (%d)", 9); NPT_LOG_SEVERE_L(MyLogger, "this is severe!"); NPT_LOG_SEVERE_L1(MyLogger, "this is severe (%d)", 9); NPT_LOG_SEVERE_L(FooLogger, "this is severe!"); NPT_LOG_SEVERE_L1(FooLogger, "this is severe (%d)", 9); NPT_LOG_SEVERE("severe"); NPT_LOG_WARNING("warning"); NPT_LOG_INFO("info"); NPT_LOG_FINE("fine"); NPT_LOG_FINER("finer"); NPT_LOG_FINEST("finest"); NPT_LOG_SEVERE_L(FooLogger, "severe"); NPT_LOG_WARNING_L(FooLogger, "warning"); NPT_LOG_INFO_L(FooLogger, "info"); NPT_LOG_FINE_L(FooLogger, "fine"); NPT_LOG_FINER_L(FooLogger, "finer"); NPT_LOG_FINEST_L(FooLogger, "finest"); TestLargeBuffer(); TestCheck(); TestCheckSevere(); TestCheckWarning(); TestCheckInfo(); TestCheckFine(); TestCheckFiner(); TestCheckFinest(); TestCheckL(); TestCheckSevereL(); TestCheckWarningL(); TestCheckInfoL(); TestCheckFineL(); TestCheckFinerL(); TestCheckFinestL(); return 0; }
/*---------------------------------------------------------------------- | PLT_MediaServer::ParseTagList +---------------------------------------------------------------------*/ NPT_Result PLT_MediaServer::ParseTagList(const NPT_String& updates, NPT_Map<NPT_String,NPT_String>& tags) { // reset output params first tags.Clear(); NPT_List<NPT_String> split = updates.Split(","); NPT_XmlNode* node = NULL; NPT_XmlElementNode* didl_partial = NULL; NPT_XmlParser parser; // as these are single name value pairs, separated by commas we wrap in a tag // to create a valid tree NPT_String xml("<TagValueList>"); for (NPT_List<NPT_String>::Iterator entry = split.GetFirstItem(); entry; entry++) { NPT_String& element = (*entry); if (element.IsEmpty()) xml.Append("<empty>empty</empty>"); else xml.Append(element); } xml.Append("</TagValueList>"); NPT_LOG_FINE("Parsing TagList..."); NPT_CHECK_LABEL_SEVERE(parser.Parse(xml, node), cleanup); if (!node || !node->AsElementNode()) { NPT_LOG_SEVERE("Invalid node type"); goto cleanup; } didl_partial = node->AsElementNode(); if (didl_partial->GetTag().Compare("TagValueList", true)) { NPT_LOG_SEVERE("Invalid node tag"); goto cleanup; } for (NPT_List<NPT_XmlNode*>::Iterator children = didl_partial->GetChildren().GetFirstItem(); children; children++) { NPT_XmlElementNode* child = (*children)->AsElementNode(); if (!child) continue; tags[child->GetTag()] = *child->GetText(); } return NPT_SUCCESS; cleanup: if (node) delete node; return NPT_FAILURE; }
/*---------------------------------------------------------------------- | TestLargeBuffer +---------------------------------------------------------------------*/ static void TestLargeBuffer(void) { char* buffer = new char[32768]; int i; for (i=0; i<32768; i++) { buffer[i] = 'a'; } buffer[32767] = 0; NPT_LOG_SEVERE(buffer); delete[] buffer; }
/*---------------------------------------------------------------------- | PLT_HttpHelper::SetContentRange +---------------------------------------------------------------------*/ NPT_Result PLT_HttpHelper::SetContentRange(NPT_HttpResponse* response, NPT_Integer start, NPT_Integer end, NPT_Integer length) { if (start < 0 || end < 0 || length < 0) { NPT_LOG_SEVERE("ERROR: Invalid Content Range!"); return NPT_FAILURE; } NPT_String range = "bytes "; range += NPT_String::FromInteger(start); range += '-'; range += NPT_String::FromInteger(end); range += '/'; range += NPT_String::FromInteger(length); response->GetHeaders().SetHeader(NPT_HTTP_HEADER_CONTENT_RANGE, range); return NPT_SUCCESS; }
static NPT_Result TestCheckFinerL(void) { NPT_CHECK_FINER_L(FooLogger, NPT_FAILURE); NPT_LOG_SEVERE("###"); return NPT_SUCCESS; }
static NPT_Result TestCheckInfoL(void) { NPT_CHECK_INFO_L(FooLogger, NPT_FAILURE); NPT_LOG_SEVERE("###"); return NPT_SUCCESS; }
static NPT_Result TestCheckWarningL(void) { NPT_CHECK_WARNING_L(FooLogger, NPT_FAILURE); NPT_LOG_SEVERE("###"); return NPT_SUCCESS; }
static NPT_Result TestCheckSevereL(void) { NPT_CHECK_SEVERE(NPT_FAILURE); NPT_LOG_SEVERE("###"); return NPT_SUCCESS; }
static NPT_Result TestCheckFinest(void) { NPT_CHECK_FINEST(NPT_FAILURE); NPT_LOG_SEVERE("###"); return NPT_SUCCESS; }
static NPT_Result TestCheckInfo(void) { NPT_CHECK_INFO(NPT_FAILURE); NPT_LOG_SEVERE("###"); return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | TestCheck functions +---------------------------------------------------------------------*/ static NPT_Result TestCheck(void) { NPT_CHECK_L(NPT_LOG_LEVEL_WARNING, NPT_FAILURE); NPT_LOG_SEVERE("###"); return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_Didl::FromDidl +---------------------------------------------------------------------*/ NPT_Result PLT_Didl::FromDidl(const char* xml, PLT_MediaObjectListReference& objects) { NPT_String str; PLT_MediaObject* object = NULL; NPT_XmlNode* node = NULL; NPT_XmlElementNode* didl = NULL; NPT_XmlParser parser; NPT_LOG_FINE("Parsing Didl..."); NPT_CHECK_LABEL_SEVERE(parser.Parse(xml, node), cleanup); if (!node || !node->AsElementNode()) { NPT_LOG_SEVERE("Invalid node type"); goto cleanup; } didl = node->AsElementNode(); if (didl->GetTag().Compare("DIDL-Lite", true)) { NPT_LOG_SEVERE("Invalid node tag"); goto cleanup; } // create entry list objects = new PLT_MediaObjectList(); // for each child, find out if it's a container or not // and then invoke the FromDidl on it for (NPT_List<NPT_XmlNode*>::Iterator children = didl->GetChildren().GetFirstItem(); children; children++) { NPT_XmlElementNode* child = (*children)->AsElementNode(); if (!child) continue; if (child->GetTag().Compare("Container", true) == 0) { object = new PLT_MediaContainer(); } else if (child->GetTag().Compare("item", true) == 0) { object = new PLT_MediaItem(); } else { NPT_LOG_WARNING("Invalid node tag"); continue; } if (NPT_FAILED(object->FromDidl(child))) { NPT_LOG_WARNING_1("Invalid didl for object: %s", (const char*) PLT_XmlHelper::Serialize(*child, false)); continue; } objects->Add(object); object = NULL; // reset to make sure it doesn't get deleted twice in case of error } delete node; return NPT_SUCCESS; cleanup: objects = NULL; delete node; delete object; return NPT_FAILURE; }