void safe_exit(int code) { char *dummy, *dammy; dump_close(); #ifdef HAVE_TERMIOS if(param.term_ctrl) term_restore(); #endif if(have_output) exit_output(ao, intflag); if(mh != NULL) mpg123_delete(mh); if(cleanup_mpg123) mpg123_exit(); httpdata_free(&htd); #ifdef WANT_WIN32_UNICODE win32_cmdline_free(argc, argv); /* This handles the premature argv == NULL, too. */ #endif #if defined (WANT_WIN32_SOCKETS) win32_net_deinit(); #endif /* It's ugly... but let's just fix this still-reachable memory chunk of static char*. */ split_dir_file("", &dummy, &dammy); exit(code); }
void capture_close() { capture_info_t *capinfo; // Nothing to close if (vector_count(capture_cfg.sources) == 0) return; // Stop all captures vector_iter_t it = vector_iterator(capture_cfg.sources); while ((capinfo = vector_iterator_next(&it))) { //Close PCAP file if (capinfo->handle) { pcap_breakloop(capinfo->handle); pthread_join(capinfo->capture_t, NULL); pcap_close(capinfo->handle); } } // Close dump file if (capture_cfg.pd) { dump_close(capture_cfg.pd); } }
void ufw_close(ufw_sk *sk){ struct node *cur, *next; if(!sk) return; while(close(sk->fd) < 0 && errno == EINTR); for(cur = sk->recvhook; cur; cur = next){ next = cur->next; free(cur); } for(cur = sk->sendhook; cur; cur = next){ next = cur->next; free(cur); } if(sk->dump) dump_close(sk->dump); for(cur = ufwsk_list; cur; cur = cur->next) if(sk == cur->data){ if(cur->prev) cur->prev->next = cur->next; else ufwsk_list = cur->next; if(cur->next) cur->next->prev = cur->prev; free(cur); return; } }
/* External API... open and close. */ int dump_open(mpg123_handle *mh) { int ret; if(param.streamdump == NULL) return 0; if(!param.quiet) fprintf(stderr, "Note: Dumping stream to %s\n", param.streamdump); dump_fd = compat_open(param.streamdump, O_CREAT|O_TRUNC|O_RDWR); if(dump_fd < 0) { error1("Failed to open dump file: %s\n", strerror(errno)); return -1; } #ifdef WIN32 _setmode(dump_fd, _O_BINARY); #endif ret = mpg123_replace_reader(mh, dump_read, dump_seek); if(ret != MPG123_OK) { error1("Unable to replace reader for stream dump: %s\n", mpg123_strerror(mh)); dump_close(); return -1; } else return 0; }
void capture_close() { //Close PCAP file if (capinfo.handle) { pcap_breakloop(capinfo.handle); pthread_join(capinfo.capture_t, NULL); pcap_close(capinfo.handle); } // Close dump file if (capinfo.pd) { dump_close(capinfo.pd); } }
int main(int argc, char **argv) { char *ptr; //open_dump("test.out"); open_dump("-"); struct dumper d; d.width = 16; d.height = 2; d.data = malloc( sizeof(char) * d.width * d.height ); memset(d.data, '0', sizeof(char) * d.width * d.height); ptr = d.data; ptr[5] = '1'; write_dump(&d); dump_close(); return 0; }
/* 1 on success, 0 on failure */ int open_track(char *fname) { filept=-1; httpdata_reset(&htd); if(MPG123_OK != mpg123_param(mh, MPG123_ICY_INTERVAL, 0, 0)) error1("Cannot (re)set ICY interval: %s", mpg123_strerror(mh)); if(!strcmp(fname, "-")) { filept = STDIN_FILENO; #ifdef WIN32 _setmode(STDIN_FILENO, _O_BINARY); #endif return open_track_fd(); } else if (!strncmp(fname, "http://", 7)) /* http stream */ { #if defined (WANT_WIN32_SOCKETS) if(param.streamdump != NULL) { fprintf(stderr, "\nWarning: win32 networking conflicts with stream dumping. Aborting the dump.\n"); dump_close(); } /*Use recv instead of stdio functions */ win32_net_replace(mh); filept = win32_net_http_open(fname, &htd); #else filept = http_open(fname, &htd); #endif network_sockets_used = 1; /* utf-8 encoded URLs might not work under Win32 */ /* now check if we got sth. and if we got sth. good */ if( (filept >= 0) && (htd.content_type.p != NULL) && !APPFLAG(MPG123APP_IGNORE_MIME) && !(debunk_mime(htd.content_type.p) & IS_FILE) ) { error1("Unknown mpeg MIME type %s - is it perhaps a playlist (use -@)?", htd.content_type.p == NULL ? "<nil>" : htd.content_type.p); error("If you know the stream is mpeg1/2 audio, then please report this as "PACKAGE_NAME" bug"); return 0; } if(filept < 0) { error1("Access to http resource %s failed.", fname); return 0; } if(MPG123_OK != mpg123_param(mh, MPG123_ICY_INTERVAL, htd.icy_interval, 0)) error1("Cannot set ICY interval: %s", mpg123_strerror(mh)); if(param.verbose > 1) fprintf(stderr, "Info: ICY interval %li\n", (long)htd.icy_interval); } if(param.icy_interval > 0) { if(MPG123_OK != mpg123_param(mh, MPG123_ICY_INTERVAL, param.icy_interval, 0)) error1("Cannot set ICY interval: %s", mpg123_strerror(mh)); if(param.verbose > 1) fprintf(stderr, "Info: Forced ICY interval %li\n", param.icy_interval); } debug("OK... going to finally open."); /* Now hook up the decoder on the opened stream or the file. */ if(network_sockets_used) { return open_track_fd(); } else if(mpg123_open(mh, fname) != MPG123_OK) { error2("Cannot open %s: %s", fname, mpg123_strerror(mh)); return 0; } debug("Track successfully opened."); fresh = TRUE; return 1; }
int save_to_file(ui_t *ui) { char savepath[256]; char savefile[256]; char fullfile[512]; sip_call_t *call = NULL; sip_msg_t *msg = NULL; pcap_dumper_t *pd = NULL; FILE *f = NULL; int cur = 0, total = 0; WINDOW *progress; vector_iter_t calls, msgs, rtps, packets; packet_t *packet; vector_t *sorted; // Get panel information save_info_t *info = save_info(ui); // Get current path field value. memset(savepath, 0, sizeof(savepath)); strcpy(savepath, field_buffer(info->fields[FLD_SAVE_PATH], 0)); strtrim(savepath); if (strlen(savepath)) strcat(savepath, "/"); // Get current file field value. memset(savefile, 0, sizeof(savefile)); strcpy(savefile, field_buffer(info->fields[FLD_SAVE_FILE], 0)); strtrim(savefile); if (!strlen(savefile)) { dialog_run("Please enter a valid filename"); return 1; } if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { if (!strstr(savefile, ".pcap")) strcat(savefile, ".pcap"); } else { if (!strstr(savefile, ".txt")) strcat(savefile, ".txt"); } // Absolute filename sprintf(fullfile, "%s%s", savepath, savefile); if (access(fullfile, R_OK) == 0) { if (dialog_confirm("Overwrite confirmation", "Selected file already exits.\n Do you want to overwrite it?", "Yes,No") != 0) return 1; } // Don't allow to save no packets! if (info->savemode == SAVE_SELECTED && call_group_msg_count(info->group) == 0) { dialog_run("Unable to save: No selected dialogs."); return 1; } if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { // Open dump file pd = dump_open(fullfile); if (access(fullfile, W_OK) != 0) { dialog_run(capture_last_error()); return 1; } } else { // Open a text file if (!(f = fopen(fullfile, "w"))) { dialog_run("Error: %s", strerror(errno)); return 0; } } // Get calls iterator switch (info->savemode) { case SAVE_ALL: // Get calls iterator calls = sip_calls_iterator(); break; case SAVE_SELECTED: // Save selected packets to file calls = vector_iterator(info->group->calls); break; case SAVE_DISPLAYED: // Set filtering for this iterator calls = sip_calls_iterator(); vector_iterator_set_filter(&calls, filter_check_call); break; default: break; } if (info->savemode == SAVE_MESSAGE) { if (info->saveformat == SAVE_TXT) { // Save selected message to file save_msg_txt(f, info->msg); } else { // Save selected message packet to pcap dump_packet(pd, info->msg->packet); } } else if (info->saveformat == SAVE_TXT) { // Save selected packets to file while ((call = vector_iterator_next(&calls))) { msgs = vector_iterator(call->msgs); // Save SIP message content while ((msg = vector_iterator_next(&msgs))) { save_msg_txt(f, msg); } } } else { // Store all messages in a time sorted vector sorted = vector_create(100, 50); vector_set_sorter(sorted, capture_packet_time_sorter); // Count packages for progress bar while ((call = vector_iterator_next(&calls))) { total += vector_count(call->msgs); if (info->saveformat == SAVE_PCAP_RTP) total += vector_count(call->rtp_packets); } vector_iterator_reset(&calls); progress = dialog_progress_run("Saving packets..."); dialog_progress_set_value(progress, 0); // Save selected packets to file while ((call = vector_iterator_next(&calls))) { msgs = vector_iterator(call->msgs); // Save SIP message content while ((msg = vector_iterator_next(&msgs))) { // Update progress bar dialog dialog_progress_set_value(progress, (++cur * 100) / total); vector_append(sorted, msg->packet); } // Save RTP packets if (info->saveformat == SAVE_PCAP_RTP) { rtps = vector_iterator(call->rtp_packets); while ((packet = vector_iterator_next(&rtps))) { // Update progress bar dialog dialog_progress_set_value(progress, (++cur * 100) / total); vector_append(sorted, packet); } } } // Save sorted packets packets = vector_iterator(sorted); while ((packet = vector_iterator_next(&packets))) { dump_packet(pd, packet); } dialog_progress_destroy(progress); } // Close saved file if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { dump_close(pd); } else { fclose(f); } // Show success popup if (info->savemode == SAVE_MESSAGE) { dialog_run("Successfully saved selected SIP message to %s", savefile); } else { dialog_run("Successfully saved %d dialogs to %s", vector_iterator_count(&calls), savefile); } return 0; }