예제 #1
0
/*
 * ascii_rescue
 *
 * Looks for a ASCII file starting at cur. If found, writes it to disk.
 *
 * cur: Current position in file in memory.
 * end: One byte past the end of the file in memory.
 */
static inline void
ascii_rescue(const uint8_t *cur,
             const uint8_t * const end)
{
    const uint8_t * const ascii_start = cur;
    const uint64_t        min_size_bytes = 1024;

    /*
     * If this byte has already been examined, ignore it.
     */
    if (cur < g_ascii_ignore_before) {
        return;
    }

    /*
     * Keep going while the character is within the printable ASCII range.
     */
    while (*cur >= 0x20 && *cur <= 0x7E && cur < end) {
        cur++;
    }

    /*
     * If we found sufficiently many, this is probably an ASCII text file.
     */
    if (cur - ascii_start >= min_size_bytes) {
        std::cerr << "ASCII: " << (uint64_t)(cur - ascii_start)
                  << " bytes of text found\n";
        write_fragment(ascii_start, cur, "txt");
    }
    g_ascii_ignore_before = cur;
}
예제 #2
0
void
snra_server_client_send_message (SnraServerClient * client,
                                 gchar * body, gsize len)
{
    PendingMsg *msg;

    if (client->fired_conn_lost)
        return;

    if (client->type == SNRA_SERVER_CLIENT_CHUNKED) {
        soup_message_body_append (client->event_pipe->response_body,
                                  SOUP_MEMORY_COPY, body, len);
        soup_server_unpause_message (client->soup, client->event_pipe);
        return;
    }
    if (client->type == SNRA_SERVER_CLIENT_SINGLE) {
        soup_message_set_response (client->event_pipe,
                                   "application/json", SOUP_MEMORY_COPY, body, len);
        snra_server_connection_lost (client);
        return;
    }

    /* else, websocket connection */
    if (client->io) {
        write_fragment (client, body, len);
        return;
    }

    /* Websocket isn't ready to send yet. Store as a pending message */
    msg = g_new (PendingMsg, 1);
    msg->len = len;
    msg->body = g_memdup (body, len);

    client->pending_msgs = g_list_append (client->pending_msgs, msg);
}
예제 #3
0
/* Format and write out all the code fragments. */
static void write_all_fragments(struct code_state *code)
{
	struct code_fragment *fragment = NULL;
	for (fragment = code->list_head; fragment != NULL;
	     fragment = fragment->next) {
		write_fragment(code, fragment);
	}
}
예제 #4
0
void SoundOutput_Impl::mixer_thread()
{
    mixer_thread_starting();
    
	while (if_continue_mixing())
	{
		// Mix some audio:
		mix_fragment();

		// Send mixed data to sound card:
		write_fragment(stereo_buffer);

		// Wait for sound card to want more:
		wait();
	}
    
    mixer_thread_stopping();
}
예제 #5
0
/*
 * jpeg_rescue
 *
 * Looks for a JPEG file starting at cur. If found, writes it to disk.
 *
 * cur: Current position in file in memory.
 * end: One byte past the end of the file in memory.
 */
static inline void
jpeg_rescue(const uint8_t *const cur,
            const uint8_t *const end)
{
    /*
     * To do: stop examining in the middle of JPEG files that have already
     *        been found.     
     */
         
    if (jpeg_is_header(cur, end)) {
        std::cerr << "JPEG: found header at byte "
                  << (uint64_t)(cur - g_start) << "\n";

        const uint8_t *const jpeg_end = jpeg_find_footer(cur, end);
        if (jpeg_end == NULL) {
            std::cerr << "JPEG: footer not found!\n";
        } else {
            std::cerr << "JPEG: footer found\n";
            write_fragment(cur, jpeg_end, "jpg");
        }
    }
}