Exemplo n.º 1
0
void
trelease(spdid_t spdid, td_t td)
{
	struct torrent *t;
	struct connection *c;

	if (!tor_is_usrdef(td)) return;

	LOCK();
	t = tor_lookup(td);
	if (!t) goto done;
	c = t->data;
	lock_connection(c);
	/* wait till others release the connection */
	unlock_connection(c);
	if (c) {
		http_free_connection(c);
		/* bookkeeping */
		http_conn_cnt++;
	}
	tor_free(t);
done:
	UNLOCK();
	return;
}
Exemplo n.º 2
0
static session_desc_t *find_sdp_for_program (const char *cm,
        const char *loc,
        char *errmsg,
        uint32_t errlen,
        uint64_t prog)
{
    char buffer[1024];
    http_client_t *http_client;
    http_resp_t *http_resp;
    sdp_decode_info_t *sdp_info;
    session_desc_t *sdp, *ptr, *sdp_ret;
    int translated;
    int ret, ix;

    snprintf(buffer, sizeof(buffer), "http://%s/%s", cm, loc);
    http_resp = NULL;
    http_client = http_init_connection(buffer);

    if (http_client == NULL) {
        snprintf(errmsg, errlen, "Cannot create http client with %s\n",
                 cm);
        return NULL;
    }
    ret = http_get(http_client, NULL, &http_resp);

    sdp_ret = NULL;
    if (ret > 0) {
        sdp_info = set_sdp_decode_from_memory(http_resp->body);
        if ((sdp_decode(sdp_info, &sdp, &translated) == 0) &&
                (translated > 0)) {
            for (ix = 0; ix < translated && sdp_ret == NULL; ix++) {
                if (sdp->session_id == prog) {
                    sdp_ret = sdp;
                    sdp = sdp->next;
                    sdp_ret->next = NULL;
                } else {
                    ptr = sdp->next;
                    sdp->next = NULL;
                    sdp_free_session_desc(sdp);
                    sdp = ptr;
                }
            }
            sdp_decode_info_free(sdp_info);
            if (sdp != NULL) sdp_free_session_desc(sdp);

        }
    }
    http_resp_free(http_resp);
    http_free_connection(http_client);
    return sdp_ret;
}
int content_remove(spdid_t spdid, long conn_id)
{
	struct connection *c = cos_map_lookup(&conn_map, conn_id);

	if (NULL == c) return 1;
	cos_map_del(&conn_map, c->conn_id);
	c->conn_id = -1;
	http_free_connection(c);

	/* bookkeeping */
	http_conn_cnt++;

	return 0;
}
long content_create(spdid_t spdid, long evt_id, struct cos_array *d)
{
	struct connection *c = http_new_connection(0, evt_id);
	long c_id;

//	printc("HTTP open connection");
	if (NULL == c) return -ENOMEM;
	c_id = cos_map_add(&conn_map, c);
	if (c_id < 0) {
		http_free_connection(c);
		return -ENOMEM;
	}
	c->conn_id = c_id;
	
	return c_id;
}
Exemplo n.º 5
0
int main (int argc, char **argv)
{
    http_client_t *http_client;
    http_resp_t *http_resp;
    argv++;
    http_set_loglevel(LOG_DEBUG);

    http_client = http_init_connection(*argv);
    if (http_client == NULL) {
        printf("no client\n");
        return (1);
    }

    argv++;
    http_resp = NULL;
    printf("argv is %s\n", *argv);
    http_get(http_client, *argv, &http_resp);
    http_resp_free(http_resp);
    http_free_connection(http_client);
    return (0);
}
Exemplo n.º 6
0
static int create_media_for_http (CPlayerSession *psptr,
                                  const char *name,
                                  char *errmsg,
                                  uint32_t errlen,
                                  control_callback_vft_t *cc_vft)
{
    http_client_t *http_client;

    int ret;
    http_resp_t *http_resp;
    http_resp = NULL;
    http_client = http_init_connection(name);

    if (http_client == NULL) {
        snprintf(errmsg, errlen, "Can't create http client");
        return -1;
    }
    ret = http_get(http_client, NULL, &http_resp);
    if (ret > 0) {
        sdp_decode_info_t *sdp_info;

        int have_audio_driver = do_we_have_audio();
        sdp_info = set_sdp_decode_from_memory(http_resp->body);
        ret = create_from_sdp(psptr,
                              name,
                              errmsg,
                              errlen,
                              sdp_info,
                              have_audio_driver,
                              cc_vft);
    } else {
        ret = -1;
        snprintf(errmsg, errlen, "HTTP error %d, %s", http_resp->ret_code,
                 http_resp->resp_phrase);
    }
    http_resp_free(http_resp);
    http_free_connection(http_client);

    return (ret);
}
Exemplo n.º 7
0
td_t 
tsplit(spdid_t spdid, td_t tid, char *param, int len, 
       tor_flags_t tflags, long evtid)
{
	td_t ret = -1;
	struct torrent *t;
	struct connection *c;

	if (tor_isnull(tid)) return -EINVAL;
	
	LOCK();
	c = http_new_connection(0, evtid);
	if (!c) ERR_THROW(-ENOMEM, err);
	/* ignore the param for now */
	t = tor_alloc(c, tflags);
	if (!t) ERR_THROW(-ENOMEM, free);
	c->conn_id = ret = t->td;
err:
	UNLOCK();
	return ret;
free:
	http_free_connection(c);
	goto err;
}
Exemplo n.º 8
0
int check_name_for_network (const char *name,
                            int &isOnDemand,
                            int &isRtpOverRtsp)
{
    sdp_decode_info_t *sdp_info;
    session_desc_t *sdp;
    int translated;
    http_resp_t *http_resp;
    int do_sdp = 0;

    http_resp = NULL;
    isOnDemand = 0;
    isRtpOverRtsp = 0;
    sdp_info = NULL;
    if (strncmp(name, "mpeg2t://", strlen("mpeg2t://")) == 0) {
        return 1;
    }
    if (strncmp(name, "iptv://", strlen("iptv://")) == 0) {
        // more later to handle the on demand/streaming case
        return 1;
    }
    if (strncmp(name, "rtsp://", strlen("rtsp://")) == 0) {
        isOnDemand = 1;
        isRtpOverRtsp = config.get_config_value(CONFIG_USE_RTP_OVER_RTSP);
        return 1;
    }
    // handle http, .sdp case
    if (strncmp(name, "http://", strlen("http://")) == 0) {
        http_client_t *http_client;
        int ret;
        http_client = http_init_connection(name);

        if (http_client == NULL) {
            return -1;
        }
        ret = http_get(http_client, NULL, &http_resp);
        if (ret > 0) {
            sdp_decode_info_t *sdp_info;
            sdp_info = set_sdp_decode_from_memory(http_resp->body);
            do_sdp = 1;
            http_free_connection(http_client);
        } else return -1;
        do_sdp = 1;
    } else {
        const char *suffix = strrchr(name, '.');
        if (suffix == NULL) {
            return -1;
        }
        if (strcasecmp(suffix, ".sdp") == 0) {
            sdp_info = set_sdp_decode_from_filename(name);
            do_sdp = 1;
        } else
            return 0;
    }
    if (do_sdp != 0) {
        if ((sdp_decode(sdp_info, &sdp, &translated) != 0) ||
                translated != 1) {
            sdp_decode_info_free(sdp_info);
            return (-1);
        }
        if (sdp->control_string != NULL) {
            isOnDemand = 1;
            isRtpOverRtsp = config.get_config_value(CONFIG_USE_RTP_OVER_RTSP);
        }
        sdp_free_session_desc(sdp);
        if (http_resp != NULL)
            http_resp_free(http_resp);
        sdp_decode_info_free(sdp_info);
        return 1;
    }
    return 0;
}