예제 #1
0
static int owncloud_commit() {

  clean_caches();

  if( dav_session.ctx )
    ne_session_destroy( dav_session.ctx );
  /* DEBUG_WEBDAV( "********** vio_module_shutdown" ); */

  dav_session.ctx = 0;

  // ne_sock_exit();
  _connected = 0;  /* triggers dav_connect to go through the whole neon setup */

  SAFE_FREE( dav_session.user );
  SAFE_FREE( dav_session.pwd );
  SAFE_FREE( dav_session.session_key);
  SAFE_FREE( dav_session.error_string );

  SAFE_FREE( dav_session.proxy_type );
  SAFE_FREE( dav_session.proxy_host );
  SAFE_FREE( dav_session.proxy_user );
  SAFE_FREE( dav_session.proxy_pwd  );

  return 0;
}
static void
gst_neonhttp_src_dispose (GObject * gobject)
{
    GstNeonhttpSrc *src = GST_NEONHTTP_SRC (gobject);

    ne_uri_free (&src->uri);
    ne_uri_free (&src->proxy);

    g_free (src->user_agent);

    if (src->cookies) {
        g_strfreev (src->cookies);
        src->cookies = NULL;
    }

    if (src->request) {
        ne_request_destroy (src->request);
        src->request = NULL;
    }

    if (src->session) {
        ne_close_connection (src->session);
        ne_session_destroy (src->session);
        src->session = NULL;
    }

    if (src->location) {
        ne_free (src->location);
    }
    if (src->query_string) {
        ne_free (src->query_string);
    }

    G_OBJECT_CLASS (parent_class)->dispose (gobject);
}
예제 #3
0
파일: common.c 프로젝트: tolsen/Prestan
int finish(void)
{
    ne_delete(i_session, i_path);
    ne_session_destroy(i_session);
    printf("\n\n");
    return OK;
}
예제 #4
0
void rawx_client_free_session( rawx_session_t *session )
{
	if (!session)
		return;
	ne_session_destroy( session->neon_session );
	memset( session, 0x00, sizeof(rawx_session_t) );
	g_free( session );
}
예제 #5
0
void vio_module_shutdown(csync_vio_method_t *method) {
    (void) method;

    SAFE_FREE( dav_session.user );
    SAFE_FREE( dav_session.pwd );

    if( dav_session.ctx )
        ne_session_destroy( dav_session.ctx );
}
예제 #6
0
파일: cadaver.c 프로젝트: grimneko/cadaver
void close_connection(void)
{
    ne_session_destroy(session.sess);
    session.connected = 0;
    printf(_("Connection to `%s' closed.\n"),
           session.uri.host);
    ne_uri_free(&session.uri);
    if (session.lastwp)
        ne_free(session.lastwp);
}
예제 #7
0
파일: libs3.c 프로젝트: soundsrc/s3nbd
void s3_end_session(S3 *s3)
{
	if(s3 && s3->session) {
		s3->session_count--;
		if(s3->session_count == 0) {
			ne_session_destroy(s3->session);
			s3->session = NULL;
		}
	}
}
static void
gst_neonhttp_src_close_session (GstNeonhttpSrc * src)
{
    if (src->request) {
        ne_request_destroy (src->request);
        src->request = NULL;
    }

    if (src->session) {
        ne_close_connection (src->session);
        ne_session_destroy (src->session);
        src->session = NULL;
    }
}
예제 #9
0
/* could implement failure on self-referential redirects, but
 * realistically, the application must implement a max-redirs count
 * check, so it's kind of redundant.  Mozilla takes this approach. */
