[FFmpeg-devel] [PATCH] Gopher client support

Michael Niedermayer michaelni
Sat Jan 24 19:20:37 CET 2009


On Thu, Jan 22, 2009 at 05:14:14PM +0900, nazo wrote:
> Hi,
>
> I wrote Gopher client support patch based on libavformat/http.c and 
> attached. It works only with binary transaction.
> Here is example:
> ./ffplay gopher://zcrayfish.dyndns.org/9/users/everyone/cowbell.wmv
>
> Other samples are here: gopher://gopher.floodgap.com/7/v2/vs?.wmv

[...]

> +static int gopher_write(URLContext *h, uint8_t *buf, int size)

shouldnt it be const uint8_t *buf ?


[...]
> +static int gopher_connect(URLContext *h, const char *path)
> +{
> +    GopherContext *s = h->priv_data;

> +    char const *sector = path;

redundant variable


> +
> +    if (!*sector) return AVERROR(EINVAL);
> +    switch (*++sector) {
> +        case '5':
> +        case '9':

> +            for (;*sector;sector++)
> +                if (*sector == '/') {
> +                    sector++;
> +                    break;
> +                }

sector= strchr(sector, '/');


[...]

> +/* return non zero if error */
> +static int gopher_open_cnx(URLContext *h, const char *uri)

The comment should be doxygen compatible
something like
/**
 *
 * @returns ...


> +{
> +    char hostname[1024];
> +    char auth[1024];
> +    char path[1024];
> +    char buf[1024];
> +    int port, err;
> +    GopherContext *s = h->priv_data;
> +    URLContext *hd = NULL;
> +
> +    /* needed in any case to build the host string */
> +    url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
> +              path, sizeof(path), uri);
> +
> +    if (port < 0)
> +        port = 70;
> +
> +    snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
> +    err = url_open(&hd, buf, URL_RDWR);
> +    if (err < 0)
> +        goto fail;
> +

> +    if (!*path)
> +        return AVERROR(EINVAL);

gopher_connect() checks this as well so they are redundant


> +
> +    s->hd = hd;

> +    if (gopher_connect(h, path) < 0)
> +        goto fail;

this discards the returned error code


[...]
> +static int gopher_open(URLContext *h, const char *uri, int flags)
> +{
> +    GopherContext *s;
> +    int ret;
> +
> +    h->is_streamed = 1;
> +
> +    s = av_malloc(sizeof(GopherContext));
> +    if (!s) {
> +        return AVERROR(ENOMEM);
> +    }
> +    h->priv_data = s;
> +
> +    ret = gopher_open_cnx(h, uri);

> +    if (ret != 0)

!= 0 is superflous


[...]
> +static int gopher_read(URLContext *h, uint8_t *buf, int size)
> +{
> +    GopherContext *s = h->priv_data;
> +    int len;
> +
> +    /* read bytes from input buffer first */
> +    len = s->buf_end - s->buf_ptr;
> +    if (len > 0) {

> +        if (len > size)
> +            len = size;
> +        memcpy(buf, s->buf_ptr, len);
> +        s->buf_ptr += len;

this code will never be run, as len will be 0


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090124/2b8111b5/attachment.pgp>



More information about the ffmpeg-devel mailing list