change license from GPLv2 to 'GPL v2 or later', requested by Diego, I can do that since I wrote the files (based on other stuff from MPlayer (and some external things under GPL v2 or later))
line source
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 /*
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * HTTP Helper
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * by Bertrand Baudet <bertrand_baudet@yahoo.com>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * (C) 2001, MPlayer team.
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include "config.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include <stdio.h>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include <stdlib.h>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include <string.h>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include <unistd.h>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #ifndef HAVE_WINSOCK2
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #define closesocket close
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #else
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include <winsock2.h>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include <ws2tcpip.h>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #endif
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include "http.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include "url.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include "mp_msg.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include "stream.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include "libmpdemux/demuxer.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include "network.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 #include "help_mp.h"
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 extern const mime_struct_t mime_type_table[];
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 extern int stream_cache_size;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 extern int network_bandwidth;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 extern int http_seek(stream_t *stream, off_t pos);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 typedef struct {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned metaint;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned metapos;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int is_ultravox;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } scast_data_t;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 /**
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \brief first read any data from sc->buffer then from fd
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param fd file descriptor to read data from
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param buffer buffer to read into
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param len how many bytes to read
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param sc streaming control containing buffer to read from first
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \return len unless there is a read error or eof
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static unsigned my_read(int fd, char *buffer, int len, streaming_ctrl_t *sc) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned pos = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned cp_len = sc->buffer_size - sc->buffer_pos;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (cp_len > len)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 cp_len = len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 memcpy(buffer, &sc->buffer[sc->buffer_pos], cp_len);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 sc->buffer_pos += cp_len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 pos += cp_len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while (pos < len) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int ret = recv(fd, &buffer[pos], len - pos, 0);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (ret <= 0)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 break;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 pos += ret;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return pos;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 /**
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \brief read and process (i.e. discard *g*) a block of ultravox metadata
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param fd file descriptor to read from
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param sc streaming_ctrl_t whose buffer is consumed before reading from fd
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \return number of real data before next metadata block starts or 0 on error
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static unsigned uvox_meta_read(int fd, streaming_ctrl_t *sc) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned metaint;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned char info[6] = {0, 0, 0, 0, 0, 0};
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int info_read;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 do {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 info_read = my_read(fd, info, 1, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (info[0] == 0x00)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 info_read = my_read(fd, info, 6, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 else
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 info_read += my_read(fd, &info[1], 5, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (info_read != 6) // read error or eof
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // sync byte and reserved flags
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (info[0] != 0x5a || (info[1] & 0xfc) != 0x00) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_DEMUXER, MSGL_ERR, "Invalid or unknown uvox metadata\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (info[1] & 0x01)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_DEMUXER, MSGL_WARN, "Encrypted ultravox data\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 metaint = info[4] << 8 | info[5];
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if ((info[3] & 0xf) < 0x07) { // discard any metadata nonsense
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *metabuf = malloc(metaint);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 my_read(fd, metabuf, metaint, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free(metabuf);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } while ((info[3] & 0xf) < 0x07);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return metaint;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 /**
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \brief read one scast meta data entry and print it
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param fd file descriptor to read from
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param sc streaming_ctrl_t whose buffer is consumed before reading from fd
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static void scast_meta_read(int fd, streaming_ctrl_t *sc) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned char tmp = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned metalen;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 my_read(fd, &tmp, 1, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 metalen = tmp * 16;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (metalen > 0) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *info = malloc(metalen + 1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned nlen = my_read(fd, info, metalen, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 info[nlen] = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_DEMUXER, MSGL_INFO, "\nICY Info: %s\n", info);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free(info);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 /**
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \brief read data from scast/ultravox stream without any metadata
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param fd file descriptor to read from
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param buffer buffer to read data into
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param size number of bytes to read
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 * \param sc streaming_ctrl_t whose buffer is consumed before reading from fd
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 */
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static int scast_streaming_read(int fd, char *buffer, int size,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 streaming_ctrl_t *sc) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 scast_data_t *sd = (scast_data_t *)sc->data;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned block, ret;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned done = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // first read remaining data up to next metadata
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 block = sd->metaint - sd->metapos;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (block > size)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 block = size;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ret = my_read(fd, buffer, block, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 sd->metapos += ret;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 done += ret;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (ret != block) // read problems or eof
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 size = done;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while (done < size) { // now comes the metadata
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (sd->is_ultravox)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 sd->metaint = uvox_meta_read(fd, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (!sd->metaint)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 size = done;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 else
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 scast_meta_read(fd, sc); // read and display metadata
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 sd->metapos = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 block = size - done;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (block > sd->metaint)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 block = sd->metaint;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ret = my_read(fd, &buffer[done], block, sc);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 sd->metapos += ret;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 done += ret;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (ret != block) // read problems or eof
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 size = done;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return done;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static int scast_streaming_start(stream_t *stream) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int metaint;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 scast_data_t *scast_data;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_header_t *http_hdr = stream->streaming_ctrl->data;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (!stream || stream->fd < 0 || !http_hdr)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (is_ultravox)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 metaint = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 else {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 metaint = atoi(http_get_field(http_hdr, "Icy-MetaInt"));
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (metaint <= 0)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->buffer = malloc(http_hdr->body_size);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->buffer_size = http_hdr->body_size;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->buffer_pos = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 memcpy(stream->streaming_ctrl->buffer, http_hdr->body, http_hdr->body_size);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 scast_data = malloc(sizeof(scast_data_t));
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 scast_data->metaint = metaint;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 scast_data->metapos = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 scast_data->is_ultravox = is_ultravox;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_free(http_hdr);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->data = scast_data;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->streaming_read = scast_streaming_read;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->streaming_seek = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->prebuffer_size = 64 * 1024; // 64 KBytes
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->buffering = 1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->status = streaming_playing_e;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static int nop_streaming_start( stream_t *stream ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_header_t *http_hdr = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *next_url=NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 URL_t *rd_url=NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int fd,ret;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( stream==NULL ) return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 fd = stream->fd;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( fd<0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 fd = http_send_request( stream->streaming_ctrl->url, 0 );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( fd<0 ) return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr = http_read_response( fd );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 switch( http_hdr->status_code ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 200: // OK
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->body_size>0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_free( http_hdr );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 break;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Redirect
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 301: // Permanently
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 302: // Temporarily
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 303: // See Other
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ret=-1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 next_url = http_get_field( http_hdr, "Location" );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (next_url != NULL)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 rd_url=url_new(next_url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (next_url != NULL && rd_url != NULL) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Redirected: Using this url instead %s\n",next_url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->url=check4proxies(rd_url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ret=nop_streaming_start(stream); //recursively get streaming started
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } else {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Redirection failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 closesocket( fd );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 fd = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return ret;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 break;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 401: //Authorization required
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 403: //Forbidden
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 404: //Not found
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 500: //Server Error
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 default:
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned code %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 closesocket( fd );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 fd = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 break;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->fd = fd;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } else {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr = (HTTP_header_t*)stream->streaming_ctrl->data;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->body_size>0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_free( http_hdr );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->data = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_free( http_hdr );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->data = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->streaming_read = nop_streaming_read;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->streaming_seek = nop_streaming_seek;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->prebuffer_size = 64*1024; // 64 KBytes
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->buffering = 1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->status = streaming_playing_e;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_header_t *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_new_header(void) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_header_t *http_hdr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr = malloc(sizeof(HTTP_header_t));
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 memset( http_hdr, 0, sizeof(HTTP_header_t) );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return http_hdr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 void
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_free( HTTP_header_t *http_hdr ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_field_t *field, *field2free;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->protocol!=NULL ) free( http_hdr->protocol );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->uri!=NULL ) free( http_hdr->uri );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->reason_phrase!=NULL ) free( http_hdr->reason_phrase );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->field_search!=NULL ) free( http_hdr->field_search );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->method!=NULL ) free( http_hdr->method );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->buffer!=NULL ) free( http_hdr->buffer );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = http_hdr->first_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( field!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field2free = field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (field->field_name)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free(field->field_name);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = field->next;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free( field2free );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free( http_hdr );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_response_append( HTTP_header_t *http_hdr, char *response, int length ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL || response==NULL || length<0 ) return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( (unsigned)length > SIZE_MAX - http_hdr->buffer_size - 1) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Bad size in memory (re)allocation\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->buffer = (char*)realloc( http_hdr->buffer, http_hdr->buffer_size+length+1 );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->buffer==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory (re)allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 memcpy( http_hdr->buffer+http_hdr->buffer_size, response, length );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->buffer_size += length;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->buffer[http_hdr->buffer_size]=0; // close the string!
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return http_hdr->buffer_size;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_is_header_entire( HTTP_header_t *http_hdr ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->buffer==NULL ) return 0; // empty
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( strstr(http_hdr->buffer, "\r\n\r\n")==NULL &&
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strstr(http_hdr->buffer, "\n\n")==NULL ) return 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return 1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_response_parse( HTTP_header_t *http_hdr ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *hdr_ptr, *ptr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *field=NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int pos_hdr_sep, hdr_sep_len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 size_t len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->is_parsed ) return 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Get the protocol
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 hdr_ptr = strstr( http_hdr->buffer, " " );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( hdr_ptr==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. No space separator found.\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 len = hdr_ptr-http_hdr->buffer;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->protocol = malloc(len+1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->protocol==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strncpy( http_hdr->protocol, http_hdr->buffer, len );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->protocol[len]='\0';
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( !strncasecmp( http_hdr->protocol, "HTTP", 4) ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( sscanf( http_hdr->protocol+5,"1.%d", &(http_hdr->http_minor_version) )!=1 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get HTTP minor version.\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Get the status code
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( sscanf( ++hdr_ptr, "%d", &(http_hdr->status_code) )!=1 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get status code.\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 hdr_ptr += 4;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Get the reason phrase
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr = strstr( hdr_ptr, "\n" );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( hdr_ptr==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get the reason phrase.\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 len = ptr-hdr_ptr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->reason_phrase = malloc(len+1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->reason_phrase==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strncpy( http_hdr->reason_phrase, hdr_ptr, len );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->reason_phrase[len-1]=='\r' ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 len--;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->reason_phrase[len]='\0';
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Set the position of the header separator: \r\n\r\n
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 hdr_sep_len = 4;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr = strstr( http_hdr->buffer, "\r\n\r\n" );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( ptr==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr = strstr( http_hdr->buffer, "\n\n" );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( ptr==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Header may be incomplete. No CRLF CRLF found.\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 hdr_sep_len = 2;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 pos_hdr_sep = ptr-http_hdr->buffer;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Point to the first line after the method line.
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 hdr_ptr = strstr( http_hdr->buffer, "\n" )+1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 do {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr = hdr_ptr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( *ptr!='\r' && *ptr!='\n' ) ptr++;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 len = ptr-hdr_ptr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( len==0 ) break;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = (char*)realloc(field, len+1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( field==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strncpy( field, hdr_ptr, len );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field[len]='\0';
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_set_field( http_hdr, field );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 hdr_ptr = ptr+((*ptr=='\r')?2:1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } while( hdr_ptr<(http_hdr->buffer+pos_hdr_sep) );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( field!=NULL ) free( field );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( pos_hdr_sep+hdr_sep_len<http_hdr->buffer_size ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Response has data!
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->body = http_hdr->buffer+pos_hdr_sep+hdr_sep_len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->body_size = http_hdr->buffer_size-(pos_hdr_sep+hdr_sep_len);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->is_parsed = 1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_build_request( HTTP_header_t *http_hdr ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *ptr, *uri=NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_field_t *field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->method==NULL ) http_set_method( http_hdr, "GET");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->uri==NULL ) http_set_uri( http_hdr, "/");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 else {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 uri = malloc(strlen(http_hdr->uri) + 1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( uri==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strcpy(uri,http_hdr->uri);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 //**** Compute the request length
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Add the Method line
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 len = strlen(http_hdr->method)+strlen(uri)+12;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Add the fields
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = http_hdr->first_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( field!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 len += strlen(field->field_name)+2;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = field->next;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Add the CRLF
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 len += 2;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Add the body
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->body!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 len += http_hdr->body_size;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Free the buffer if it was previously used
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->buffer!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free( http_hdr->buffer );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->buffer = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->buffer = malloc(len+1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->buffer==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->buffer_size = len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 //*** Building the request
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr = http_hdr->buffer;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Add the method line
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, uri, http_hdr->http_minor_version );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = http_hdr->first_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Add the field
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( field!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr += sprintf( ptr, "%s\r\n", field->field_name );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = field->next;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr += sprintf( ptr, "\r\n" );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Add the body
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->body!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 memcpy( ptr, http_hdr->body, http_hdr->body_size );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( uri ) free( uri );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return http_hdr->buffer;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_get_field( HTTP_header_t *http_hdr, const char *field_name ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL || field_name==NULL ) return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->field_search_pos = http_hdr->first_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->field_search = (char*)realloc( http_hdr->field_search, strlen(field_name)+1 );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->field_search==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strcpy( http_hdr->field_search, field_name );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return http_get_next_field( http_hdr );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_get_next_field( HTTP_header_t *http_hdr ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *ptr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_field_t *field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = http_hdr->field_search_pos;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( field!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr = strstr( field->field_name, ":" );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( ptr==NULL ) return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( !strncasecmp( field->field_name, http_hdr->field_search, ptr-(field->field_name) ) ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 ptr++; // Skip the column
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( ptr[0]==' ' ) ptr++; // Skip the spaces if there is some
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->field_search_pos = field->next;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return ptr; // return the value without the field name
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = field->next;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 void
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_set_field( HTTP_header_t *http_hdr, const char *field_name ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_field_t *new_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL || field_name==NULL ) return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 new_field = malloc(sizeof(HTTP_field_t));
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( new_field==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 new_field->next = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 new_field->field_name = malloc(strlen(field_name)+1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( new_field->field_name==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strcpy( new_field->field_name, field_name );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->last_field==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->first_field = new_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } else {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->last_field->next = new_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->last_field = new_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->field_nb++;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 void
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_set_method( HTTP_header_t *http_hdr, const char *method ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL || method==NULL ) return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->method = malloc(strlen(method)+1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->method==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strcpy( http_hdr->method, method );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 void
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_set_uri( HTTP_header_t *http_hdr, const char *uri ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL || uri==NULL ) return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr->uri = malloc(strlen(uri)+1);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr->uri==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 strcpy( http_hdr->uri, uri );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int encoded_len, pass_len=0, out_len;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int res = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL || username==NULL ) return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( password!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 pass_len = strlen(password);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 usr_pass = malloc(strlen(username)+pass_len+2);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( usr_pass==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Base 64 encode with at least 33% more data than the original size
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 encoded_len = strlen(usr_pass)*2;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 b64_usr_pass = malloc(encoded_len);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( b64_usr_pass==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 out_len = base64_encode( usr_pass, strlen(usr_pass), b64_usr_pass, encoded_len);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( out_len<0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Base64 out overflow\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 b64_usr_pass[out_len]='\0';
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 auth = malloc(encoded_len+22);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( auth==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 sprintf( auth, "Authorization: Basic %s", b64_usr_pass);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_set_field( http_hdr, auth );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 res = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 out:
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free( usr_pass );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free( b64_usr_pass );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free( auth );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return res;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 void
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_debug_hdr( HTTP_header_t *http_hdr ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_field_t *field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int i = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) return;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- START ---\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"protocol: [%s]\n", http_hdr->protocol );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"http minor version: [%d]\n", http_hdr->http_minor_version );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"uri: [%s]\n", http_hdr->uri );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"method: [%s]\n", http_hdr->method );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"status code: [%d]\n", http_hdr->status_code );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"reason phrase: [%s]\n", http_hdr->reason_phrase );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"body size: [%d]\n", http_hdr->body_size );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"Fields:\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = http_hdr->first_field;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( field!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V," %d - %s\n", i++, field->field_name );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 field = field->next;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- END ---\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 base64_encode(const void *enc, int encLen, char *out, int outMax) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned char *encBuf;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int outLen;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned int bits;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned int shift;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 encBuf = (unsigned char*)enc;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 outLen = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 bits = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 shift = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 outMax &= ~3;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while(1) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( encLen>0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Shift in byte
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 bits <<= 8;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 bits |= *encBuf;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 shift += 8;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Next byte
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 encBuf++;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 encLen--;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } else if( shift>0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Pad last bits to 6 bits - will end next loop
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 bits <<= 6 - shift;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 shift = 6;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } else {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // As per RFC 2045, section 6.8,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // pad output as necessary: 0 to 2 '=' chars.
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( outLen & 3 ){
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 *out++ = '=';
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 outLen++;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return outLen;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Encode 6 bit segments
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while( shift>=6 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (outLen >= outMax)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 shift -= 6;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 *out = b64[ (bits >> shift) & 0x3F ];
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 out++;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 outLen++;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 //! If this function succeeds you must closesocket stream->fd
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static int http_streaming_start(stream_t *stream, int* file_format) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_header_t *http_hdr = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 unsigned int i;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int fd = stream->fd;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int res = STREAM_UNSUPPORTED;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int redirect = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int auth_retry=0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int seekable=0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *content_type;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *next_url;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 URL_t *url = stream->streaming_ctrl->url;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 do
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 redirect = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (fd > 0) closesocket(fd);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 fd = http_send_request( url, 0 );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( fd<0 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_free(http_hdr);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr = http_read_response( fd );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( mp_msg_test(MSGT_NETWORK,MSGL_V) ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_debug_hdr( http_hdr );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Check if we can make partial content requests and thus seek in http-streams
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_hdr!=NULL && http_hdr->status_code==200 ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *accept_ranges;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( (accept_ranges = http_get_field(http_hdr,"Accept-Ranges")) != NULL )
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 seekable = strncmp(accept_ranges,"bytes",5)==0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Check if the response is an ICY status_code reason_phrase
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( !strcasecmp(http_hdr->protocol, "ICY") ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 switch( http_hdr->status_code ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 200: { // OK
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *field_data = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // note: I skip icy-notice1 and 2, as they contain html <BR>
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // and are IMHO useless info ::atmos
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( (field_data = http_get_field(http_hdr, "icy-name")) != NULL )
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_INFO,"Name : %s\n", field_data); field_data = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( (field_data = http_get_field(http_hdr, "icy-genre")) != NULL )
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_INFO,"Genre : %s\n", field_data); field_data = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( (field_data = http_get_field(http_hdr, "icy-url")) != NULL )
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_INFO,"Website: %s\n", field_data); field_data = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // XXX: does this really mean public server? ::atmos
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( (field_data = http_get_field(http_hdr, "icy-pub")) != NULL )
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_INFO,"Public : %s\n", atoi(field_data)?"yes":"no"); field_data = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( (field_data = http_get_field(http_hdr, "icy-br")) != NULL )
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_INFO,"Bitrate: %skbit/s\n", field_data); field_data = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // If content-type == video/nsv we most likely have a winamp video stream
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // otherwise it should be mp3. if there are more types consider adding mime type
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // handling like later
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if ( (field_data = http_get_field(http_hdr, "content-type")) != NULL && (!strcmp(field_data, "video/nsv") || !strcmp(field_data, "misc/ultravox")))
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 *file_format = DEMUXER_TYPE_NSV;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 else if ( (field_data = http_get_field(http_hdr, "content-type")) != NULL && (!strcmp(field_data, "audio/aacp") || !strcmp(field_data, "audio/aac")))
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 *file_format = DEMUXER_TYPE_AAC;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 else
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 *file_format = DEMUXER_TYPE_AUDIO;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 res = STREAM_ERROR;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 400: // Server Full
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server is full, skipping!\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 401: // Service Unavailable
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return service unavailable, skipping!\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 403: // Service Forbidden
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return 'Service Forbidden'\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 404: // Resource Not Found
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server couldn't find requested stream, skipping!\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 default:
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: unhandled ICY-Errorcode, contact MPlayer developers!\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Assume standard http if not ICY
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 switch( http_hdr->status_code ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 200: // OK
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Look if we can use the Content-Type
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 content_type = http_get_field( http_hdr, "Content-Type" );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( content_type!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 char *content_length = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", content_type );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( (content_length = http_get_field(http_hdr, "Content-Length")) != NULL)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length"));
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Check in the mime type table for a demuxer type
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 i = 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 while(mime_type_table[i].mime_type != NULL) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( !strcasecmp( content_type, mime_type_table[i].mime_type ) ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 *file_format = mime_type_table[i].demuxer_type;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 res = seekable;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 i++;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Not found in the mime type table, don't fail,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // we should try raw HTTP
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 res = seekable;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // Redirect
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 301: // Permanently
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 302: // Temporarily
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 303: // See Other
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 // TODO: RFC 2616, recommand to detect infinite redirection loops
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 next_url = http_get_field( http_hdr, "Location" );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( next_url!=NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->url = url_redirect( &url, next_url );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (!strcasecmp(url->protocol, "mms")) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 res = STREAM_REDIRECTED;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (strcasecmp(url->protocol, "http")) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Unsupported http %d redirect to %s protocol\n", http_hdr->status_code, url->protocol);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (is_ultravox) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 free(url->protocol);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 url->protocol = strdup("unsv");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 redirect = 1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 break;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 case 401: // Authentication required
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( http_authenticate(http_hdr, url, &auth_retry)<0 )
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 redirect = 1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 break;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 default:
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 goto err_out;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 } while( redirect );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 err_out:
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (fd > 0) closesocket( fd );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 fd = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_free( http_hdr );
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 http_hdr = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 out:
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->data = (void*)http_hdr;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->fd = fd;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return res;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static int fixup_open(stream_t *stream,int seekable) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 HTTP_header_t *http_hdr = stream->streaming_ctrl->data;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int is_icy = http_hdr && http_get_field(http_hdr, "Icy-MetaInt");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->type = STREAMTYPE_STREAM;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if(!is_icy && !is_ultravox && seekable)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->flags |= STREAM_SEEK;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->seek = http_seek;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->bandwidth = network_bandwidth;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if ((!is_icy && !is_ultravox) || scast_streaming_start(stream))
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if(nop_streaming_start( stream )) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_start failed\n");
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (stream->fd >= 0)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 closesocket(stream->fd);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->fd = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 streaming_ctrl_free(stream->streaming_ctrl);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return STREAM_UNSUPPORTED;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 fixup_network_stream_cache(stream);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return STREAM_OK;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static int open_s1(stream_t *stream,int mode, void* opts, int* file_format) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int seekable=0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 URL_t *url;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl = streaming_ctrl_new();
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( stream->streaming_ctrl==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return STREAM_ERROR;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->bandwidth = network_bandwidth;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 url = url_new(stream->url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->url = check4proxies(url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 url_free(url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(1), URL: %s\n", stream->url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 seekable = http_streaming_start(stream, file_format);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if((seekable < 0) || (*file_format == DEMUXER_TYPE_ASF)) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (stream->fd >= 0)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 closesocket(stream->fd);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->fd = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (seekable == STREAM_REDIRECTED)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return seekable;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 streaming_ctrl_free(stream->streaming_ctrl);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return STREAM_UNSUPPORTED;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return fixup_open(stream, seekable);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 static int open_s2(stream_t *stream,int mode, void* opts, int* file_format) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 int seekable=0;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 URL_t *url;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl = streaming_ctrl_new();
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if( stream->streaming_ctrl==NULL ) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return STREAM_ERROR;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->bandwidth = network_bandwidth;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 url = url_new(stream->url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl->url = check4proxies(url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 url_free(url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(2), URL: %s\n", stream->url);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 seekable = http_streaming_start(stream, file_format);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if(seekable < 0) {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 if (stream->fd >= 0)
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 closesocket(stream->fd);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->fd = -1;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 streaming_ctrl_free(stream->streaming_ctrl);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 stream->streaming_ctrl = NULL;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return STREAM_UNSUPPORTED;
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 return fixup_open(stream, seekable);
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 }
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 const stream_info_t stream_info_http1 = {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 "http streaming",
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 "null",
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 "Bertrand, Albeau, Reimar Doeffinger, Arpi?",
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 "plain http",
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 open_s1,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 {"http", "http_proxy", "unsv", NULL},
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 NULL,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 0 // Urls are an option string
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 };
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 const stream_info_t stream_info_http2 = {
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 "http streaming",
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 "null",
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 "Bertrand, Albeu, Arpi? who?",
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 "plain http, also used as fallback for many other protocols",
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 open_s2,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 {"http", "http_proxy", "pnm", "mms", "mmsu", "mmst", "rtsp", NULL}, //all the others as fallback
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 NULL,
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 0 // Urls are an option string
+ 鐃緒申��申鐃初姐�渇����鐃醇�鐃緒申��申鐃緒申 };