Go to the documentation of this file.
1 /*
2  * Gopher protocol
3  *
4  * Copyright (c) 2009 Toshimitsu Kimura
5  *
6  * based on libavformat/http.c, Copyright (c) 2000, 2001 Fabrice Bellard
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
25 #include "libavutil/avstring.h"
26 #include "avformat.h"
27 #include "internal.h"
28 #include "network.h"
29 #include "url.h"
31 typedef struct GopherContext {
35 static int gopher_write(URLContext *h, const uint8_t *buf, int size)
36 {
38  return ffurl_write(s->hd, buf, size);
39 }
41 static int gopher_connect(URLContext *h, const char *path)
42 {
43  char buffer[1024];
45  if (!*path) return AVERROR(EINVAL);
46  switch (*++path) {
47  case '5':
48  case '9':
49  path = strchr(path, '/');
50  if (!path) return AVERROR(EINVAL);
51  break;
52  default:
54  "Gopher protocol type '%c' not supported yet!\n",
55  *path);
56  return AVERROR(EINVAL);
57  }
59  /* send gopher sector */
60  snprintf(buffer, sizeof(buffer), "%s\r\n", path);
62  if (gopher_write(h, buffer, strlen(buffer)) < 0)
63  return AVERROR(EIO);
65  return 0;
66 }
69 {
71  ffurl_closep(&s->hd);
72  return 0;
73 }
75 static int gopher_open(URLContext *h, const char *uri, int flags)
76 {
78  char hostname[1024], auth[1024], path[1024], buf[1024];
79  int port, err;
81  h->is_streamed = 1;
83  /* needed in any case to build the host string */
84  av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
85  path, sizeof(path), uri);
87  if (port < 0)
88  port = 70;
90  ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
92  s->hd = NULL;
95  if (err < 0)
96  goto fail;
98  if ((err = gopher_connect(h, path)) < 0)
99  goto fail;
100  return 0;
101  fail:
102  gopher_close(h);
103  return err;
104 }
106 static int gopher_read(URLContext *h, uint8_t *buf, int size)
107 {
108  GopherContext *s = h->priv_data;
109  int len = ffurl_read(s->hd, buf, size);
110  return len;
111 }
115  .name = "gopher",
116  .url_open = gopher_open,
117  .url_read = gopher_read,
118  .url_write = gopher_write,
119  .url_close = gopher_close,
120  .priv_data_size = sizeof(GopherContext),
122 };
static int gopher_open(URLContext *h, const char *uri, int flags)
Definition: gopher.c:75
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
Definition: utils.c:4759
#define NULL
Definition: coverity.c:32
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
Definition: avio.c:310
Definition: url.h:34
URLContext * hd
Definition: gopher.c:32
Something somehow does not look correct.
Definition: log.h:200
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: avio.c:416
int is_streamed
true if streamed (no seek possible), default = false
Definition: url.h:45
AVIOInterruptCB interrupt_callback
Definition: url.h:47
static int gopher_read(URLContext *h, uint8_t *buf, int size)
Definition: gopher.c:106
static int gopher_connect(URLContext *h, const char *path)
Definition: gopher.c:41
ptrdiff_t size
Definition: opengl_enc.c:100
#define av_log(a,...)
const char * protocol_whitelist
Definition: url.h:49
#define fail()
Definition: checkasm.h:133
#define s(width, name)
Definition: cbs_vp9.c:257
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
Definition: avio.c:439
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
Definition: url.c:38
const char * protocol_blacklist
Definition: url.h:50
Definition: url.h:38
read-write pseudo flag
Definition: avio.h:676
static int gopher_close(URLContext *h)
Definition: gopher.c:68
void * priv_data
Definition: url.h:41
const URLProtocol ff_gopher_protocol
Definition: gopher.c:114
#define snprintf
Definition: snprintf.h:34
const char * name
Definition: url.h:55
#define flags(name, subs,...)
Definition: cbs_av1.c:561
Main libavformat public API header.
int len
static int gopher_write(URLContext *h, const uint8_t *buf, int size)
Definition: gopher.c:35
unbuffered private I/O API
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf...
Definition: avio.c:402
GLuint buffer
Definition: opengl_enc.c:101