int main(int argc, char *argv[]) { int ret = 0; char *home = getenv("HOME"), *tmp; progname = argv[0]; #ifdef HAVE_SETLOCALE setlocale(LC_ALL, ""); #endif #ifdef ENABLE_NLS bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); #endif /* ENABLE_NLS */ ne_debug_init(stderr, 0); if (!home) { /* Show me the way to go home... */ printf(_("Environment variable $HOME needs to be set!\n")); return -1; } ne_sock_init(); memset(&session, 0, sizeof session); /* Options before rcfile, so rcfile settings can * override defaults */ tmp = ne_concat(home, "/.cadaver-locks", NULL); set_option(opt_lockstore, tmp); init_options(); init_netrc(); init_signals(); init_locking(); parse_args(argc, argv); ret = init_rcfile(); init_readline(); while (ret == 0) { char *cmd; cmd = read_command(); if (cmd == NULL) { /* Is it safe to do this... they just closed stdin, so * is it bad to write to stdout? */ putchar('\n'); ret = 1; } else { #ifdef HAVE_ADD_HISTORY if (strcmp(cmd, "") != 0) add_history(cmd); #endif ret = execute_command(cmd); free(cmd); } } if (session.connected) { close_connection(); } finish_locking(); ne_sock_exit(); return 0; }
void upsdrv_initups(void) { int ret; char *val; FILE *fp; #if HAVE_NE_SET_CONNECT_TIMEOUT && HAVE_NE_SOCK_CONNECT_TIMEOUT /* we don't need to use alarm() */ #else struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = netxml_alarm_handler; sigaction(SIGALRM, &sa, NULL); #endif /* allow override of default network timeout value */ val = getval("timeout"); if (val) { timeout = atoi(val); if (timeout < 1) { fatalx(EXIT_FAILURE, "timeout must be greater than 0"); } } val = getval("shutdown_duration"); if (val) { shutdown_duration = atoi(val); if (shutdown_duration < 0) { fatalx(EXIT_FAILURE, "shutdown duration must be greater than or equal to 0"); } } val = getval("shutdown_timer"); if (val) { shutdown_timer = atoi(val); if (shutdown_timer < 0) { fatalx(EXIT_FAILURE, "shutdown timer must be greater than or equal to 0"); } } if (nut_debug_level > 5) { ne_debug_init(stderr, NE_DBG_HTTP | NE_DBG_HTTPBODY); } if (ne_sock_init()) { fatalx(EXIT_FAILURE, "%s: failed to initialize socket libraries", progname); } if (ne_uri_parse(device_path, &uri) || uri.host == NULL) { fatalx(EXIT_FAILURE, "%s: invalid hostname '%s'", progname, device_path); } /* if (uri.scheme == NULL) { uri.scheme = strdup("http"); } if (uri.host == NULL) { uri.host = strdup(device_path); } */ if (uri.port == 0) { uri.port = ne_uri_defaultport(uri.scheme); } upsdebugx(1, "using %s://%s port %d", uri.scheme, uri.host, uri.port); session = ne_session_create(uri.scheme, uri.host, uri.port); /* timeout if we can't (re)connect to the UPS */ #ifdef HAVE_NE_SET_CONNECT_TIMEOUT ne_set_connect_timeout(session, timeout); #endif /* just wait for a couple of seconds */ ne_set_read_timeout(session, timeout); ne_set_useragent(session, subdriver->version); if (strcasecmp(uri.scheme, "https") == 0) { ne_ssl_trust_default_ca(session); } ne_set_server_auth(session, netxml_authenticate, NULL); /* if debug level is set, direct output to stderr */ if (!nut_debug_level) { fp = fopen("/dev/null", "w"); } else { fp = stderr; } if (!fp) { fatal_with_errno(EXIT_FAILURE, "Connectivity test failed"); } /* see if we have a connection */ ret = ne_get(session, subdriver->initups, fileno(fp)); if (!nut_debug_level) { fclose(fp); } else { fprintf(fp, "\n"); } if (ret != NE_OK) { fatalx(EXIT_FAILURE, "Connectivity test: %s", ne_get_error(session)); } upslogx(LOG_INFO, "Connectivity test: %s", ne_get_error(session)); }
int main(int argc, char *argv[]) { int n; static const char dots[] = "......................"; /* get basename(argv[0]) */ test_suite = strrchr(argv[0], '/'); if (test_suite == NULL) { test_suite = argv[0]; } else { test_suite++; } #ifdef HAVE_SETLOCALE setlocale(LC_MESSAGES, ""); #endif ne_i18n_init(NULL); #if defined(HAVE_ISATTY) && defined(STDOUT_FILENO) if (isatty(STDOUT_FILENO)) { use_colour = 1; } #endif test_argc = argc; test_argv = argv; debug = fopen("debug.log", "a"); if (debug == NULL) { fprintf(stderr, "%s: Could not open debug.log: %s\n", test_suite, strerror(errno)); return -1; } child_debug = fopen("child.log", "a"); if (child_debug == NULL) { fprintf(stderr, "%s: Could not open child.log: %s\n", test_suite, strerror(errno)); fclose(debug); return -1; } if (tests[0].fn == NULL) { printf("-> no tests found in `%s'\n", test_suite); return -1; } /* install special SEGV handler. */ signal(SIGSEGV, parent_segv); signal(SIGABRT, parent_segv); /* test the "no-debugging" mode of ne_debug. */ ne_debug_init(NULL, 0); NE_DEBUG(TEST_DEBUG, "This message should go to /dev/null"); /* enable debugging for real. */ ne_debug_init(debug, TEST_DEBUG); NE_DEBUG(TEST_DEBUG | NE_DBG_FLUSH, "Version string: %s\n", ne_version_string()); /* another silly test. */ NE_DEBUG(0, "This message should also go to /dev/null"); if (ne_sock_init()) { COL("43;01"); printf("WARNING:"); NOCOL; printf(" Socket library initalization failed.\n"); } printf("-> running `%s':\n", test_suite); for (n = 0; !aborted && tests[n].fn != NULL; n++) { int result, is_xfail = 0; #ifdef NEON_MEMLEAK size_t allocated = ne_alloc_used; int is_xleaky = 0; #endif test_name = tests[n].name; printf("%2d. %s%.*s ", n, test_name, (int) (strlen(dots) - strlen(test_name)), dots); have_context = 0; test_num = n; warned = 0; fflush(stdout); NE_DEBUG(TEST_DEBUG, "******* Running test %d: %s ********\n", n, test_name); /* run the test. */ result = tests[n].fn(); #ifdef NEON_MEMLEAK /* issue warnings for memory leaks, if requested */ if ((tests[n].flags & T_CHECK_LEAKS) && result == OK && ne_alloc_used > allocated) { t_context("memory leak of %" NE_FMT_SIZE_T " bytes", ne_alloc_used - allocated); fprintf(debug, "Blocks leaked: "); ne_alloc_dump(debug); result = FAIL; } else if (tests[n].flags & T_EXPECT_LEAKS && result == OK && ne_alloc_used == allocated) { t_context("expected memory leak not detected"); result = FAIL; } else if (tests[n].flags & T_EXPECT_LEAKS && result == OK) { fprintf(debug, "Blocks leaked (expected): "); ne_alloc_dump(debug); is_xleaky = 1; } #endif if (tests[n].flags & T_EXPECT_FAIL) { if (result == OK) { t_context("test passed but expected failure"); result = FAIL; } else if (result == FAIL) { result = OK; is_xfail = 1; } } /* align the result column if we've had warnings. */ if (warned) { printf(" %s ", dots); } switch (result) { case OK: if (is_xfail) { COL("32;07"); printf("xfail"); } else { COL("32"); printf("pass"); } NOCOL; if (warned) { printf(" (with %d warning%s)", warned, (warned > 1)?"s":""); } #ifdef NEON_MEMLEAK if (is_xleaky) { printf(" (with expected leak, %" NE_FMT_SIZE_T " bytes)", ne_alloc_used - allocated); } #endif putchar('\n'); passes++; break; case FAILHARD: aborted = 1; /* fall-through */ case FAIL: COL("41;37;01"); printf("FAIL"); NOCOL; if (have_context) { printf(" (%s)", test_context); } putchar('\n'); fails++; break; case SKIPREST: aborted = 1; /* fall-through */ case SKIP: COL("44;37;01"); printf("SKIPPED"); NOCOL; if (have_context) { printf(" (%s)", test_context); } putchar('\n'); skipped++; break; default: COL("41;37;01"); printf("OOPS"); NOCOL; printf(" unexpected test result `%d'\n", result); break; } reap_server(); } /* discount skipped tests */ if (skipped) { printf("-> %d %s.\n", skipped, skipped==1?"test was skipped":"tests were skipped"); n -= skipped; if (passes + fails != n) { printf("-> ARGH! Number of test results does not match " "number of tests.\n" "-> ARGH! Test Results are INRELIABLE.\n"); } } /* print the summary. */ if (skipped && n == 0) { printf("<- all tests skipped for `%s'.\n", test_suite); } else { printf("<- summary for `%s': " "of %d tests run: %d passed, %d failed. %.1f%%\n", test_suite, n, passes, fails, 100*(float)passes/n); if (warnings) { printf("-> %d warning%s issued.\n", warnings, warnings==1?" was":"s were"); } } if (fclose(debug)) { fprintf(stderr, "Error closing debug.log: %s\n", strerror(errno)); fails = 1; } if (fclose(child_debug)) { fprintf(stderr, "Error closing child.log: %s\n", strerror(errno)); fails = 1; } ne_sock_exit(); return fails; }
int main (int argc, char *argv[]) { CurrentState *state; const char *home_dir; char *config_file; int opt, sock; setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); program_name = argv[0]; while ((opt = getopt_long (argc, argv, opts, longopts, NULL)) != -1) { switch (opt) { case 'v': verbosity++; break; case 0400 + 'h': print_usage (); return 0; case 0400 + 'v': print_version (); return 0; case '?': fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); return 1; } } home_dir = getenv ("HOME"); if (! home_dir) { fprintf (stderr, "%s: %s\n", program_name, _("unable to find HOME in environment")); return 1; } print_version (); printf ("\n"); if (ne_sock_init ()) { fprintf (stderr, "%s: %s\n", program_name, _("unable to initialise http library")); return 1; } state = malloc (sizeof (CurrentState)); memset (state, 0, sizeof (CurrentState)); state->host = NULL; state->auth_host = NULL; state->email = NULL; state->password = NULL; state->cookie = NULL; state->car_position = NULL; state->car_info = NULL; config_file = malloc (strlen (home_dir) + 7); sprintf (config_file, "%s/.f1rc", home_dir); if (read_config (state, config_file)) return 1; if ((! state->email) || (! state->password)) { if (get_config (state) || write_config (state, config_file)) return 1; } if (! state->host) state->host = DEFAULT_HOST; if (! state->auth_host) state->auth_host = DEFAULT_HOST; free (config_file); do { state->cookie = obtain_auth_cookie (state->auth_host, state->email, state->password); } while (! state->cookie); for (;;) { int ret; sock = open_stream (state->host, 4321); if (sock < 0) { close_display (); fprintf (stderr, "%s: %s: %s\n", program_name, _("unable to open data stream"), strerror (errno)); return 2; } state->key = 0; state->frame = 0; state->event_no = 0; state->event_type = RACE_EVENT; state->epoch_time = 0; state->remaining_time = 0; state->laps_completed = 0; state->total_laps = 0; state->flag = GREEN_FLAG; state->track_temp = 0; state->air_temp = 0; state->wind_speed = 0; state->humidity = 0; state->pressure = 0; state->wind_direction = 0; if (state->fl_car) free (state->fl_car); state->fl_car = calloc(3, sizeof(char)); if (state->fl_driver) free (state->fl_driver); state->fl_driver = calloc(15, sizeof(char)); if (state->fl_time) free (state->fl_time); state->fl_time = calloc(9, sizeof(char)); if (state->fl_lap) free (state->fl_lap); state->fl_lap = calloc(3, sizeof(char)); state->num_cars = 0; if (state->car_position) { free (state->car_position); state->car_position = NULL; } if (state->car_info) { free (state->car_info); state->car_info = NULL; } reset_decryption (state); while ((ret = read_stream (state, sock)) > 0) { if (handle_keys (state) < 0) { close_display (); close (sock); return 0; } } if (ret < 0) { close_display (); fprintf (stderr, "%s: %s: %s\n", program_name, _("error reading from data stream"), strerror (errno)); return 2; } close (sock); info (1, _("Reconnecting ...\n")); } }
int main(int argc, char **argv) { struct dt_dentry *probe; struct wdwk_dir curdir; int full = 0; int lookup = 0; char *host; int i; char *oldtree = NULL; FILE *oldfile; int port = 0; for (i = 1; i < argc; i++) { if (argv[i][0] != '-') break; if (argv[i][1] == '-' && argv[i][2] == 0) { i++; break; } switch (argv[i][1]) { case 'f': full = 1; break; case 'p': port = atoi(&argv[i][2]); break; case 'l': lookup = 1; break; case 'u': i++; if (i >= argc) usage(argv[0], ESTAT_FAILURE); oldtree = argv[i]; break; case 'h': usage(argv[0], ESTAT_SUCCESS); default: usage(argv[0], ESTAT_FAILURE); } } if (i + 1 != argc) usage(argv[0], ESTAT_FAILURE); ne_debug_init(stderr, 0); if (ne_sock_init()) { LOG_ERR("ne_sock_init() returned non-zero\n"); exit(ESTAT_NOCONNECT); } host = argv[i]; if (wdwk_open(&curdir, host, port) < 0) exit(ESTAT_NOCONNECT); if (lookup) { probe = wdwk_walker.readdir(&curdir); wdwk_close(&curdir); if (probe != NULL) { dt_free(probe); exit(ESTAT_SUCCESS); } else exit(ESTAT_FAILURE); } if (full) dt_full(&wdwk_walker, &curdir); else if (oldtree) { if ((oldfile = fopen(oldtree, "r")) == NULL) { LOG_ERRNO("Can't open file %s\n", oldtree); exit(ESTAT_FAILURE); } dt_diff(oldfile, &wdwk_walker, &curdir); fclose(oldfile); } else dt_reverse(&wdwk_walker, &curdir); wdwk_close(&curdir); ne_sock_exit(); return ESTAT_SUCCESS; }
/* * Connect to a DAV server * This function sets the flag _connected if the connection is established * and returns if the flag is set, so calling it frequently is save. */ static int dav_connect(const char *base_url) { int timeout = 30; int useSSL = 0; int rc; char protocol[6]; char uaBuf[256]; char *path = NULL; char *scheme = NULL; char *host = NULL; unsigned int port = 0; if (_connected) { return 0; } rc = c_parse_uri( base_url, &scheme, &dav_session.user, &dav_session.pwd, &host, &port, &path ); if( rc < 0 ) { DEBUG_WEBDAV(("Failed to parse uri %s\n", base_url )); goto out; } DEBUG_WEBDAV(("* scheme %s\n", scheme )); DEBUG_WEBDAV(("* host %s\n", host )); DEBUG_WEBDAV(("* port %u\n", port )); DEBUG_WEBDAV(("* path %s\n", path )); if( strcmp( scheme, "owncloud" ) == 0 ) { strncpy( protocol, "http", 6); } else if( strcmp( scheme, "ownclouds" ) == 0 ) { strncpy( protocol, "https", 6 ); useSSL = 1; } else { strncpy( protocol, "", 6 ); DEBUG_WEBDAV(("Invalid scheme %s, go outa here!", scheme )); rc = -1; goto out; } DEBUG_WEBDAV(("* user %s\n", dav_session.user ? dav_session.user : "")); if (port == 0) { port = ne_uri_defaultport(protocol); } rc = ne_sock_init(); DEBUG_WEBDAV(("ne_sock_init: %d\n", rc )); if (rc < 0) { rc = -1; goto out; } dav_session.ctx = ne_session_create( protocol, host, port); if (dav_session.ctx == NULL) { DEBUG_WEBDAV(("Session create with protocol %s failed\n", protocol )); rc = -1; goto out; } ne_set_read_timeout(dav_session.ctx, timeout); snprintf( uaBuf, sizeof(uaBuf), "csyncoC/%s",CSYNC_STRINGIFY( LIBCSYNC_VERSION )); ne_set_useragent( dav_session.ctx, c_strdup( uaBuf )); ne_set_server_auth(dav_session.ctx, ne_auth, 0 ); if( useSSL ) { if (!ne_has_support(NE_FEATURE_SSL)) { DEBUG_WEBDAV(("Error: SSL is not enabled.\n")); rc = -1; goto out; } ne_ssl_trust_default_ca( dav_session.ctx ); ne_ssl_set_verify( dav_session.ctx, verify_sslcert, 0 ); } _connected = 1; rc = 0; out: return rc; }
/* create a socket for connecting to remote server */ static gboolean gst_neonhttp_src_start (GstBaseSrc * bsrc) { GstNeonhttpSrc *src = GST_NEONHTTP_SRC (bsrc); const gchar *content_length; gint res; #ifndef GST_DISABLE_GST_DEBUG if (src->neon_http_debug) ne_debug_init (stderr, NE_DBG_HTTP); #endif ne_oom_callback (oom_callback); res = ne_sock_init (); if (res != 0) goto init_failed; res = gst_neonhttp_src_send_request_and_redirect (src, &src->session, &src->request, 0, src->automatic_redirect); if (res != NE_OK || !src->session) { if (res == HTTP_SOCKET_ERROR) { goto socket_error; } else if (res == HTTP_REQUEST_WRONG_PROXY) { goto wrong_proxy; } else { goto begin_req_failed; } } content_length = ne_get_response_header (src->request, "Content-Length"); if (content_length) src->content_size = g_ascii_strtoull (content_length, NULL, 10); else src->content_size = -1; if (TRUE) { /* Icecast stuff */ const gchar *str_value; GstTagList *tags; gchar *iradio_name; gchar *iradio_url; gchar *iradio_genre; gint icy_metaint; tags = gst_tag_list_new_empty (); str_value = ne_get_response_header (src->request, "icy-metaint"); if (str_value) { if (sscanf (str_value, "%d", &icy_metaint) == 1) { GstCaps *icy_caps; icy_caps = gst_caps_new_simple ("application/x-icy", "metadata-interval", G_TYPE_INT, icy_metaint, NULL); gst_base_src_set_caps (GST_BASE_SRC (src), icy_caps); } } /* FIXME: send tags with name, genre, url */ str_value = ne_get_response_header (src->request, "icy-name"); if (str_value) { iradio_name = gst_neonhttp_src_unicodify (str_value); if (iradio_name) { gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_ORGANIZATION, iradio_name, NULL); g_free (iradio_name); } } str_value = ne_get_response_header (src->request, "icy-genre"); if (str_value) { iradio_genre = gst_neonhttp_src_unicodify (str_value); if (iradio_genre) { gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_GENRE, iradio_genre, NULL); g_free (iradio_genre); } } str_value = ne_get_response_header (src->request, "icy-url"); if (str_value) { iradio_url = gst_neonhttp_src_unicodify (str_value); if (iradio_url) { gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_LOCATION, iradio_url, NULL); g_free (iradio_url); } } if (!gst_tag_list_is_empty (tags)) { GST_DEBUG_OBJECT (src, "pushing tag list %" GST_PTR_FORMAT, tags); gst_pad_push_event (GST_BASE_SRC_PAD (src), gst_event_new_tag (tags)); } else { gst_tag_list_unref (tags); } } return TRUE; /* ERRORS */ init_failed: { GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL), ("ne_sock_init() failed: %d", res)); return FALSE; } socket_error: { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("HTTP Request failed when opening socket: %d", res)); return FALSE; } wrong_proxy: { GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL), ("Proxy Server URI is invalid - make sure that either both proxy host " "and port are specified or neither.")); return FALSE; } begin_req_failed: { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("Could not begin request: %d", res)); return FALSE; } }
/* * Connect to a DAV server * This function sets the flag _connected if the connection is established * and returns if the flag is set, so calling it frequently is save. */ static int dav_connect(const char *base_url) { int useSSL = 0; int rc; char protocol[6] = {'\0'}; char uaBuf[256]; char *path = NULL; char *scheme = NULL; char *host = NULL; unsigned int port = 0; int proxystate = -1; if (_connected) { return 0; } rc = c_parse_uri( base_url, &scheme, &dav_session.user, &dav_session.pwd, &host, &port, &path ); if( rc < 0 ) { DEBUG_WEBDAV("Failed to parse uri %s", base_url ); goto out; } DEBUG_WEBDAV("* scheme %s", scheme ); DEBUG_WEBDAV("* host %s", host ); DEBUG_WEBDAV("* port %u", port ); DEBUG_WEBDAV("* path %s", path ); if( strcmp( scheme, "owncloud" ) == 0 ) { strcpy( protocol, "http"); } else if( strcmp( scheme, "ownclouds" ) == 0 ) { strcpy( protocol, "https"); useSSL = 1; } else { DEBUG_WEBDAV("Invalid scheme %s, go outa here!", scheme ); rc = -1; goto out; } DEBUG_WEBDAV("* user %s", dav_session.user ? dav_session.user : ""); if (port == 0) { port = ne_uri_defaultport(protocol); } #if 0 rc = ne_sock_init(); DEBUG_WEBDAV("ne_sock_init: %d", rc ); if (rc < 0) { rc = -1; goto out; } #endif dav_session.ctx = ne_session_create( protocol, host, port); if (dav_session.ctx == NULL) { DEBUG_WEBDAV("Session create with protocol %s failed", protocol ); rc = -1; goto out; } if (dav_session.read_timeout == 0) dav_session.read_timeout = 300; // set 300 seconds as default. ne_set_read_timeout(dav_session.ctx, dav_session.read_timeout); snprintf( uaBuf, sizeof(uaBuf), "Mozilla/5.0 (%s) csyncoC/%s", get_platform(), CSYNC_STRINGIFY( LIBCSYNC_VERSION )); ne_set_useragent( dav_session.ctx, uaBuf); ne_set_server_auth(dav_session.ctx, ne_auth, 0 ); if( useSSL ) { if (!ne_has_support(NE_FEATURE_SSL)) { DEBUG_WEBDAV("Error: SSL is not enabled."); rc = -1; goto out; } ne_ssl_trust_default_ca( dav_session.ctx ); ne_ssl_set_verify( dav_session.ctx, verify_sslcert, 0 ); } /* Hook called when a request is created. It sets the proxy connection header. */ ne_hook_create_request( dav_session.ctx, request_created_hook, NULL ); /* Hook called after response headers are read. It gets the Session ID. */ ne_hook_post_headers( dav_session.ctx, post_request_hook, NULL ); /* Hook called before a request is sent. It sets the cookies. */ ne_hook_pre_send( dav_session.ctx, pre_send_hook, NULL ); /* Hook called after request is dispatched. Used for handling possible redirections. */ ne_hook_post_send( dav_session.ctx, post_send_hook, NULL ); /* Proxy support */ proxystate = configureProxy( dav_session.ctx ); if( proxystate < 0 ) { DEBUG_WEBDAV("Error: Proxy-Configuration failed."); } else if( proxystate > 0 ) { ne_set_proxy_auth( dav_session.ctx, ne_proxy_auth, 0 ); } _connected = 1; rc = 0; out: SAFE_FREE(path); SAFE_FREE(host); SAFE_FREE(scheme); return rc; }
/* create a socket for connecting to remote server */ static gboolean gst_neonhttp_src_start (GstBaseSrc * bsrc) { GstNeonhttpSrc *src = GST_NEONHTTP_SRC (bsrc); const gchar *content_length; gint res; #ifndef GST_DISABLE_GST_DEBUG if (src->neon_http_debug) ne_debug_init (stderr, NE_DBG_HTTP); #endif ne_oom_callback (oom_callback); res = ne_sock_init (); if (res != 0) goto init_failed; res = gst_neonhttp_src_send_request_and_redirect (src, &src->session, &src->request, 0, src->automatic_redirect); if (res != NE_OK || !src->session) { if (res == HTTP_SOCKET_ERROR) { goto socket_error; } else if (res == HTTP_REQUEST_WRONG_PROXY) { goto wrong_proxy; } else { goto begin_req_failed; } } content_length = ne_get_response_header (src->request, "Content-Length"); if (content_length) src->content_size = g_ascii_strtoull (content_length, NULL, 10); else src->content_size = -1; if (src->iradio_mode) { /* Icecast stuff */ const gchar *str_value; gint gint_value; str_value = ne_get_response_header (src->request, "icy-metaint"); if (str_value) { if (sscanf (str_value, "%d", &gint_value) == 1) { if (src->icy_caps) { gst_caps_unref (src->icy_caps); src->icy_caps = NULL; } src->icy_metaint = gint_value; src->icy_caps = gst_caps_new_simple ("application/x-icy", "metadata-interval", G_TYPE_INT, src->icy_metaint, NULL); } } str_value = ne_get_response_header (src->request, "icy-name"); if (str_value) { if (src->iradio_name) { g_free (src->iradio_name); src->iradio_name = NULL; } src->iradio_name = gst_neonhttp_src_unicodify (str_value); } str_value = ne_get_response_header (src->request, "icy-genre"); if (str_value) { if (src->iradio_genre) { g_free (src->iradio_genre); src->iradio_genre = NULL; } src->iradio_genre = gst_neonhttp_src_unicodify (str_value); } str_value = ne_get_response_header (src->request, "icy-url"); if (str_value) { if (src->iradio_url) { g_free (src->iradio_url); src->iradio_url = NULL; } src->iradio_url = gst_neonhttp_src_unicodify (str_value); } } return TRUE; /* ERRORS */ init_failed: { GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL), ("ne_sock_init() failed: %d", res)); return FALSE; } socket_error: { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("HTTP Request failed when opening socket: %d", res)); return FALSE; } wrong_proxy: { GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL), ("Proxy Server URI is invalid - make sure that either both proxy host " "and port are specified or neither.")); return FALSE; } begin_req_failed: { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("Could not begin request: %d", res)); return FALSE; } }