added URI.h/.cpp
This commit is contained in:
parent
14bca2e58f
commit
a62f822f73
97
inc/hgl/URI.h
Normal file
97
inc/hgl/URI.h
Normal file
@ -0,0 +1,97 @@
|
||||
#ifndef HGL_URI_INCLUDE
|
||||
#define HGL_URI_INCLUDE
|
||||
|
||||
#include<hgl/type/String.h>
|
||||
namespace hgl
|
||||
{
|
||||
const uint16 GetSchemePort(const char *scheme);
|
||||
|
||||
/**
|
||||
* 统一地址标识符类<br>
|
||||
* <p>注:此类只处理名称,与真实文件系统/网络系统没有任何相关操作</p>
|
||||
*
|
||||
* <p>example 1:
|
||||
* http:// www.hyzgame.com / index .php
|
||||
* ------- --------------- ----- ---
|
||||
* scheme path main_name ext_name
|
||||
*
|
||||
* scheme: http
|
||||
* path: www.hyzgame.com
|
||||
* main_name: index
|
||||
* ext_name: php
|
||||
* </p>
|
||||
*
|
||||
* <p> example 2:
|
||||
* file:// C:/windows/system32/1234.dll
|
||||
*
|
||||
* scheme: file
|
||||
* driver: C
|
||||
* path: Windows\System32
|
||||
* main_name: 1234
|
||||
* ext_name: dll
|
||||
* fullname: C:\windows\system32\1234.dll
|
||||
* </p>
|
||||
*
|
||||
* <p> example 3:
|
||||
* C:\windows\system32\1234.dll
|
||||
*
|
||||
* scheme:
|
||||
* driver: C
|
||||
* path: Windows\System32
|
||||
* main_name: 1234
|
||||
* ext_name: dll
|
||||
* fullname: C:\windows\system32\1234.dll
|
||||
* </p>
|
||||
*/
|
||||
class URI
|
||||
{
|
||||
public:
|
||||
|
||||
enum class SchemeType
|
||||
{
|
||||
Unknow=0,
|
||||
LocalFile, ///<本地文件系统
|
||||
ArachivesFile, ///<档案文件(压缩包/tar/ISO镜像之类)
|
||||
Device, ///<设备虚拟文件
|
||||
Network, ///<网络
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
OSString origin_name;
|
||||
|
||||
OSString scheme_name; ///<协议名称(如http,ftp之类)
|
||||
SchemeType scheme_type; ///<协议
|
||||
|
||||
UTF8String network_host; ///<网络主机(IP或网址)
|
||||
uint16 network_port; ///<网络协议默认端口
|
||||
|
||||
OSString fullname; ///<完整文件名
|
||||
|
||||
OSString path_name; ///<路径名
|
||||
OSString main_name; ///<主名称
|
||||
OSString ext_name; ///<文件扩展名
|
||||
|
||||
UTF8String url;
|
||||
|
||||
public:
|
||||
|
||||
URI(const OSString &);
|
||||
URI(const OSString &scheme,const OSString &path,const OSString &filename);
|
||||
~URI()=default;
|
||||
|
||||
const bool isFile();
|
||||
const bool isDevice();
|
||||
const bool isNetwork();
|
||||
|
||||
public:
|
||||
|
||||
const OSString &path();
|
||||
const OSString &main();
|
||||
const OSString &ext();
|
||||
const OSString &full();
|
||||
|
||||
const UTF8String &URL();
|
||||
};//class Filename
|
||||
}//namespace hgl
|
||||
#endif//HGL_URI_INCLUDE
|
@ -19,7 +19,7 @@ file(GLOB TYPE_TEMPLATE_HEADER ${TYPE_INCLUDE_PATH}/*.h)
|
||||
|
||||
SET(TYPE_SOURCE_FILES Type/Collection.cpp)
|
||||
|
||||
SOURCE_GROUP("DataType\\Collection" FILES ${TYPE_INCLUDE_PATH}/Collection.h
|
||||
SOURCE_GROUP("DataType\\Collection" FILES ${TYPE_INCLUDE_PATH}/Collection.h
|
||||
${COLLECTION_SOURCE})
|
||||
|
||||
SET(SYSTEM_INFO_SOURCE ${CORE_PLATFORM_INCLUDE_PATH}/SystemInfo.h
|
||||
@ -145,12 +145,13 @@ SET(IO_SOURCE_FILES ${IO_BASE_FILES}
|
||||
SET(FILESYSTEM_INCLUDE_PATH ${CMCORE_ROOT_INCLUDE_PATH}/hgl/filesystem)
|
||||
|
||||
SET(FILESYSTEM_HEADER_FILES ${FILESYSTEM_INCLUDE_PATH}/EnumFile.h
|
||||
${FILESYSTEM_INCLUDE_PATH}/EnumVolume.h
|
||||
${FILESYSTEM_INCLUDE_PATH}/Filename.h
|
||||
${FILESYSTEM_INCLUDE_PATH}/FileSystem.h)
|
||||
${FILESYSTEM_INCLUDE_PATH}/EnumVolume.h
|
||||
${FILESYSTEM_INCLUDE_PATH}/Filename.h
|
||||
${FILESYSTEM_INCLUDE_PATH}/FileSystem.h)
|
||||
|
||||
SET(FILESYSTEM_SOURCE_FILES FileSystem/FileSystem.cpp
|
||||
FileSystem/EnumFile.cpp)
|
||||
FileSystem/EnumFile.cpp
|
||||
FileSystem/Filename.cpp)
|
||||
|
||||
SOURCE_GROUP("FileSystem" FILES ${FILESYSTEM_HEADER_FILES} ${FILESYSTEM_SOURCE_FILES})
|
||||
|
||||
|
89
src/URI.cpp
Normal file
89
src/URI.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include<hgl/URI.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
|
||||
|
||||
struct SchemePort
|
||||
{
|
||||
uint16 port;
|
||||
char scheme[16];
|
||||
};
|
||||
|
||||
const SchemePort SchemePortList[]=
|
||||
{
|
||||
{7, "echo"},
|
||||
{21, "ftp"},
|
||||
{22, "ssh"},
|
||||
{23, "telnet"},
|
||||
{25, "smtp"},
|
||||
{53, "dns"},
|
||||
{69, "tftp"},
|
||||
{80, "http"},
|
||||
{80, "ws"},
|
||||
{110, "pop3"},
|
||||
{119, "nntp"},
|
||||
{123, "ntp"},
|
||||
{143, "imap"},
|
||||
{161, "snmp"},
|
||||
{162, "snmptrap"},
|
||||
{194, "irc"},
|
||||
{199, "smux"},
|
||||
{389, "ldap"},
|
||||
{443, "https"},
|
||||
{443, "wss"},
|
||||
{445, "smb"},
|
||||
{465, "smtps"},
|
||||
{548, "afp"}, //Apple File Services
|
||||
{554, "rtsp"},
|
||||
{636, "ldaps"},
|
||||
{853, "dnss"},
|
||||
{873, "rsync"},
|
||||
{993, "imaps"},
|
||||
{5060, "sip"},
|
||||
{5061, "sips"},
|
||||
{5222, "xmpp"}
|
||||
};
|
||||
}
|
||||
|
||||
const uint16 GetSchemePort(const char *scheme)
|
||||
{
|
||||
for(const SchemePort &sp:SchemePortList)
|
||||
if(strcmp(scheme,sp.scheme)==0)
|
||||
return sp.port;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
URI::URI(const OSString &fn)
|
||||
{
|
||||
origin_name=fn;
|
||||
|
||||
scheme_type=SchemeType::Unknow;
|
||||
}
|
||||
|
||||
URI::URI(const OSString &scheme,const OSString &path,const OSString &filename)
|
||||
{
|
||||
scheme_name=scheme;
|
||||
|
||||
if(scheme=="file")
|
||||
scheme_type=SchemeType::LocalFile;
|
||||
else
|
||||
|
||||
}
|
||||
|
||||
const bool URI::isFile()
|
||||
{
|
||||
if(scheme_type==SchemeType::Unknow)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if(scheme_type==SchemeType::LocalFile)
|
||||
return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user