static int fail_loop(void)
{
    ne_session *sess;

    CALL(make_session(&sess, serve_redir, "http://localhost:7777/foo/bar"));

    ne_redirect_register(sess);

    ONN("followed looping redirect",
	any_request(sess, "/foo/bar") != NE_ERROR);

    ne_session_destroy(sess);
    return OK;
}
예제 #10
0
static int test_acl(const char *uri, ne_acl_entry *es, int nume)
{
    ne_session *sess;

    CALL(make_session(&sess, single_serve_string,
		      "HTTP/1.1 200 OK\r\n"
		      "Connection: close\r\n\r\n"));

    ON(ne_acl_set(sess, uri, es, nume));

    CALL(await_server());
    ne_session_destroy(sess);

    return OK;
}
예제 #11
0
int neon_vfs_fclose_impl (VFSFile * file)
{
    struct neon_handle * h = vfs_get_handle (file);

    if (h->reader_status.reading)
        kill_reader (h);

    if (h->request)
        ne_request_destroy (h->request);
    if (h->session)
        ne_session_destroy (h->session);

    handle_free (h);

    return 0;
}
예제 #12
0
파일: netxml-ups.c 프로젝트: balooloo/nut
void upsdrv_cleanup(void)
{
	free(subdriver->configure);
	free(subdriver->subscribe);
	free(subdriver->summary);
	free(subdriver->getobject);
	free(subdriver->setobject);

	if (sock) {
		ne_sock_close(sock);
	}

	if (session) {
		ne_session_destroy(session);
	}

	ne_uri_free(&uri);
}
예제 #13
0
파일: rawx.c 프로젝트: amogrid/redcurrant
static gboolean _ne_request(const char *host, int port, const char *target,
		const char *method, GSList *headers, GError **err)
{
	GRID_TRACE("%s", __FUNCTION__);
	gboolean result = FALSE;
	ne_session* session = ne_session_create("http", host, port);
	ne_set_connect_timeout(session, 10);
	ne_set_read_timeout(session, 30);

	GRID_DEBUG("%s http://%s:%d%s", method, host, port, target);
	ne_request* req = ne_request_create(session, method, target);
	if (NULL != req) {
		for (GSList *l = headers; l; l = l->next) {
			gchar **toks = g_strsplit(l->data, ":", 2);
			ne_add_request_header(req, toks[0], toks[1]);
			g_strfreev(toks);
		}
		switch (ne_request_dispatch(req)) {
			case NE_OK:
				if (ne_get_status(req)->klass != 2) {
					*err = NEWERROR(0, "cannot %s '%s' (%s)", method, target,
							ne_get_error(session));
				} else {
					result = TRUE;
				}
				break;
			case NE_AUTH:
			case NE_CONNECT:
			case NE_TIMEOUT:
			case NE_ERROR:
			default:
				*err = NEWERROR(0,
						"unexpected error from the WebDAV server (%s)",
						ne_get_error(session));
				break;
		}
		ne_request_destroy(req);
	} else {
		// This should be an assertion
		*err = NEWERROR(0, "Failed to create request");
	}
	ne_session_destroy (session);
	return result;
}
예제 #14
0
/* sends a small segment of the file from a high offset. */
static int send_high_offset(void)
{
    int ret, fd = open64(SPARSE, O_RDONLY);
    ne_session *sess;
    ne_request *req;

    ONN("could not open sparse file", fd < 0);

    CALL(make_session(&sess, serve_check_body, NULL));
    
    req = ne_request_create(sess, "PUT", "/sparse");
    ne_set_request_body_fd64(req, fd, point, strlen(data));
    ret = ne_request_dispatch(req);
    CALL(await_server());
    ONV(ret != NE_OK || ne_get_status(req)->klass != 2,
        ("request failed: %s", ne_get_error(sess)));
    ne_request_destroy(req);
    ne_session_destroy(sess);
    close(fd);
    return OK;
}
예제 #15
0
static int check_redir(struct redir_args *args, const char *expect)
{
    ne_session *sess;
    const ne_uri *loc;
    char *unp;

    CALL(make_session(&sess, serve_redir, args));
    ne_redirect_register(sess);

    CALL(process_redir(sess, args->path, &loc));
    ONN("redirect location was NULL", loc == NULL);

    unp = ne_uri_unparse(loc);
    ONV(strcmp(unp, expect), ("redirected to `%s' not `%s'", unp, expect));
    ne_free(unp);

    ne_session_destroy(sess);
    CALL(await_server());

    return OK;
}
예제 #16
0
static int read_large_response(void)
{
    ne_session *sess;
    ne_request *req;
    off64_t count = 0;
    int ret;
    char buf[8192];

    CALL(make_session(&sess, serve_large_response, NULL));

    req = ne_request_create(sess, "GET", "/foo");

#ifdef NE_DEBUGGING
    ne_debug_init(ne_debug_stream, ne_debug_mask & ~(NE_DBG_HTTPBODY|NE_DBG_HTTP));
#endif
    
    ret = ne_begin_request(req);
    if (ret == NE_OK) {
        while ((ret = ne_read_response_block(req, buf, sizeof buf)) > 0)
            count += ret;
        if (ret == NE_OK)
            ret = ne_end_request(req);
    }

#ifdef NE_DEBUGGING
    ne_debug_init(ne_debug_stream, ne_debug_mask & (NE_DBG_HTTPBODY|NE_DBG_HTTP));
#endif
        
    ONV(ret, ("request failed: %s", ne_get_error(sess)));
    ONV(count != RESPSIZE, 
        ("response body was %" NE_FMT_OFF64_T " not %" NE_FMT_OFF64_T,
         count, RESPSIZE));

    ne_request_destroy(req);

    CALL(any_2xx_request(sess, "/bar"));
    CALL(await_server());
    ne_session_destroy(sess);
    return OK;
}
예제 #17
0
static char *
_check_chunk(const char *cid)
{
	ne_session *session=NULL;
	ne_request *request=NULL;

	GString *str = g_string_new("");

	char **split = g_strsplit(cid, "/", 0);
	char **addr_tok = g_strsplit(split[2], ":", 2);

	if(NULL != (session = ne_session_create("http", addr_tok[0], atoi(addr_tok[1])))) {
		ne_set_connect_timeout(session, 10);
		ne_set_read_timeout(session, 30);
		/* FIXME: I'm a little harder with strrchr success presumption */
		if(NULL != (request = ne_request_create (session, "HEAD", strrchr(cid, '/')))) {
			switch (ne_request_dispatch (request)) {
				case NE_OK:
					if (ne_get_status(request)->klass != 2) {
						g_string_append_printf(str, "(Chunk unavailable : %s)",
								ne_get_error(session));
					}
					break;
				default:
					g_string_append_printf(str, "(Chunk unavailable : %s)",
							ne_get_error(session));
			}
			ne_request_destroy (request);
		} 
		ne_session_destroy (session);
	}

	g_strfreev(addr_tok);
	g_strfreev(split);

	return g_string_free(str, FALSE);
}
예제 #18
0
/* ensure that ne_redirect_location returns NULL when no redirect has
 * been encountered, or redirect hooks aren't registered. */
