本文整理汇总了C++中NPT_String::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_String::GetLength方法的具体用法?C++ NPT_String::GetLength怎么用?C++ NPT_String::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NPT_String
的用法示例。
在下文中一共展示了NPT_String::GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
/*----------------------------------------------------------------------
| CMediaCrawler::SplitObjectId
+---------------------------------------------------------------------*/
NPT_Result
CMediaCrawler::SplitObjectId(const NPT_String& object_id, NPT_String& server_uuid, NPT_String& server_object_id)
{
// reset output params
server_uuid = "";
server_object_id = "";
if (object_id.GetLength() == 0 || object_id[0] != '0')
return NPT_ERROR_INVALID_FORMAT;
if (object_id.GetLength() > 1) {
if (object_id[1] != '/') return NPT_ERROR_INVALID_FORMAT;
server_uuid = object_id.SubString(2);
// look for next delimiter
int index = server_uuid.Find('/');
if (index >= 0) {
server_object_id = server_uuid.SubString(index+1);
server_uuid.SetLength(index);
}
}
return NPT_SUCCESS;
}
示例2: while
/*----------------------------------------------------------------------
| NPT_DirectorySplitFilePath
+---------------------------------------------------------------------*/
NPT_Result
NPT_DirectorySplitFilePath(const char* filepath,
NPT_String& path,
NPT_String& filename)
{
if (!filepath || filepath[0] == '\0')
return NPT_ERROR_INVALID_PARAMETERS;
path = filepath;
char last_char;
NPT_Int32 i = path.GetLength();
do {
last_char = path[i-1];
if (last_char == '\\' || last_char == '/')
break;
} while (--i);
// we need at least one delimiter and it cannot be last
if (i == 0 || i == (NPT_Int32)path.GetLength()) {
return NPT_ERROR_INVALID_PARAMETERS;
}
// assign filename
filename = filepath+i;
// truncate path & remove trailing slashes
NPT_CHECK_FATAL(path.SetLength(i-1));
// remove excessive delimiters
path.TrimRight("/");
path.TrimRight("\\");
return NPT_SUCCESS;
}
示例3: ServeFile
/*----------------------------------------------------------------------
| PLT_FileMediaServer::ServeFile
+---------------------------------------------------------------------*/
NPT_Result
PLT_FileMediaServer::ServeFile(NPT_HttpRequest& request,
const NPT_HttpRequestContext& context,
NPT_HttpResponse& response,
const NPT_String& uri_path,
const NPT_String& file_path)
{
NPT_COMPILER_UNUSED(context);
// prevent hackers from accessing files outside of our root
if ((file_path.Find("/..") >= 0) || (file_path.Find("\\..") >= 0)) {
return NPT_FAILURE;
}
// File requested
NPT_String path = m_FileBaseUri.GetPath();
if (path.Compare(uri_path.Left(path.GetLength()), true) == 0) {
NPT_Position start, end;
PLT_HttpHelper::GetRange(request, start, end);
return PLT_FileServer::ServeFile(response,
NPT_FilePath::Create(m_Path, file_path),
start,
end,
!request.GetMethod().Compare("HEAD"));
}
// Album Art requested
path = m_AlbumArtBaseUri.GetPath();
if (path.Compare(uri_path.Left(path.GetLength()), true) == 0) {
return OnAlbumArtRequest(response, m_Path + file_path);
}
return NPT_FAILURE;
}
示例4:
/*----------------------------------------------------------------------
| NPT_String::NPT_String
+---------------------------------------------------------------------*/
NPT_String::NPT_String(const NPT_String& str)
{
if (str.GetLength() == 0) {
m_Chars = NULL;
} else {
m_Chars = Buffer::Create(str.GetChars(), str.GetLength());
}
}
示例5: query
/*----------------------------------------------------------------------
| PLT_FileMediaServer::ProcessFileRequest
+---------------------------------------------------------------------*/
NPT_Result
PLT_FileMediaServer::ProcessFileRequest(NPT_HttpRequest& request,
NPT_HttpResponse& response,
NPT_SocketInfo& client_info)
{
NPT_COMPILER_UNUSED(client_info);
NPT_LOG_FINE("PLT_FileMediaServer::ProcessFileRequest Received Request:");
PLT_LOG_HTTP_MESSAGE(NPT_LOG_LEVEL_FINE, &request);
response.GetHeaders().SetHeader("Accept-Ranges", "bytes");
if (request.GetMethod().Compare("GET") && request.GetMethod().Compare("HEAD")) {
response.SetStatus(500, "Internal Server Error");
return NPT_SUCCESS;
}
// File requested
NPT_String path = m_FileBaseUri.GetPath();
NPT_String strUri = NPT_Uri::PercentDecode(request.GetUrl().GetPath());
NPT_HttpUrlQuery query(request.GetUrl().GetQuery());
NPT_String file_path = query.GetField("path");
// hack for XBMC support for 360, we urlencoded the ? to that the 360 doesn't strip out the query
// but then the query ends being parsed as part of the path
int index = strUri.Find("path=");
if (index>0) file_path = strUri.Right(strUri.GetLength()-index-5);
if (file_path.GetLength() == 0) goto failure;
// HACK for wmp: somehow they inverse our slashes !
// do it only if we're on windows
if (m_DirDelimiter == "\\") {
file_path.Replace('/', '\\');
}
if (path.Compare(strUri.Left(path.GetLength()), true) == 0) {
NPT_Integer start, end;
PLT_HttpHelper::GetRange(&request, start, end);
return PLT_FileServer::ServeFile(m_Path + file_path, &response, start, end, !request.GetMethod().Compare("HEAD"));
}
// Album Art requested
path = m_AlbumArtBaseUri.GetPath();
if (path.Compare(strUri.Left(path.GetLength()), true) == 0) {
return OnAlbumArtRequest(m_Path + file_path, response);
}
failure:
response.SetStatus(404, "File Not Found");
return NPT_SUCCESS;
}
示例6:
/*----------------------------------------------------------------------
| PLT_MediaBrowser::OnSearchResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::OnSearchResponse(NPT_Result res,
PLT_DeviceDataReference& device,
PLT_ActionReference& action,
void* userdata)
{
NPT_String value;
PLT_BrowseInfo info;
NPT_String unescaped;
if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
goto bad_action;
}
if (NPT_FAILED(action->GetArgumentValue("ContainerId", info.object_id))) {
goto bad_action;
}
if (NPT_FAILED(action->GetArgumentValue("UpdateID", value)) ||
value.GetLength() == 0 ||
NPT_FAILED(value.ToInteger(info.uid))) {
goto bad_action;
}
if (NPT_FAILED(action->GetArgumentValue("NumberReturned", value)) ||
value.GetLength() == 0 ||
NPT_FAILED(value.ToInteger(info.nr))) {
goto bad_action;
}
if (NPT_FAILED(action->GetArgumentValue("TotalMatches", value)) ||
value.GetLength() == 0 ||
NPT_FAILED(value.ToInteger(info.tm))) {
goto bad_action;
}
if (NPT_FAILED(action->GetArgumentValue("Result", value)) ||
value.GetLength() == 0) {
goto bad_action;
}
if (NPT_FAILED(PLT_Didl::FromDidl(value, info.items))) {
goto bad_action;
}
if (m_Delegate) m_Delegate->OnSearchResult(NPT_SUCCESS, device, &info, userdata);
return NPT_SUCCESS;
bad_action:
if (m_Delegate) m_Delegate->OnSearchResult(NPT_FAILURE, device, NULL, userdata);
return NPT_FAILURE;
}
示例7: while
/*----------------------------------------------------------------------
| PLT_MediaServer::ParseSort
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaServer::ParseSort(const NPT_String& sort, NPT_List<NPT_String>& list)
{
// reset output params first
list.Clear();
// easy out
if (sort.GetLength() == 0 || sort == "*") return NPT_SUCCESS;
list = sort.Split(",");
// verify each property has a namespace
NPT_List<NPT_String>::Iterator property = list.GetFirstItem();
while (property) {
NPT_List<NPT_String> parsed_property = (*property).Split(":");
if (parsed_property.GetItemCount() != 2)
parsed_property = (*property).Split("@");
if (parsed_property.GetItemCount() != 2 ||
(!(*property).StartsWith("-") && !(*property).StartsWith("+"))) {
NPT_LOG_WARNING_1("Invalid SortCriteria property %s", (*property).GetChars());
return NPT_FAILURE;
}
property++;
}
return NPT_SUCCESS;
}
示例8: matchDeviceType
bool DeviceDesc::matchDeviceType(const NPT_String& deviceType) const
{
if (deviceType.EndsWith(":*")) {
return m_private->m_deviceType.CompareN(deviceType, deviceType.GetLength() - 1) == 0;
}
return m_private->m_deviceType.Compare(deviceType) == 0;
}
示例9: while
/*----------------------------------------------------------------------
| NPT_String::Replace
+---------------------------------------------------------------------*/
const NPT_String&
NPT_String::Replace(char a, const char* str)
{
// check args
if (m_Chars == NULL || a == '\0' || str == NULL || str[0] == '\0') return *this;
// optimization
if (NPT_StringLength(str) == 1) return Replace(a, str[0]);
// we are going to create a new string
NPT_String dst;
char* src = m_Chars;
// reserve at least as much as input
dst.Reserve(GetLength());
// process the buffer
while (*src) {
if (*src == a) {
dst += str;
} else {
dst += *src;
}
src++;
}
Assign(dst.GetChars(), dst.GetLength());
return *this;
}
示例10: lock
/*----------------------------------------------------------------------
| PLT_MicroMediaController::ChooseDevice
+---------------------------------------------------------------------*/
PLT_DeviceDataReference
PLT_MicroMediaController::ChooseDevice(const NPT_Lock<PLT_DeviceMap>& deviceList)
{
PLT_StringMap namesTable;
PLT_DeviceDataReference* result = NULL;
NPT_String chosenUUID;
NPT_AutoLock lock(m_MediaServers);
// create a map with the device UDN -> device Name
const NPT_List<PLT_DeviceMapEntry*>& entries = deviceList.GetEntries();
NPT_List<PLT_DeviceMapEntry*>::Iterator entry = entries.GetFirstItem();
while (entry) {
PLT_DeviceDataReference device = (*entry)->GetValue();
NPT_String name = device->GetFriendlyName();
namesTable.Put((*entry)->GetKey(), name);
++entry;
}
// ask user to choose
chosenUUID = ChooseIDFromTable(namesTable);
if (chosenUUID.GetLength()) {
deviceList.Get(chosenUUID, result);
}
return result?*result:PLT_DeviceDataReference(); // return empty reference if not device was selected
}
示例11: if
/*----------------------------------------------------------------------
| CUPnPDirectory::GetFriendlyName
+---------------------------------------------------------------------*/
const char*
CUPnPDirectory::GetFriendlyName(const char* url)
{
NPT_String path = url;
if (!path.EndsWith("/")) path += "/";
if (path.Left(7).Compare("upnp://", true) != 0) {
return NULL;
} else if (path.Compare("upnp://", true) == 0) {
return "UPnP Media Servers (Auto-Discover)";
}
// look for nextslash
int next_slash = path.Find('/', 7);
if (next_slash == -1)
return NULL;
NPT_String uuid = path.SubString(7, next_slash-7);
NPT_String object_id = path.SubString(next_slash+1, path.GetLength()-next_slash-2);
// look for device
PLT_DeviceDataReference device;
if(!FindDeviceWait(CUPnP::GetInstance(), uuid, device))
return NULL;
return (const char*)device->GetFriendlyName();
}
示例12: Run
void Run() {
do {
// wait for a connection
NPT_Socket* client = NULL;
NPT_LOG_FINE_1("waiting for connection on port %d...", m_Port);
NPT_Result result = m_Socket.WaitForNewClient(client, NPT_TIMEOUT_INFINITE);
if (NPT_FAILED(result) || client == NULL) return;
NPT_SocketInfo client_info;
client->GetInfo(client_info);
NPT_LOG_FINE_2("client connected (%s -> %s)",
client_info.local_address.ToString().GetChars(),
client_info.remote_address.ToString().GetChars());
// get the output stream
NPT_OutputStreamReference output;
client->GetOutputStream(output);
// generate policy based on our current IP
NPT_String policy = "<cross-domain-policy>";
policy += "<allow-access-from domain=\""+client_info.local_address.GetIpAddress().ToString()+"\" to-ports=\""+m_AuthorizedPorts+"\"/>";
policy += "<allow-access-from domain=\""+client_info.remote_address.GetIpAddress().ToString()+"\" to-ports=\""+m_AuthorizedPorts+"\"/>";
policy += "</cross-domain-policy>";
NPT_MemoryStream* mem_input = new NPT_MemoryStream();
mem_input->Write(policy.GetChars(), policy.GetLength());
NPT_InputStreamReference input(mem_input);
NPT_StreamToStreamCopy(*input, *output);
delete client;
} while (!m_Aborted);
}
示例13:
/*----------------------------------------------------------------------
| PLT_MediaConnect::OnIsValidated
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaConnect::OnIsValidated(PLT_ActionReference& action,
PLT_MediaConnectInfo* mc_info)
{
bool validated = true;
NPT_String deviceID;
action->GetArgumentValue("DeviceID", deviceID);
/* is there a device ID passed ? */
if (deviceID.GetLength()) {
/* lookup the MediaConnectInfo from the UDN */
NPT_String MAC;
PLT_MediaConnectInfo* device_info;
if (NPT_FAILED(LookUpMediaConnectInfo(deviceID, device_info))) {
validated = false;
} else {
validated = device_info->m_Validated;
}
} else {
validated = mc_info?mc_info->m_Validated:true;
}
action->SetArgumentValue("Result", validated?"1":"0");
return NPT_SUCCESS;
}
示例14: if
/*----------------------------------------------------------------------
| CUPnPDirectory::GetFriendlyName
+---------------------------------------------------------------------*/
const char*
CUPnPDirectory::GetFriendlyName(const char* url)
{
NPT_String path = url;
if (!path.EndsWith("/")) path += "/";
if (path.Left(7).Compare("upnp://", true) != 0) {
return NULL;
} else if (path.Compare("upnp://", true) == 0) {
return "UPnP Media Servers (Auto-Discover)";
}
// look for nextslash
int next_slash = path.Find('/', 7);
if (next_slash == -1)
return NULL;
NPT_String uuid = path.SubString(7, next_slash-7);
NPT_String object_id = path.SubString(next_slash+1, path.GetLength()-next_slash-2);
// look for device
PLT_DeviceDataReference* device;
const NPT_Lock<PLT_DeviceMap>& devices = CUPnP::GetInstance()->m_MediaBrowser->GetMediaServers();
if (NPT_FAILED(devices.Get(uuid, device)) || device == NULL)
return NULL;
return (const char*)(*device)->GetFriendlyName();
}
示例15: SetBody
/*----------------------------------------------------------------------
| PLT_HttpHelper::SetBody
+---------------------------------------------------------------------*/
NPT_Result
PLT_HttpHelper::SetBody(NPT_HttpMessage& message,
NPT_String& body,
NPT_HttpEntity** entity /* = NULL */)
{
return SetBody(message, (const char*)body, body.GetLength(), entity);
}