/* Create a RMI structure and start the ripping thread */ error_code rip_manager_start (RIP_MANAGER_INFO **rmip, STREAM_PREFS *prefs, RIP_MANAGER_CALLBACK status_callback) { RIP_MANAGER_INFO* rmi; #if __UNIX__ int rc; #endif if (!prefs || !rmip) { return SR_ERROR_INVALID_PARAM; } rmi = (*rmip) = (RIP_MANAGER_INFO*) malloc (sizeof(RIP_MANAGER_INFO)); memset (rmi, 0, sizeof(RIP_MANAGER_INFO)); rmi->prefs = prefs; rmi->started_sem = threadlib_create_sem(); register_codesets (rmi, &prefs->cs_opt); /* From select() man page: On systems that lack pselect() reliable (and more portable) signal trapping can be achieved using the self-pipe trick (where a signal handler writes a byte to a pipe whose other end is mon- itored by select() in the main program. */ #if __UNIX__ rc = pipe (rmi->abort_pipe); if (rc != 0) { return SR_ERROR_CREATE_PIPE_FAILED; } #endif rmi->status_callback = status_callback; rmi->bytes_ripped = 0; rmi->megabytes_ripped = 0; rmi->write_data = 1; /* Initialize the parsing rules */ /* GCS FIX: parser_free() would need to be freed by the caller. But he has no cleanup routine to call! */ init_metadata_parser (rmi, prefs->rules_file); /* Start the ripping thread */ debug_printf ("Pre ripthread: %s\n", rmi->prefs->url); rmi->started = 1; return threadlib_beginthread (&rmi->hthread_ripper, ripthread, (void*) rmi); }
void debug_mprintf (mchar* fmt, ...) { int was_open = 1; va_list argptr; int rc; mchar mbuf[DEBUG_BUF_LEN]; char cbuf[DEBUG_BUF_LEN]; if (!debug_on) return; if (!debug_initialized) { m_debug_lock = threadlib_create_sem(); threadlib_signal_sem(&m_debug_lock); } threadlib_waitfor_sem (&m_debug_lock); va_start (argptr, fmt); if (!gcsfp) { was_open = 0; debug_open(); if (!gcsfp) return; } if (!debug_initialized) { debug_initialized = 1; fprintf (gcsfp, "=========================\n"); fprintf (gcsfp, "STREAMRIPPER " SRPLATFORM " " SRVERSION "\n"); } #if defined HAVE_WCHAR_SUPPORT rc = vswprintf (mbuf, DEBUG_BUF_LEN, fmt, argptr); debug_on = 0; /* Avoid recursive call which hangs on semaphore */ rc = string_from_mstring (cbuf, DEBUG_BUF_LEN, mbuf, CODESET_LOCALE); debug_on = 1; #else rc = vsnprintf (cbuf, DEBUG_BUF_LEN, fmt, argptr); #endif fwrite (cbuf, 1, rc, gcsfp); fflush (gcsfp); va_end (argptr); if (!was_open) { debug_close (); } threadlib_signal_sem (&m_debug_lock); }
debug_printf (char* fmt, ...) #endif { int was_open = 1; va_list argptr; if (!debug_on) { /* Uncomment to debug debug_mprintf() */ #if defined (commentout) va_start (argptr, fmt); vprintf (fmt, argptr); va_end (argptr); #endif return; } if (!debug_initialized) { m_debug_lock = threadlib_create_sem(); threadlib_signal_sem(&m_debug_lock); } threadlib_waitfor_sem (&m_debug_lock); va_start (argptr, fmt); if (!gcsfp) { was_open = 0; debug_open(); if (!gcsfp) return; } if (!debug_initialized) { debug_initialized = 1; fprintf (gcsfp, "=========================\n"); fprintf (gcsfp, "STREAMRIPPER " SRPLATFORM " " SRVERSION "\n"); } vfprintf (gcsfp, fmt, argptr); fflush (gcsfp); va_end (argptr); if (!was_open) { debug_close (); } threadlib_signal_sem (&m_debug_lock); }
void debug_printf(char *fmt, ...) { int was_open = 1; va_list argptr; if (!debug_on) { return; } if (!debug_initialized) { m_debug_lock = threadlib_create_sem(); threadlib_signal_sem(&m_debug_lock); } threadlib_waitfor_sem(&m_debug_lock); va_start(argptr, fmt); if (!gcsfp) { was_open = 0; debug_open(); if (!gcsfp) return; } if (!debug_initialized) { debug_initialized = 1; fprintf(gcsfp, "=========================\n"); fprintf(gcsfp, "STREAMRIPPER " SRPLATFORM " " SRVERSION "\n"); } vfprintf(gcsfp, fmt, argptr); fflush(gcsfp); va_end(argptr); if (!was_open) { debug_close(); } threadlib_signal_sem(&m_debug_lock); }
error_code relaylib_start (RIP_MANAGER_INFO* rmi, BOOL search_ports, u_short relay_port, u_short max_port, u_short *port_used, char *if_name, int max_connections, char *relay_ip, int have_metadata) { int ret; #ifdef WIN32 WSADATA wsd; #endif RELAYLIB_INFO* rli = &rmi->relaylib_info; /* GCS: These were globally initialized... */ rli->m_listensock = SOCKET_ERROR; rli->m_running = FALSE; rli->m_running_accept = FALSE; rli->m_running_send = FALSE; debug_printf ("relaylib_start()\n"); rmi->relay_list = 0; rmi->relay_list_len = 0; #ifdef WIN32 if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) { debug_printf ("relaylib_init(): SR_ERROR_CANT_BIND_ON_PORT\n"); return SR_ERROR_CANT_BIND_ON_PORT; } #endif if (relay_port < 1 || !port_used) { debug_printf ("relaylib_init(): SR_ERROR_INVALID_PARAM\n"); return SR_ERROR_INVALID_PARAM; } #ifndef WIN32 // catch a SIGPIPE if send fails signal(SIGPIPE, catch_pipe); #endif rli->m_sem_not_connected = threadlib_create_sem(); rmi->relay_list_sem = threadlib_create_sem(); threadlib_signal_sem (&rmi->relay_list_sem); // NOTE: we need to signal it here in case we try to destroy // relaylib before the thread starts! threadlib_signal_sem (&rli->m_sem_not_connected); //m_max_connections = max_connections; //m_have_metadata = have_metadata; *port_used = 0; if (!search_ports) max_port = relay_port; for(;relay_port <= max_port; relay_port++) { ret = try_port (rli, (u_short) relay_port, if_name, relay_ip); if (ret == SR_ERROR_CANT_BIND_ON_PORT) continue; // Keep searching. if (ret == SR_SUCCESS) { *port_used = relay_port; debug_printf ("Relay: Listening on port %d\n", relay_port); ret = SR_SUCCESS; if (!rli->m_running) { ret = relaylib_start_threads (rmi); } return ret; } else { return ret; } } return SR_ERROR_CANT_BIND_ON_PORT; }