X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Fliburi.so_src%2Fmain.c;h=a9f2e1757aa6b231ceac40c78eace3072b5c1b84;hb=e1e28eeec4619359322227478d826e3dcdd0a09d;hp=2d785f3eed3b1494e094db53cf2bdf616f0edf9d;hpb=7bc1f2fbeb70981e23b427e72d3f3d195c104884;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/liburi.so_src/main.c b/Usermode/Libraries/liburi.so_src/main.c index 2d785f3e..a9f2e175 100644 --- a/Usermode/Libraries/liburi.so_src/main.c +++ b/Usermode/Libraries/liburi.so_src/main.c @@ -32,11 +32,12 @@ void URI_Close(tURIFile *File); size_t URI_file_Read(int Handle, size_t Bytes, void *Buffer); size_t URI_file_Write(int Handle, size_t Bytes, void *Buffer); void URI_file_Close(int Handle); +off_t URI_file_GetSize(int Handle); // === CONSTANTS === // Builtin URI protocol handlers tURIHandler caBuiltinHandlers[] = { - {"file", 0, URI_file_Open, URI_file_Close, URI_file_Read, URI_file_Write} + {"file", 0, URI_file_Open, URI_file_Close, URI_file_Read, URI_file_Write, URI_file_GetSize} }; #define NUM_BUILTIN_HANDLERS (sizeof(caBuiltinHandlers)/sizeof(caBuiltinHandlers[0])) @@ -55,14 +56,14 @@ tURI *URI_Parse(const char *String) if(!String) return NULL; protolen = 0; - while( isalpha(*tmp) ) tmp++, protolen++; + while( isalpha(*tmp) || isdigit(*tmp) ) tmp++, protolen++; // true URI if(tmp[0] == ':' && tmp[1] == '/' && tmp[2] == '/') { int hostlen, portlen, pathlen; tmp += 3; // Eat '://' - ret = malloc(sizeof(tURI) + strlen(String) - 2); + ret = malloc(sizeof(tURI) + protolen + 1 + strlen(tmp) + 1); ret->Proto = (char*)ret + sizeof(tURI); memcpy(ret->Proto, String, protolen); @@ -75,7 +76,7 @@ tURI *URI_Parse(const char *String) if( *tmp == '[' ) { tmp ++; - while( *tmp != ']' ) { + while( *tmp && *tmp != ']' ) { ret->Host[hostlen] = *tmp; tmp ++; hostlen ++; @@ -86,7 +87,7 @@ tURI *URI_Parse(const char *String) // IPv4/DNS else { - while( *tmp != '/' && *tmp != ':' ) + while( *tmp && *tmp != '/' && *tmp != ':' ) { ret->Host[hostlen] = *tmp; tmp ++; @@ -119,6 +120,7 @@ tURI *URI_Parse(const char *String) else { ret->PortStr = NULL; ret->PortNum = -1; + portlen = 0; } if(*tmp == '\0') @@ -138,14 +140,8 @@ tURI *URI_Parse(const char *String) else ret->Path = ret->Host + hostlen + 1; - tmp ++; pathlen = 0; - while(*tmp) - { - ret->Path[pathlen] = *tmp; - tmp ++; - pathlen ++; - } + strcpy(ret->Path, tmp); return ret; } @@ -225,6 +221,19 @@ tURIFile *URI_Open(int Mode, tURI *URI) return ret; } +int URI_GetSize(tURIFile *File, size_t *Size) +{ + if( !File || !Size ) return -1; + + if( File->Handler->GetSize ) + { + *Size = File->Handler->GetSize(File->Handle); + return 0; // Success + } + + return 1; // Size not avaliable +} + /** * \brief Read from a URI file */ @@ -235,7 +244,7 @@ size_t URI_Read(tURIFile *File, size_t Bytes, void *Buffer) size_t tmp; printf("URI_Read(File=%p, Bytes=%u, Buffer=%p)\n", - File, Bytes, Buffer); + File, (unsigned int)Bytes, Buffer); if(!File || !Buffer) return -1; if(Bytes == 0) return 0; @@ -301,24 +310,33 @@ int URI_file_Open(char *Host, int Port, char *Path, int Mode) if(Mode & URI_MODE_READ) smode |= OPENFLAG_READ; if(Mode & URI_MODE_WRITE) smode |= OPENFLAG_WRITE; - printf("URI_file_Open: open('%s', 0x%x)\n", Path, smode); +// printf("URI_file_Open: open('%s', 0x%x)\n", Path, smode); { int ret; - ret = open(Path, smode); + ret = _SysOpen(Path, smode); return ret; } } size_t URI_file_Read(int Handle, size_t Bytes, void *Buffer) { - printf("URI_file_Read: (Handle=%i, Bytes=%i, Buffer=%p)\n", - Handle, Bytes, Buffer); - return read(Handle, Bytes, Buffer); +// printf("URI_file_Read: (Handle=%i, Buffer=%p, Bytes=%i)\n", +// Handle, Buffer, (int)Bytes); + return _SysRead(Handle, Buffer, Bytes); } size_t URI_file_Write(int Handle, size_t Bytes, void *Buffer) { - return write(Handle, Bytes, Buffer); + return _SysWrite(Handle, Buffer, Bytes); } void URI_file_Close(int Handle) { - close(Handle); + _SysClose(Handle); +} +off_t URI_file_GetSize(int Handle) +{ + uint64_t curpos = _SysTell(Handle); + off_t ret; + _SysSeek(Handle, 0, SEEK_END); + ret = _SysTell(Handle); + _SysSeek(Handle, curpos, SEEK_SET); + return ret; }