UtlBoolean SipPublishContentMgr::getContent(const char* resourceId, const char* eventTypeKey, const char* acceptHeaderValue, HttpBody*& content, UtlBoolean& isDefaultContent) { #ifdef TEST_PRINT osPrintf("SipPublishContentMgr::getContent(%s, %s, %s, ...)\n", resourceId, eventTypeKey, acceptHeaderValue); #endif UtlBoolean foundContent = FALSE; UtlString key(resourceId); key.append(eventTypeKey); PublishContentContainer* container = NULL; UtlHashMap contentTypes; isDefaultContent = FALSE; UtlBoolean acceptedTypesGiven = buildContentTypesContainer(acceptHeaderValue, contentTypes); lock(); // See if resource specific content exists container = (PublishContentContainer*) mContentEntries.find(&key); // No resource specific content check if the default exists if(container == NULL) { key = eventTypeKey; container = (PublishContentContainer*) mDefaultContentEntries.find(&key); if(container) { isDefaultContent = TRUE; } } if(container) { HttpBody* bodyPtr = NULL; UtlSListIterator contentIterator(container->mEventContent); while((bodyPtr = (HttpBody*)contentIterator())) { // No MIME types specified, take the first one if(!acceptedTypesGiven) { content = HttpBody::copyBody(*bodyPtr); foundContent = TRUE; break; } // Find the first match. The container has the bodies // in the servers preferred order. if(contentTypes.find(bodyPtr)) { content = HttpBody::copyBody(*bodyPtr); foundContent = TRUE; break; } } } else { OsSysLog::add(FAC_SIP, PRI_WARNING, "SipPublishContentMgr::getContent no container is found\n"); } unlock(); contentTypes.destroyAll(); return(foundContent); }
UtlBoolean SipPublishContentMgr::getContent(const char* resourceId, const char* eventTypeKey, const char* eventType, const char* acceptHeaderValue, HttpBody*& content, int& version, UtlBoolean& isDefaultContent, UtlBoolean fullState) { UtlBoolean foundContent = FALSE; UtlString key(resourceId); key.append(eventTypeKey); PublishContentContainer* container = NULL; isDefaultContent = FALSE; // Turn acceptHeaderValue into a HashBag of its components. // acceptedTypesGiven = FALSE if there are no components. UtlHashBag contentTypes; UtlBoolean acceptedTypesGiven = buildContentTypesContainer(acceptHeaderValue, contentTypes); lock(); UtlHashBag* pContent; if (fullState) { // Full content (this is the usual case) pContent = &mContentEntries; } else { // Partial content (used for partial dialog events) pContent = &mPartialContentEntries; } // See if resource-specific content exists container = dynamic_cast <PublishContentContainer*> (pContent->find(&key)); // There is no resource-specific content. Check if the default // constructor exists. if (container == NULL) { // Construct the key for the default data. UtlString default_key(eventTypeKey); // Look up the constructor. SipPublishContentMgrDefaultConstructor* constructor = dynamic_cast <SipPublishContentMgrDefaultConstructor*> (mDefaultContentConstructors.findValue(&default_key)); // If it exists, call it to publish content for this resource/event. if (constructor) { constructor->generateDefaultContent(this, resourceId, eventTypeKey, eventType); } // See if resource specific content exists now. container = dynamic_cast <PublishContentContainer*> (pContent->find(&key)); // If content was found, still mark it as default content. if (container) { isDefaultContent = TRUE; } // If still no content was found, check if the default exists. else { container = dynamic_cast <PublishContentContainer*> (mDefaultContentEntries.find(&default_key)); if(container) { isDefaultContent = TRUE; } } } // Within the container, find the content of the right MIME type. if (container) { if (acceptedTypesGiven) { UtlString base_mime_type; // Search for the first content in the container whose // MIME type is in the acceptable list. UtlSListIterator contentIterator(container->mEventContent); HttpBody* bodyPtr; UtlSListIterator versionIterator(container->mEventVersion); UtlInt* versionPtr; while (!foundContent && (bodyPtr = dynamic_cast <HttpBody*> (contentIterator())) && (versionPtr = dynamic_cast <UtlInt*> (versionIterator()))) { // Test if ';' is present in *bodyPtr's MIME type. // (Remember that an HttpBody considered as a UtlString has // the value of its content type.) ssize_t i = bodyPtr->index(';'); // The 'if expression' is TRUE if the MIME type of *bodyPtr // is found in in contentTypes. This is messy, because // *bodyPtr's MIME type may have parameters, which have // to be removed before searching contentTypes. if (contentTypes.find(i == UTL_NOT_FOUND ? bodyPtr : ( base_mime_type.remove(0), base_mime_type.append(*bodyPtr, 0, i), &base_mime_type))) { content = bodyPtr->copy(); version = versionPtr->getValue(); foundContent = TRUE; } } if (!foundContent) { // No content was found that matched the required MIME types. OsSysLog::add(FAC_SIP, PRI_WARNING, "SipPublishContentMgr::getContent no content found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s'", key.data(), acceptHeaderValue ? acceptHeaderValue : "[none]", resourceId ? resourceId : "[none]", eventTypeKey, eventType); } } else { // No MIME types were specified, take the first content in the list. HttpBody* bodyPtr = dynamic_cast <HttpBody*> (container->mEventContent.first()); UtlInt* versionPtr = dynamic_cast <UtlInt*> (container->mEventVersion.first()); if (bodyPtr) { content = bodyPtr->copy(); version = versionPtr->getValue(); foundContent = TRUE; } else { // No content was found (at all). OsSysLog::add(FAC_SIP, PRI_WARNING, "SipPublishContentMgr::getContent no content found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s'", key.data(), acceptHeaderValue ? acceptHeaderValue : "[none]", resourceId ? resourceId : "[none]", eventTypeKey, eventType); } } } else { // No container found for this resource and event. OsSysLog::add(FAC_SIP, PRI_WARNING, "SipPublishContentMgr::getContent no container found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s', fullState = %d", key.data(), acceptHeaderValue ? acceptHeaderValue : "[none]", resourceId ? resourceId : "[none]", eventTypeKey, eventType, fullState); } unlock(); contentTypes.destroyAll(); return (foundContent); }