| Revision 4716,
1.5 KB
checked in by jylam, 2 years ago
(diff) |
- Initial commit
-This line, and those below, will be ignored--
A gaycko/tests
A gaycko/tests/lnx.html
A gaycko/tests/html.html
A gaycko/tests/simple.html
A gaycko/configure.ac
A gaycko/src
A gaycko/src/dom
A gaycko/src/dom/dom.c
A gaycko/src/dom/dom.h
A gaycko/src/helpers
A gaycko/src/helpers/str.c
A gaycko/src/helpers/str.h
A gaycko/src/gaycko.h
A gaycko/src/parsing
A gaycko/src/parsing/parse.h
A gaycko/src/parsing/parse.c
A gaycko/src/io
A gaycko/src/io/file.c
A gaycko/src/io/http.c
A gaycko/src/io/file.h
A gaycko/src/io/http.h
A gaycko/src/io/io.c
A gaycko/src/io/io.h
A gaycko/src/Makefile.am
A gaycko/src/gaycko.c
A gaycko/Makefile.am
AM gaycko/bootstrap
|
| Line | |
|---|
| 1 | #include "io.h" |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <string.h> |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | gIO *gaycko_open(char *uri) { |
|---|
| 7 | gIO *ret = NULL; |
|---|
| 8 | //TODO handle URI scheme |
|---|
| 9 | |
|---|
| 10 | ret = malloc(sizeof(gIO)); |
|---|
| 11 | |
|---|
| 12 | if(strlen(uri)>7 && !strncmp(uri, "http://", 7)) { |
|---|
| 13 | ret->type = IO_HTTP; |
|---|
| 14 | } else { |
|---|
| 15 | ret->type = IO_FILE; |
|---|
| 16 | } |
|---|
| 17 | switch(ret->type) { |
|---|
| 18 | default: |
|---|
| 19 | ret->stream.http = http_open(uri); |
|---|
| 20 | if(!ret->stream.http) { |
|---|
| 21 | free(ret); |
|---|
| 22 | return NULL; |
|---|
| 23 | } |
|---|
| 24 | break; |
|---|
| 25 | case IO_FILE: |
|---|
| 26 | ret->stream.file = file_open(uri); |
|---|
| 27 | if(!ret->stream.file) { |
|---|
| 28 | free(ret); |
|---|
| 29 | return NULL; |
|---|
| 30 | } |
|---|
| 31 | break; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | return ret; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | void gaycko_close(gIO *io) { |
|---|
| 38 | if(!io) return; |
|---|
| 39 | |
|---|
| 40 | switch(io->type) { |
|---|
| 41 | default: |
|---|
| 42 | http_close(io->stream.http); |
|---|
| 43 | break; |
|---|
| 44 | case IO_FILE: |
|---|
| 45 | file_close(io->stream.file); |
|---|
| 46 | break; |
|---|
| 47 | } |
|---|
| 48 | free(io); |
|---|
| 49 | |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | char *gaycko_get_data(gIO *io) { |
|---|
| 53 | if(!io) return NULL; |
|---|
| 54 | |
|---|
| 55 | switch(io->type) { |
|---|
| 56 | default: |
|---|
| 57 | return io->stream.http->data; |
|---|
| 58 | break; |
|---|
| 59 | case IO_FILE: |
|---|
| 60 | return io->stream.file->data; |
|---|
| 61 | break; |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | unsigned int gaycko_get_size(gIO *io) { |
|---|
| 66 | if(!io) return 0; |
|---|
| 67 | |
|---|
| 68 | switch(io->type) { |
|---|
| 69 | default: |
|---|
| 70 | return io->stream.http->size; |
|---|
| 71 | break; |
|---|
| 72 | case IO_FILE: |
|---|
| 73 | return io->stream.file->size; |
|---|
| 74 | break; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.