void in_child(void) { ne_debug_init(child_debug, TEST_DEBUG); NE_DEBUG(TEST_DEBUG, "**** Child forked for test %s ****\n", test_name); signal(SIGSEGV, child_segv); signal(SIGABRT, child_segv); }
static int init_largefile(void) { int n; #ifndef NE_LFS if (sizeof(off_t) == 4) { t_context("32-bit off_t and no LFS support detected " "=> cannot run tests!"); return SKIPREST; } #endif for (n = 0; n < BLOCKSIZE; n++) block[n] = n % 256; /* upload a random file to prep auth if necessary. */ CALL(upload_foo("random.txt")); path = ne_concat(i_path, "large.txt", NULL); /* don't log a message for each body block! */ ne_debug_init(ne_debug_stream, ne_debug_mask & ~(NE_DBG_HTTPBODY|NE_DBG_HTTP)); return OK; }
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; }
/* close the socket and associated resources * used both to recover from errors and go to NULL state */ static gboolean gst_neonhttp_src_stop (GstBaseSrc * bsrc) { GstNeonhttpSrc *src; src = GST_NEONHTTP_SRC (bsrc); if (src->iradio_name) { g_free (src->iradio_name); src->iradio_name = NULL; } if (src->iradio_genre) { g_free (src->iradio_genre); src->iradio_genre = NULL; } if (src->iradio_url) { g_free (src->iradio_url); src->iradio_url = NULL; } if (src->icy_caps) { gst_caps_unref (src->icy_caps); src->icy_caps = NULL; } src->eos = FALSE; src->content_size = -1; src->read_position = 0; src->seekable = TRUE; gst_neonhttp_src_close_session (src); #ifndef GST_DISABLE_GST_DEBUG ne_debug_init (NULL, 0); #endif ne_oom_callback (NULL); ne_sock_exit (); return TRUE; }
/* close the socket and associated resources * used both to recover from errors and go to NULL state */ static gboolean gst_neonhttp_src_stop (GstBaseSrc * bsrc) { GstNeonhttpSrc *src; src = GST_NEONHTTP_SRC (bsrc); src->eos = FALSE; src->content_size = -1; src->read_position = 0; src->seekable = TRUE; gst_neonhttp_src_close_session (src); #ifndef GST_DISABLE_GST_DEBUG ne_debug_init (NULL, 0); #endif ne_oom_callback (NULL); ne_sock_exit (); return TRUE; }
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; }
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 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; }
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; }
/* 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; } }
/* 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; } }