static int no_redirect(void)
{
    ne_session *sess = ne_session_create("http", "localhost", 7777);
    const ne_uri *loc;

    ONN("redirect non-NULL before register", ne_redirect_location(sess));
    ne_redirect_register(sess);
    ONN("initial redirect non-NULL", ne_redirect_location(sess));

    CALL(spawn_server(7777, single_serve_string,
                      "HTTP/1.0 200 OK\r\n\r\n\r\n"));
    ONREQ(any_request(sess, "/noredir"));
    CALL(await_server());

    ONN("redirect non-NULL after non-redir req", ne_redirect_location(sess));

    CALL(spawn_server(7777, single_serve_string, "HTTP/1.0 302 Get Ye Away\r\n"
                      "Location: /blah\r\n" "\r\n"));
    CALL(process_redir(sess, "/foo", &loc));
    CALL(await_server());

    ne_session_destroy(sess);
    return OK;
}
예제 #19
0
파일: rawx.c 프로젝트: amogrid/redcurrant
gs_status_t rawx_delete (gs_chunk_t *chunk, GError **err)
{
	char str_req_id [1024];
	char str_addr [STRLEN_ADDRINFO];
	char str_ci [STRLEN_CHUNKID];
	char cPath [CI_FULLPATHLEN];
	char str_hash[STRLEN_CHUNKHASH];

	ne_request *request=NULL;
	ne_session *session=NULL;
	
	memset(str_req_id, 0x00, sizeof(str_req_id));

	if (!chunk || !chunk->ci || !chunk->content)
	{
		GSETERROR (err,"Invalid parameter (bad chunk structure)");
		goto error_label;
	}

	addr_info_to_string (&(chunk->ci->id.addr), str_addr, sizeof(str_addr));
	chunk_id2str(chunk, str_ci, sizeof(str_ci));
	chunk_getpath (chunk, cPath, sizeof(cPath));
	DEBUG("about to delete %s on %s", str_ci, cPath);

	gscstat_tags_start(GSCSTAT_SERVICE_RAWX, GSCSTAT_TAGS_REQPROCTIME);

	session = rawx_opensession (chunk, err);
	if (!session)
	{
		GSETERROR (err, "Cannot open a webdav session");
		goto error_label;
	}

	/*Create a webdav request*/
	do {
		request = ne_request_create (session, RAWX_DELETE, cPath);
		if (!request)
		{
			GSETERROR (err, "cannot create a %s WebDAV request", RAWX_DELETE);
			goto error_label;
		}

	} while (0);

	chunk_id2str (chunk, str_ci, sizeof(str_ci));
	chunk_gethash (chunk, str_hash, sizeof(str_hash));

	/* Add request header */
	add_req_id_header(request, str_req_id, sizeof(str_req_id)-1);


	ne_add_request_header  (request, "chunkid",     str_ci);
	ne_add_request_header  (request, "chunkhash",   str_hash);
	ne_add_request_header  (request, "containerid", C1_IDSTR(chunk->content));
	ne_add_request_header  (request, "contentpath", chunk->content->info.path);
	ne_print_request_header(request, "chunkpos",    "%"G_GUINT32_FORMAT, chunk->ci->position);
	ne_print_request_header(request, "chunknb",     "%"G_GUINT32_FORMAT, chunk->ci->nb);
	ne_print_request_header(request, "chunksize",   "%"G_GINT64_FORMAT, chunk->ci->size);
	ne_print_request_header(request, "contentsize", "%"G_GINT64_FORMAT, chunk->content->info.size);

	/*now perform the request*/
	switch (ne_request_dispatch (request))
	{
		case NE_OK:
			if (ne_get_status(request)->klass != 2) {
				GSETERROR (err, "cannot delete '%s' (%s) (ReqId:%s)", cPath, ne_get_error(session), str_req_id);
				goto error_label;
			}
			DEBUG("chunk deletion finished (success) : %s", cPath);
			break;
		case NE_AUTH:
		case NE_CONNECT:
		case NE_TIMEOUT:
		case NE_ERROR:
			GSETERROR (err, "unexpected error from the WebDAV server (%s) (ReqId:%s)", ne_get_error(session), str_req_id);
			goto error_label;
	}

	ne_request_destroy (request);
	ne_session_destroy (session);
	
	TRACE("%s deleted (ReqId:%s)", cPath, str_req_id);

	gscstat_tags_end(GSCSTAT_SERVICE_RAWX, GSCSTAT_TAGS_REQPROCTIME);

	return 1;
error_label:
	TRACE("could not delete %s", cPath);
	if (request)
		ne_request_destroy (request);
	if (session)
		ne_session_destroy (session);

	gscstat_tags_end(GSCSTAT_SERVICE_RAWX, GSCSTAT_TAGS_REQPROCTIME);

	return 0;
}
예제 #20
0
int dav_startsessx(char *server, char *comment, int enable_ssl)
{
	FILE *p12 = NULL;
	const char *p12cert = "/tmp/usercert.p12";
	const char *userkey, *usercert, *userproxy;
  char buffer[128];

	/* Function to be executed once per thread, used to create the connection structure and set the server name */
	if(mutex == 0)
	{
		/* If no host specified, use the DPNS default one */
		if (!server)
			server = getenv("DPNS_HOST");

		/* Finish the function if the host is still NULL*/
		if (!server)
		{
			dav_error = SENOSHOST;
			return -1;
		}

		/* Trigger an error if the comment is too long */
		if(comment && (strlen(comment) > CA_MAXCOMMENTLEN))
		{
			dav_error = EINVAL;
			return -1;
		}

		pthread_once(&init_once, thread_init_once);

		connection = (struct dav_connection *)calloc(sizeof(struct dav_connection), 1);
		strcpy(connection->server, server);
		mutex = 1;
	}

	/* exit function if a session already exists */
	if(connection->session)
		return 0;	

	/* Retrieve userkey and usercert from environement variable */
	userkey   = getenv("X509_USER_KEY");
	usercert  = getenv("X509_USER_CERT");
  userproxy = getenv("X509_USER_PROXY");
  
  /* Use a proxy */
  if (enable_ssl) {
    if (userproxy) {
      userkey = usercert = userproxy;
    }
    /* Try default proxy location */
    else if (!userkey && !usercert) {
      struct stat stat_buf;

      snprintf(buffer, sizeof(buffer), "/tmp/x509up_u%d", getuid());
      /* No luck, try with host cert and key */
      if (stat(buffer, &stat_buf) != 0) {
        usercert = "/etc/grid-security/hostcert.pem";
        userkey  = "/etc/grid-security/hostkey.pem";
      }
    }

    debug_msg("User certificate: %s", usercert);
    debug_msg("User key:         %s", userkey);

    /* Try to open the certificate, create one if file does not exist yet */
    if ((p12 = fopen(p12cert, "r")) == NULL){
      if(convert_x509_to_p12(userkey, usercert, p12cert) == -1){
        fprintf(stderr, "An error occur in the certificate conversion\n");
        return -1;
      }
    }else {
      fclose(p12);
    }

    /* Try to open a session, return -1 and set the correct errno if it failed */
    if ((connection->session = ne_session_create("https", server, 443)) == NULL)
    {
      dav_error = ENSNACT;
      return -1;
    }
  }
  else {
    if ((connection->session = ne_session_create("http", server, 80)) == NULL)
    {
      dav_error = ENSNACT;
      return -1;
    }
  }

	/* manual checking for ssl credentials */
	ne_ssl_set_verify(connection->session, no_ssl_verification, NULL);

	/* Read the pkcs12 certificate */
  if (enable_ssl) {
    ne_ssl_client_cert *cert = ne_ssl_clicert_read(p12cert);
        if (cert == NULL) {
      ne_session_destroy(connection->session);
      dav_error = SECOMERR;
      return -1;
    }
    ne_ssl_set_clicert(connection->session, cert);
    ne_ssl_clicert_free(cert);
  }
	
	return 0;
}
예제 #21
0
int
main_http_config(const gchar *hn, int fd)
{
	int rc;
	GError *error = NULL;
	GByteArray *gba_services = NULL;
	GByteArray *gba_files = NULL;
	ne_session *http_session;

	set_sighandlers();
	fd_out = fd;

	DEBUG("Starting a new configuration process");
	rc = -1;

	bzero(hostname, sizeof(hostname));
	if (!hn)
		gethostname(hostname,sizeof(hostname));
	else
		g_strlcpy(hostname, hn, sizeof(hostname)-1);

	http_session = ne_session_create("http", gridconf_host, gridconf_port);
	ne_set_connect_timeout(http_session, 1);
	ne_set_read_timeout(http_session, 4);

	/*downlaod each file*/
	if (!is_running)
		goto label_error;

	gba_files = download_file_list(http_session, &error);
	if (!gba_files) {
		ERROR("Failed to get the files list file : %s", gerror_get_message(error));
		goto label_error;
	}
	
	if (!is_running)
		goto label_error;
	
	gba_services = download_file_services(http_session, &error);
	if (!gba_services) {
		ERROR("Failed to get the services definition file : %s", gerror_get_message(error));
		goto label_error;
	}
	
	if (!is_running)
		goto label_error;
	
	if (!download_each_configuration_file(http_session, gba_files, &error)) {
		ERROR("Failed to download a configuration file : %s", gerror_get_message(error));
		goto label_error;
	}

	if (!is_running)
		goto label_error;

	if (!dump_gba(gba_services, fd_out, &error)) {
		ERROR("Failed to dump the configuration to fd=%d : %s", fd_out, gerror_get_message(error));
		goto label_error;
	}

	rc = 0;
label_error:
	ne_session_destroy(http_session);
	metautils_pclose(&fd_out);
	if (gba_services)
		g_byte_array_free(gba_services, TRUE);
	if (gba_files)
		g_byte_array_free(gba_files, TRUE);
	DEBUG("http_config child pid=%d exiting with rc=%d", getpid(), rc);
	return rc;
}
예제 #22
0
static int open_handle (struct neon_handle * handle, uint64_t startbyte)
{
    int ret;
    char * proxy_host = NULL;
    int proxy_port = 0;

    bool_t use_proxy = aud_get_bool (NULL, "use_proxy");
    bool_t use_proxy_auth = aud_get_bool (NULL, "use_proxy_auth");

    if (use_proxy)
    {
        proxy_host = aud_get_str (NULL, "proxy_host");
        proxy_port = aud_get_int (NULL, "proxy_port");
    }

    handle->redircount = 0;

    _DEBUG ("<%p> Parsing URL", handle);

    if (ne_uri_parse (handle->url, handle->purl) != 0)
    {
        _ERROR ("<%p> Could not parse URL '%s'", (void *) handle, handle->url);
        return -1;
    }

    while (handle->redircount < 10)
    {
        if (! handle->purl->port)
            handle->purl->port = ne_uri_defaultport (handle->purl->scheme);

        _DEBUG ("<%p> Creating session to %s://%s:%d", handle,
         handle->purl->scheme, handle->purl->host, handle->purl->port);
        handle->session = ne_session_create (handle->purl->scheme,
         handle->purl->host, handle->purl->port);
        ne_redirect_register (handle->session);
        ne_add_server_auth (handle->session, NE_AUTH_BASIC, server_auth_callback, (void *) handle);
        ne_set_session_flag (handle->session, NE_SESSFLAG_ICYPROTO, 1);
        ne_set_session_flag (handle->session, NE_SESSFLAG_PERSIST, 0);

#ifdef HAVE_NE_SET_CONNECT_TIMEOUT
        ne_set_connect_timeout (handle->session, 10);
#endif

        ne_set_read_timeout (handle->session, 10);
        ne_set_useragent (handle->session, "Audacious/" PACKAGE_VERSION);

        if (use_proxy)
        {
            _DEBUG ("<%p> Using proxy: %s:%d", handle, proxy_host, proxy_port);
            ne_session_proxy (handle->session, proxy_host, proxy_port);

            if (use_proxy_auth)
            {
                _DEBUG ("<%p> Using proxy authentication", handle);
                ne_add_proxy_auth (handle->session, NE_AUTH_BASIC,
                 neon_proxy_auth_cb, (void *) handle);
            }
        }

        if (! strcmp ("https", handle->purl->scheme))
        {
            ne_ssl_trust_default_ca (handle->session);
            ne_ssl_set_verify (handle->session,
             neon_vfs_verify_environment_ssl_certs, handle->session);
        }

        _DEBUG ("<%p> Creating request", handle);
        ret = open_request (handle, startbyte);

        if (! ret)
        {
            str_unref (proxy_host);
            return 0;
        }

        if (ret == -1)
        {
            ne_session_destroy (handle->session);
            handle->session = NULL;
            str_unref (proxy_host);
            return -1;
        }

        _DEBUG ("<%p> Following redirect...", handle);
        ne_session_destroy (handle->session);
        handle->session = NULL;
    }

    /* If we get here, our redirect count exceeded */
    _ERROR ("<%p> Redirect count exceeded for URL %s", (void *) handle, handle->url);

    str_unref (proxy_host);
    return 1;
}
/* Try to send the HTTP request to the Icecast server, and if possible deals with
 * all the probable redirections (HTTP status code == 3xx)
 */
