[FFmpeg-devel] [PATCH] Gopher client support

nazo lovesyao
Sun Jan 25 05:33:48 CET 2009


Michael Niedermayer ????????:
> 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 ?

it shouldn't for warning

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

done

>> +
>> +    if (!*sector) return AVERROR(EINVAL);
>> +    switch (*++sector) {
>> +        case '5':
>> +        case '9':
> 
>> +            for (;*sector;sector++)
>> +                if (*sector == '/') {
>> +                    sector++;
>> +                    break;
>> +                }
> 
> sector= strchr(sector, '/');

done

> [...]
> 
>> +/* return non zero if error */
>> +static int gopher_open_cnx(URLContext *h, const char *uri)
> 
> The comment should be doxygen compatible
> something like
> /**
>  *
>  * @returns ...

done

>> +{
>> +    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

done

>> +
>> +    s->hd = hd;
> 
>> +    if (gopher_connect(h, path) < 0)
>> +        goto fail;
> 
> this discards the returned error code

done

> [...]
>> +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

done

> [...]
>> +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

done

also fixed incorrect version bump.

attached new patch

-- 
Nazo (T.K.) <lovesyao at gmail.com>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: gopher.diff
Type: text/x-patch
Size: 5614 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090125/5c6a4784/attachment.bin>



More information about the ffmpeg-devel mailing list