You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.1KB

  1. /* output byte stream handling */
  2. typedef INT64 offset_t;
  3. /* unbuffered I/O */
  4. struct URLContext {
  5. struct URLProtocol *prot;
  6. int flags;
  7. int is_streamed; /* true if streamed (no seek possible), default = false */
  8. int packet_size;
  9. void *priv_data;
  10. };
  11. typedef struct URLContext URLContext;
  12. typedef struct URLPollEntry {
  13. URLContext *handle;
  14. int events;
  15. int revents;
  16. } URLPollEntry;
  17. #define URL_RDONLY 0
  18. #define URL_WRONLY 1
  19. int url_open(URLContext **h, const char *filename, int flags);
  20. int url_read(URLContext *h, unsigned char *buf, int size);
  21. int url_write(URLContext *h, unsigned char *buf, int size);
  22. offset_t url_seek(URLContext *h, offset_t pos, int whence);
  23. int url_close(URLContext *h);
  24. int url_exist(const char *filename);
  25. offset_t url_filesize(URLContext *h);
  26. /* not implemented */
  27. int url_poll(URLPollEntry *poll_table, int n, int timeout);
  28. typedef struct URLProtocol {
  29. const char *name;
  30. int (*url_open)(URLContext *h, const char *filename, int flags);
  31. int (*url_read)(URLContext *h, unsigned char *buf, int size);
  32. int (*url_write)(URLContext *h, unsigned char *buf, int size);
  33. offset_t (*url_seek)(URLContext *h, offset_t pos, int whence);
  34. int (*url_close)(URLContext *h);
  35. struct URLProtocol *next;
  36. } URLProtocol;
  37. extern URLProtocol *first_protocol;
  38. int register_protocol(URLProtocol *protocol);
  39. typedef struct {
  40. unsigned char *buffer;
  41. int buffer_size;
  42. unsigned char *buf_ptr, *buf_end;
  43. void *opaque;
  44. int (*read_packet)(void *opaque, UINT8 *buf, int buf_size);
  45. void (*write_packet)(void *opaque, UINT8 *buf, int buf_size);
  46. int (*seek)(void *opaque, offset_t offset, int whence);
  47. offset_t pos; /* position in the file of the current buffer */
  48. int must_flush; /* true if the next seek should flush */
  49. int eof_reached; /* true if eof reached */
  50. int write_flag; /* true if open for writing */
  51. int is_streamed;
  52. int packet_size;
  53. } ByteIOContext;
  54. int init_put_byte(ByteIOContext *s,
  55. unsigned char *buffer,
  56. int buffer_size,
  57. int write_flag,
  58. void *opaque,
  59. int (*read_packet)(void *opaque, UINT8 *buf, int buf_size),
  60. void (*write_packet)(void *opaque, UINT8 *buf, int buf_size),
  61. int (*seek)(void *opaque, offset_t offset, int whence));
  62. void put_byte(ByteIOContext *s, int b);
  63. void put_buffer(ByteIOContext *s, unsigned char *buf, int size);
  64. void put_le64(ByteIOContext *s, UINT64 val);
  65. void put_be64(ByteIOContext *s, UINT64 val);
  66. void put_le32(ByteIOContext *s, unsigned int val);
  67. void put_be32(ByteIOContext *s, unsigned int val);
  68. void put_le16(ByteIOContext *s, unsigned int val);
  69. void put_be16(ByteIOContext *s, unsigned int val);
  70. void put_tag(ByteIOContext *s, char *tag);
  71. offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence);
  72. void url_fskip(ByteIOContext *s, offset_t offset);
  73. offset_t url_ftell(ByteIOContext *s);
  74. int url_feof(ByteIOContext *s);
  75. void put_flush_packet(ByteIOContext *s);
  76. int get_buffer(ByteIOContext *s, unsigned char *buf, int size);
  77. int get_byte(ByteIOContext *s);
  78. unsigned int get_le32(ByteIOContext *s);
  79. UINT64 get_le64(ByteIOContext *s);
  80. unsigned int get_le16(ByteIOContext *s);
  81. unsigned int get_be16(ByteIOContext *s);
  82. unsigned int get_be32(ByteIOContext *s);
  83. UINT64 get_be64(ByteIOContext *s);
  84. static inline int url_is_streamed(ByteIOContext *s)
  85. {
  86. return s->is_streamed;
  87. }
  88. /* get the prefered packet size of the device. All I/Os should be done
  89. by multiple of this size */
  90. static inline int url_get_packet_size(ByteIOContext *s)
  91. {
  92. return s->packet_size;
  93. }
  94. int url_fdopen(ByteIOContext *s, URLContext *h);
  95. int url_setbufsize(ByteIOContext *s, int buf_size);
  96. int url_fopen(ByteIOContext *s, const char *filename, int flags);
  97. int url_fclose(ByteIOContext *s);
  98. URLContext *url_fileno(ByteIOContext *s);
  99. int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags);
  100. int url_close_buf(ByteIOContext *s);
  101. /* file.c */
  102. extern URLProtocol file_protocol;
  103. extern URLProtocol pipe_protocol;
  104. /* udp.c */
  105. extern URLProtocol udp_protocol;
  106. /* http.c */
  107. extern URLProtocol http_protocol;