static gint
gst_neonhttp_src_send_request_and_redirect (GstNeonhttpSrc * src,
        ne_session ** ses, ne_request ** req, gint64 offset, gboolean do_redir)
{
    ne_session *session = NULL;
    ne_request *request = NULL;
    gchar **c;
    gint res;
    gint http_status = 0;
    guint request_count = 0;

    do {
        if (src->proxy.host && src->proxy.port) {
            session =
                ne_session_create (src->uri.scheme, src->uri.host, src->uri.port);
            ne_session_proxy (session, src->proxy.host, src->proxy.port);
        } else if (src->proxy.host || src->proxy.port) {
            /* both proxy host and port must be specified or none */
            return HTTP_REQUEST_WRONG_PROXY;
        } else {
            session =
                ne_session_create (src->uri.scheme, src->uri.host, src->uri.port);
        }

        if (src->connect_timeout > 0) {
            ne_set_connect_timeout (session, src->connect_timeout);
        }

        if (src->read_timeout > 0) {
            ne_set_read_timeout (session, src->read_timeout);
        }

        ne_set_session_flag (session, NE_SESSFLAG_ICYPROTO, 1);
        ne_ssl_set_verify (session, ssl_verify_callback, src);

        request = ne_request_create (session, "GET", src->query_string);

        if (src->user_agent) {
            ne_add_request_header (request, "User-Agent", src->user_agent);
        }

        for (c = src->cookies; c != NULL && *c != NULL; ++c) {
            GST_INFO ("Adding header Cookie : %s", *c);
            ne_add_request_header (request, "Cookies", *c);
        }

        if (src->iradio_mode)
            ne_add_request_header (request, "icy-metadata", "1");

        if (offset > 0) {
            ne_print_request_header (request, "Range",
                                     "bytes=%" G_GINT64_FORMAT "-", offset);
        }

        res = ne_begin_request (request);

        if (res == NE_OK) {
            /* When the HTTP status code is 3xx, it is not the SHOUTcast streaming content yet;
             * Reload the HTTP request with a new URI value */
            http_status = ne_get_status (request)->code;
            if (STATUS_IS_REDIRECTION (http_status) && do_redir) {
                const gchar *redir;

                /* the new URI value to go when redirecting can be found on the 'Location' HTTP header */
                redir = ne_get_response_header (request, "Location");
                if (redir != NULL) {
                    ne_uri_free (&src->uri);
                    gst_neonhttp_src_set_location (src, redir, NULL);
                    GST_LOG_OBJECT (src, "Got HTTP Status Code %d", http_status);
                    GST_LOG_OBJECT (src, "Using 'Location' header [%s]", src->uri.host);
                }
            }
        }

        if ((res != NE_OK) ||
                (offset == 0 && http_status != 200) ||
                (offset > 0 && http_status != 206 &&
                 !STATUS_IS_REDIRECTION (http_status))) {
            ne_request_destroy (request);
            request = NULL;
            ne_close_connection (session);
            ne_session_destroy (session);
            session = NULL;
            if (offset > 0 && http_status != 206 &&
                    !STATUS_IS_REDIRECTION (http_status)) {
                src->seekable = FALSE;
            }
        }

        /* if - NE_OK */
        if (STATUS_IS_REDIRECTION (http_status) && do_redir) {
            ++request_count;
            GST_LOG_OBJECT (src, "redirect request_count is now %d", request_count);
            if (request_count < MAX_HTTP_REDIRECTS_NUMBER && do_redir) {
                GST_INFO_OBJECT (src, "Redirecting to %s", src->uri.host);
            } else {
                GST_WARNING_OBJECT (src, "Will not redirect, try again with a "
                                    "different URI or redirect location %s", src->uri.host);
            }
            /* FIXME: when not redirecting automatically, shouldn't we post a
             * redirect element message on the bus? */
        }
        /* do the redirect, go back to send another HTTP request now using the 'Location' */
    } while (do_redir && (request_count < MAX_HTTP_REDIRECTS_NUMBER)
             && STATUS_IS_REDIRECTION (http_status));

    if (session) {
        *ses = session;
        *req = request;
    }

    return res;
}
예제 #24
0
파일: rawx.c 프로젝트: amogrid/redcurrant
static gboolean
_rawx_update_chunk_attrs(chunk_id_t *cid, GSList *attrs, GError **err)
{
	ne_session *s = NULL;
	ne_request *r = NULL;
	int ne_rc;
	gboolean result = FALSE;

	gchar dst[128];
	guint16 port = 0;
	GString *req_str = NULL;
	char idstr[65];

	if (!addr_info_get_addr(&(cid->addr), dst, sizeof(dst), &port))
		return result;

	s = ne_session_create("http", dst, port);
	if (!s) {
		GSETERROR(err, "Failed to create session to rawx %s:%d", dst, port);
		return result;
	}

	ne_set_connect_timeout(s, 10);
	ne_set_read_timeout(s, 30);

	req_str =g_string_new("/rawx/chunk/set/");
	bzero(idstr, sizeof(idstr));
	buffer2str(&(cid->id), sizeof(cid->id), idstr, sizeof(idstr));
	req_str = g_string_append(req_str, idstr);
	GRID_TRACE("Calling %s", req_str->str);

	r = ne_request_create (s, "GET", req_str->str);
	if (!r) {
		goto end_attr;
	}

	for (; attrs != NULL; attrs = attrs->next) {
		struct chunk_attr_s *attr = attrs->data;
		ne_add_request_header(r, attr->key, attr->val);
	}

	switch (ne_rc = ne_request_dispatch(r)) {
		case NE_OK:
			result = TRUE;
			break;
		case NE_ERROR:
			GSETCODE(err, 500, "Request NE_ERROR");
			break;
		case NE_TIMEOUT:
			GSETCODE(err, 500, "Request Timeout");
			break;
		case NE_CONNECT:
			GSETCODE(err, 500, "Request Connection timeout");
			break;
		default:
			GSETCODE(err, 500, "Request failed");
			break;
	}

end_attr:
	if (NULL != req_str)
		g_string_free(req_str, TRUE);
	if (NULL != r)
		ne_request_destroy (r);
	if (NULL != s)
		ne_session_destroy (s);

	return result;
}
예제 #25
0
파일: session.c 프로젝트: AndyA/FuseDAV
static void session_destroy(void *s) {
    ne_session *session = s;
    assert(s);
    ne_session_destroy(session);
}