Beispiel #1
0
static int http_close(URLContext *h)
{
    HTTPContext *s = h->priv_data;
    url_close(s->hd);
    av_free(s);
    return 0;
}
Beispiel #2
0
static int md5_close(URLContext *h)
{
    const char *filename = h->filename;
    uint8_t md5[16], buf[64];
    URLContext *out;
    int i, err = 0;

    av_md5_final(h->priv_data, md5);
    for (i = 0; i < sizeof(md5); i++)
        snprintf(buf + i*2, 3, "%02x", md5[i]);
    buf[i*2] = '\n';

    av_strstart(filename, "md5:", &filename);

    if (*filename) {
        err = url_open(&out, filename, URL_WRONLY);
        if (err)
            return err;
        err = url_write(out, buf, i*2+1);
        url_close(out);
    } else {
        if (fwrite(buf, 1, i*2+1, stdout) < i*2+1)
            err = AVERROR(errno);
    }

    return err;
}
Beispiel #3
0
static int rtsp_read_close(AVFormatContext *s)
{
    RTSPState *rt = s->priv_data;
    RTSPHeader reply1, *reply = &reply1;
    char cmd[1024];

#if 0
    /* NOTE: it is valid to flush the buffer here */
    if (rt->protocol == RTSP_PROTOCOL_RTP_TCP) {
        url_fclose(&rt->rtsp_gb);
    }
#endif
    snprintf(cmd, sizeof(cmd),
             "TEARDOWN %s RTSP/1.0\r\n",
             s->filename);
    rtsp_send_cmd(s, cmd, reply, NULL);

    if (ff_rtsp_callback) {
        ff_rtsp_callback(RTSP_ACTION_CLIENT_TEARDOWN, rt->session_id,
                         NULL, 0, NULL);
    }

    rtsp_close_streams(rt);
    url_close(rt->rtsp_hd);
    return 0;
}
Beispiel #4
0
static offset_t http_seek(URLContext *h, offset_t off, int whence)
{
    HTTPContext *s = h->priv_data;
    URLContext *old_hd = s->hd;
    offset_t old_off = s->off;

    if (whence == AVSEEK_SIZE)
        return s->filesize;
    else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed)
        return -1;

    /* we save the old context in case the seek fails */
    s->hd = NULL;
    if (whence == SEEK_CUR)
        off += s->off;
    else if (whence == SEEK_END)
        off += s->filesize;
    s->off = off;

    /* if it fails, continue on old connection */
    if (http_open_cnx(h) < 0) {
        s->hd = old_hd;
        s->off = old_off;
        return -1;
    }
    url_close(old_hd);
    return off;
}
Beispiel #5
0
void main(int argc, char **argv)
{
    URL url;
    char buff[BUFSIZ];
    int c;

    if(argc != 2)
    {
	fprintf(stderr, "Usage: %s news-URL\n", argv[0]);
	exit(1);
    }
    if((url = url_news_open(argv[1])) == NULL)
    {
	fprintf(stderr, "Can't open news group: %s\n", argv[1]);
	exit(1);
    }

#if NEWS_MAIN
    while((c = url_getc(url)) != EOF)
	putchar(c);
#else
    while((c = url_read(url, buff, sizeof(buff))) > 0)
	write(1, buff, c);
#endif
    url_close(url);
    exit(0);
}
Beispiel #6
0
static int64_t http_seek(URLContext *h, int64_t off, int whence)
{
    HTTPContext *s = h->priv_data;
    URLContext *old_hd = s->hd;
    int64_t old_off = s->off;
    uint8_t old_buf[BUFFER_SIZE];
    int old_buf_size;

    if (whence == AVSEEK_SIZE)
        return s->filesize;
    else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed)
        return -1;

    /* we save the old context in case the seek fails */
    old_buf_size = s->buf_end - s->buf_ptr;
    memcpy(old_buf, s->buf_ptr, old_buf_size);
    s->hd = NULL;
    if (whence == SEEK_CUR)
        off += s->off;
    else if (whence == SEEK_END)
        off += s->filesize;
    s->off = off;

    /* if it fails, continue on old connection */
    if (http_open_cnx(h) < 0) {
        memcpy(s->buffer, old_buf, old_buf_size);
        s->buf_ptr = s->buffer;
        s->buf_end = s->buffer + old_buf_size;
        s->hd = old_hd;
        s->off = old_off;
        return -1;
    }
    url_close(old_hd);
    return off;
}
Beispiel #7
0
int main(int argc, char *argv[])
{
        unsigned char bbuf[ 204 + 10]; /* bin data buffer */
        char tbuf[1024 + 10]; /* txt data buffer */

        if(0 != deal_with_parameter(argc, argv)) {
                return -1;
        }

        fd_i = url_open(file_i, "rb");
        if(NULL == fd_i) {
                RPTERR("open \"%s\" failed", file_i);
                return -1;
        }

        pkt_addr = 0;
        while(1 == url_read(bbuf, (size_t)npline, 1, fd_i)) {
                fprintf(stdout, "*ts, ");
                b2t(tbuf, bbuf, 188);
                fprintf(stdout, "%s", tbuf);

                fprintf(stdout, "*addr, %"PRIX64", \n", pkt_addr);

                pkt_addr += npline;
        }

        url_close(fd_i);

        return 0;
}
URL url_buff_open(URL url, int autoclose)
{
    URL_buff *urlp;

    if((urlp = (URL_buff *)alloc_url(sizeof(URL_buff))) == NULL)
    {
	if(autoclose)
	    url_close(url);
	return NULL;
    }

    /* common members */
    URLm(urlp, type)	  = URL_buff_t;
    URLm(urlp, url_read)  = url_buff_read;
    URLm(urlp, url_gets)  = url_buff_gets;
    URLm(urlp, url_fgetc) = url_buff_fgetc;
    URLm(urlp, url_seek)  = url_buff_seek;
    URLm(urlp, url_tell)  = url_buff_tell;
    URLm(urlp, url_close) = url_buff_close;

    /* private members */
    urlp->reader = url;
    memset(urlp->buffer, 0, sizeof(urlp->buffer));
    urlp->wp = 0;
    urlp->rp = 0;
    if((urlp->posofs = url_tell(url)) == -1)
	urlp->posofs = 0;
    urlp->pos = 0;
    urlp->eof = 0;
    urlp->autoclose = autoclose;

    return (URL)urlp;
}
static void url_buff_close(URL url)
{
    URL_buff *urlp = (URL_buff *)url;
    if(urlp->autoclose)
	url_close(urlp->reader);
    free(url);
}
Beispiel #10
0
int url_exist(const char *filename)
{
    URLContext *h;
    if (url_open(&h, filename, URL_RDONLY) < 0)
        return 0;
    url_close(h);
    return 1;
}
Beispiel #11
0
static int gopher_close(URLContext *h)
{
    GopherContext *s = h->priv_data;
    if (s->hd) {
        url_close(s->hd);
        s->hd = NULL;
    }
    av_freep(&h->priv_data);
    return 0;
}
URL url_inflate_open(URL instream, long compsize, int autoclose)
{
    URL_inflate *url;

    url = (URL_inflate *)alloc_url(sizeof(URL_inflate));
    if(url == NULL)
    {
	if(autoclose)
	    url_close(instream);
	url_errno = errno;
	return NULL;
    }

    /* common members */
    URLm(url, type)      = URL_inflate_t;
    URLm(url, url_read)  = url_inflate_read;
    URLm(url, url_gets)  = NULL;
    URLm(url, url_fgetc) = NULL;
    URLm(url, url_seek)  = NULL;
    URLm(url, url_tell)  = url_inflate_tell;
    URLm(url, url_close) = url_inflate_close;

    /* private members */
    url->decoder = NULL;
    url->instream = instream;
    url->pos = 0;
    url->compsize = compsize;
    url->autoclose = autoclose;

    errno = 0;
    url->decoder = open_inflate_handler(url_inflate_read_func, url);
    if(url->decoder == NULL)
    {
	if(autoclose)
	    url_close(instream);
	url_inflate_close((URL)url);
	url_errno = errno;
	return NULL;
    }

    return (URL)url;
}
Beispiel #13
0
static int sap_read_close(AVFormatContext *s)
{
    struct SAPState *sap = s->priv_data;
    if (sap->sdp_ctx)
        av_close_input_stream(sap->sdp_ctx);
    if (sap->ann_fd)
        url_close(sap->ann_fd);
    av_freep(&sap->sdp);
    ff_network_close();
    return 0;
}
Beispiel #14
0
static int mmsh_close(URLContext *h)
{
    MMSHContext *mmsh = (MMSHContext *)h->priv_data;
    MMSContext *mms   = &mmsh->mms;
    if (mms->mms_hd)
        url_close(mms->mms_hd);
    av_free(mms->streams);
    av_free(mms->asf_header);
    av_freep(&h->priv_data);
    return 0;
}
Beispiel #15
0
static int rtsp_write_close(AVFormatContext *s)
{
    RTSPState *rt = s->priv_data;

    ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL);

    ff_rtsp_close_streams(s);
    url_close(rt->rtsp_hd);
    ff_network_close();
    return 0;
}
static void url_inflate_close(URL url)
{
    int save_errno = errno;
    URL_inflate *urlp = (URL_inflate *)url;
    if(urlp->decoder)
	close_inflate_handler(urlp->decoder);
    if(urlp->autoclose)
	url_close(urlp->instream);
    free(url);
    errno = save_errno;
}
Beispiel #17
0
int url_open(URLContext **puc, const char *filename, int flags)
{
    int ret = url_alloc(puc, filename, flags);
    if (ret)
        return ret;
    ret = url_connect(*puc);
    if (!ret)
        return 0;
    url_close(*puc);
    *puc = NULL;
    return ret;
}
Beispiel #18
0
static void
input_ffmpeg_close(struct input_stream *is)
{
	struct input_ffmpeg *i = (struct input_ffmpeg *)is;

#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
	avio_close(i->h);
#else
	url_close(i->h);
#endif
	input_stream_deinit(&i->base);
	g_free(i);
}
Beispiel #19
0
static void eb_io_stop(EditBuffer *b, int err)
{
    BufferIOState *s = b->io_state;

    b->flags = s->saved_flags;
    if (s->nolog) {
        b->modified = 0;
        b->save_log = s->saved_log;
    }
    url_close(s->handle);
    s->completion_cb(s->opaque, err);
    free(s);
    b->io_state = NULL;
}
Beispiel #20
0
static av_cold int concat_close(URLContext *h)
{
    int err = 0;
    size_t i;
    struct concat_data  *data  = h->priv_data;
    struct concat_nodes *nodes = data->nodes;

    for (i = 0; i != data->length; i++)
        err |= url_close(nodes[i].uc);

    av_freep(&data->nodes);
    av_freep(&h->priv_data);

    return err < 0 ? -1 : 0;
}
Beispiel #21
0
/** Close the MMSH/MMST connection */
static int mms_close(URLContext *h)
{
    MMSContext *mms = (MMSContext *)h->priv_data;

    if(mms->mms_hd) {
        send_close_packet(mms);
        url_close(mms->mms_hd);
    }

    /* free all separately allocated pointers in mms */
    av_free(mms->asf_header);
    av_freep(&h->priv_data);

    return 0;
}
Beispiel #22
0
static int http_close(URLContext *h)
{
    int ret = 0;
    char footer[] = "0\r\n\r\n";
    HTTPContext *s = h->priv_data;

    /* signal end of chunked encoding if used */
    if ((h->flags & URL_WRONLY) && s->chunksize != -1) {
        ret = url_write(s->hd, footer, sizeof(footer) - 1);
        ret = ret > 0 ? 0 : ret;
    }

    url_close(s->hd);
    av_free(s);
    return ret;
}
Beispiel #23
0
int url_open_protocol (URLContext **puc, struct URLProtocol *up,
                       const char *filename, int flags)
{
    int ret;

    ret = url_alloc_for_protocol(puc, up, filename, flags);
    if (ret)
        goto fail;
    ret = url_connect(*puc);
    if (!ret)
        return 0;
 fail:
    url_close(*puc);
    *puc = NULL;
    return ret;
}
Beispiel #24
0
static int rtsp_write_header(AVFormatContext *s)
{
    RTSPState *rt = s->priv_data;
    int ret;

    ret = ff_rtsp_connect(s);
    if (ret)
        return ret;

    if (rtsp_write_record(s) < 0) {
        ff_rtsp_close_streams(s);
        url_close(rt->rtsp_hd);
        return AVERROR_INVALIDDATA;
    }
    return 0;
}
Beispiel #25
0
static void rtp_output_context_free(RtpOutputContext *rtpContext) {
    if (rtpContext->urlContext != NULL) {
        url_close(rtpContext->urlContext);
    }
    if (rtpContext->avContext != NULL) {
        free_av_format_context(rtpContext->avContext);
    }
    if (rtpContext->tempFrame != NULL) {
        avpicture_free((AVPicture *)rtpContext->tempFrame);
        av_free(rtpContext->tempFrame);
    }
    if (rtpContext->imgConvert != NULL) {
        sws_freeContext(rtpContext->imgConvert);
    }
    av_free(rtpContext);
}
Beispiel #26
0
/* close and free RTSP streams */
static void rtsp_close_streams(RTSPState *rt)
{
    int i;
    RTSPStream *rtsp_st;

    for(i=0;i<rt->nb_rtsp_streams;i++) {
        rtsp_st = rt->rtsp_streams[i];
        if (rtsp_st) {
            if (rtsp_st->rtp_ctx)
                rtp_parse_close(rtsp_st->rtp_ctx);
            if (rtsp_st->rtp_handle)
                url_close(rtsp_st->rtp_handle);
        }
        av_free(rtsp_st);
    }
    av_free(rt->rtsp_streams);
}
Beispiel #27
0
/* close and free RTSP streams */
static void rtsp_close_streams(RTSPState *rt)
{
    int i;
    RTSPStream *rtsp_st;

    for(i=0;i<rt->nb_rtsp_streams;i++) {
        rtsp_st = rt->rtsp_streams[i];
        if (rtsp_st) {
            if (rtsp_st->rtp_ctx)
                rtp_parse_close(rtsp_st->rtp_ctx);
            if (rtsp_st->rtp_handle)
                url_close(rtsp_st->rtp_handle);
            if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context)
                rtsp_st->dynamic_handler->close(rtsp_st->dynamic_protocol_context);
        }
    }
    av_free(rt->rtsp_streams);
}
Beispiel #28
0
Datei: mmsh.c Projekt: a5an0/xbmc
static int64_t mmsh_read_seek(URLContext *h, int stream_index,
                        int64_t timestamp, int flags)
{
    MMSHContext *mmsh = h->priv_data;
    MMSContext *mms   = &mmsh->mms;
    int ret;

    ret= mmsh_open_internal(h, mmsh->location, 0, FFMAX(timestamp, 0), 0);

    if(ret>=0){
        if (mms->mms_hd)
            url_close(mms->mms_hd);
        av_freep(&mms->streams);
        av_freep(&mms->asf_header);
        av_free(mmsh);
        mmsh = h->priv_data;
        mms   = &mmsh->mms;
        mms->asf_header_read_size= mms->asf_header_size;
    }else
        h->priv_data= mmsh;
    return ret;
}
Beispiel #29
0
/* This closes files opened with open_file */
void close_file(struct timidity_file *tf)
{
    int save_errno = errno;
    if(tf->url != NULL)
    {
#ifndef __W32__
	if(tf->tmpname != NULL)
	{
	    int i;
	    /* dispose the pipe garbage */
	    for(i = 0; tf_getc(tf) != EOF && i < 0xFFFF; i++)
		;
	}
#endif /* __W32__ */
	url_close(tf->url);
    }
    if(tf->tmpname != NULL)
    {
	unlink(tf->tmpname); /* remove temporary file */
	free(tf->tmpname);
    }
    free(tf);
    errno = save_errno;
}
Beispiel #30
0
// Open a file with a (possibly) Unicode filename
int ufile_fopen(AVIOContext **s, const wxString & name, int flags)
{
   wxString url(wxString(wxT(UFILE_PROTOCOL)) + wxT(":") + name);
   URLContext *h;
   int err;

   // Open the file using our custom protocol and passing the (possibly) Unicode
   // filename.  We convert the name to UTF8 here and it will be converted back
   // to original encoding in ufile_open().  This allows us to support Unicode
   // filenames even though FFmpeg does not.
   err = url_open(&h, (const char *) url.ToUTF8(), flags);
   if (err < 0) {
      return err;
   }

   // Associate the file with a context
   err = url_fdopen(s, h);
   if (err < 0) {
      url_close(h);
      return err;
   }

   return 0;
}