* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
+#include "libavutil/base64.h"
+#include "libavutil/avstring.h"
#include "avformat.h"
#include <unistd.h>
#include "network.h"
-
-#include "base64.h"
+#include "os_support.h"
/* XXX: POST protocol is not completely implemented because ffmpeg uses
only a subset of it. */
unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
int line_count;
int http_code;
- offset_t off, filesize;
+ int64_t off, filesize;
char location[URL_SIZE];
} HTTPContext;
proxy_path = getenv("http_proxy");
use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
- strstart(proxy_path, "http://", NULL);
+ av_strstart(proxy_path, "http://", NULL);
/* fill the dest addr */
redo:
if (port > 0) {
snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port);
} else {
- pstrcpy(hoststr, sizeof(hoststr), hostname);
+ av_strlcpy(hoststr, hostname, sizeof(hoststr));
}
if (use_proxy) {
/* url moved, get next */
url_close(hd);
if (redirects++ >= MAX_REDIRECTS)
- return AVERROR_IO;
+ return AVERROR(EIO);
location_changed = 0;
goto redo;
}
fail:
if (hd)
url_close(hd);
- return AVERROR_IO;
+ return AVERROR(EIO);
}
static int http_open(URLContext *h, const char *uri, int flags)
h->priv_data = s;
s->filesize = -1;
s->off = 0;
- pstrcpy (s->location, URL_SIZE, uri);
+ av_strlcpy(s->location, uri, URL_SIZE);
ret = http_open_cnx(h);
if (ret != 0)
if (s->buf_ptr >= s->buf_end) {
len = url_read(s->hd, s->buffer, BUFFER_SIZE);
if (len < 0) {
- return AVERROR_IO;
+ return AVERROR(EIO);
} else if (len == 0) {
return -1;
} else {
char line[1024], *q;
char *auth_b64;
int auth_b64_len = strlen(auth)* 4 / 3 + 12;
- offset_t off = s->off;
+ int64_t off = s->off;
/* send http header */
post = h->flags & URL_WRONLY;
auth_b64 = av_malloc(auth_b64_len);
- av_base64_encode(auth_b64, auth_b64_len, (uint8_t *)auth, strlen(auth));
+ av_base64_encode(auth_b64, auth_b64_len, auth, strlen(auth));
snprintf(s->buffer, sizeof(s->buffer),
"%s %s HTTP/1.1\r\n"
"User-Agent: %s\r\n"
av_freep(&auth_b64);
if (http_write(h, s->buffer, strlen(s->buffer)) < 0)
- return AVERROR_IO;
+ return AVERROR(EIO);
/* init input buffer */
s->buf_ptr = s->buffer;
s->off = 0;
s->filesize = -1;
if (post) {
- sleep(1);
return 0;
}
for(;;) {
ch = http_getc(s);
if (ch < 0)
- return AVERROR_IO;
+ return AVERROR(EIO);
if (ch == '\n') {
/* process line */
if (q > line && q[-1] == '\r')
return 0;
}
-static offset_t http_seek(URLContext *h, offset_t off, int whence)
+static int64_t http_seek(URLContext *h, int64_t off, int whence)
{
HTTPContext *s = h->priv_data;
URLContext *old_hd = s->hd;
- offset_t old_off = s->off;
+ int64_t old_off = s->off;
if (whence == AVSEEK_SIZE)
return s->filesize;