/** * Log whitelist item. */ static void log_whitelist_item(const struct whitelist *item, const char *what) { const char *host; uint8 bits; if (item->host != NULL) { host = 0 == item->port ? item->host->name : host_port_to_string(item->host->name, ipv4_unspecified, item->port); } else { host = 0 == item->port ? host_addr_to_string(item->addr) : host_addr_port_to_string(item->addr, item->port); } if (is_host_addr(item->addr)) { bits = item->bits == addr_default_mask(item->addr) ? 0 : item->bits; } else { bits = 0; } g_debug("WLIST %s %s%s%s%s", what, item->use_tls ? "tls:" : "", host, bits == 0 ? "" : "/", bits == 0 ? "" : uint32_to_string(bits)); }
static size_t thex_upload_prepare_xml(char **data_ptr, const struct tth *tth, filesize_t filesize) { struct dime_record *dime; char buf[512]; size_t len, size; unsigned depth; depth = tt_good_depth(filesize); len = concat_strings(buf, sizeof buf, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" "<!DOCTYPE hashtree S" /* NOTE: HIDE FROM METACONFIG */ "YSTEM \"" THEX_DOCTYPE "\">\r\n" "<hashtree>\r\n" "<file" " size=\"", filesize_to_string(filesize), "\"" " segmentsize=\"" THEX_SEGMENT_SIZE "\"/>\r\n" "<digest" " algorithm=\"" THEX_HASH_ALGO "\"" " outputsize=\"" THEX_HASH_SIZE "\"/>\r\n" "<serializedtree" " depth=\"", uint32_to_string(depth), "\"" " type=\"" THEX_TREE_TYPE "\"" " uri=\"", thex_upload_uuid(tth), "\"/>\r\n" "</hashtree>\r\n", (void *) 0); dime = dime_record_alloc(); dime_record_set_data(dime, buf, len); dime_record_set_type_mime(dime, "text/xml"); size = dime_create_record(dime, data_ptr, TRUE, FALSE); dime_record_free(&dime); return size; }
int main(void) { #if 0 /* TIM2_PWM */ /* tim2 fast pwm mode */ DDRB |= 1 << 3; TIMSK2 = 0; TCNT2 = 0; /* fpwm = (16 * 10^6) / (OCR2A * 2 * prescal) */ #if 0 /* prescal = 1, fpwm = 41025.64102 */ OCR2A = 195; TCCR2B = (1 << 3) | (1 << 0); TCCR2A = (1 << 6) | (3 << 0); #else /* hires pwm, prescal = 1024 */ OCR2A = 255; /* 30.63725490196078431372 */ OCR2A = 240; /* 32.55208333333333333333 */ OCR2A = 230; /* 33.96739130434782608695 */ OCR2A = 220; /* 35.51136363636363636363 */ OCR2A = 210; /* 37.20238095238095238095 */ OCR2A = 200; /* 39.06250000000000000000 */ OCR2A = 20; /* 390.6250000000000000000 */ OCR2A = 10; /* 781.2500000000000000000 */ OCR2A = 2; /* 3906.25000000000000000000 */ OCR2A = 1; /* 7812.50000000000000000000 */ TCCR2B = (1 << 3) | (7 << 0); TCCR2A = (1 << 6) | (3 << 0); #endif #endif /* TIM2_PWM */ #if CONFIG_UART uart_setup(); #endif sei(); while (1) { uart_write(uint32_to_string(hfc_start_wait()), 8); uart_write((uint8_t*)"\r\n", 2); } return 0; }
/** * Verifies "data" against "signature". * * @return TRUE if the signature matches. */ bool svn_release_notification_verify(uint32 revision, time_t date, const struct array *signature) { char rev[12], data[64]; struct array input; uint32_to_string_buf(revision, rev, sizeof rev); input.data = (void *) data; input.size = concat_strings(data, sizeof data, "r", rev, "@", uint32_to_string(date), (void *) 0); return verify_signature(svn_release_notify_certificate(), &input, signature); }
void pit1_isr(void) { if (--pload_tick_count) { /* continue current step */ if (pload_msg.u.steps.op[pload_step_index] == PLOAD_STEP_OP_RAMP) { pload_current += pload_msg.u.steps.arg0[pload_step_index]; dac_set(ma_to_dac((uint32_t)pload_current)); #if 0 /* DEBUG */ SERIAL_WRITE_STRING("dac_set:"); serial_write(uint32_to_string((uint32_t)pload_current), 8); SERIAL_WRITE_STRING("\r\n"); #endif /* DEBUG */ } goto on_done; } if ((++pload_step_index) == (uint32_t)pload_msg.u.steps.count) { #if 0 /* DEBUG */ SERIAL_WRITE_STRING("stopping\r\n"); #endif /* DEBUG */ pit_stop(1); goto on_done; } /* current step done, load next state */ switch (pload_msg.u.steps.op[pload_step_index]) { case PLOAD_STEP_OP_CONST: { const_case: pload_current = (int32_t)pload_msg.u.steps.arg0[pload_step_index]; dac_set(ma_to_dac((uint32_t)pload_current)); #if 0 /* DEBUG */ SERIAL_WRITE_STRING("dac_set:"); serial_write(uint32_to_string((uint32_t)pload_current), 8); SERIAL_WRITE_STRING("\r\n"); #endif /* DEBUG */ pload_tick_count = (uint32_t)pload_msg.u.steps.arg1[pload_step_index]; break ; } case PLOAD_STEP_OP_RAMP: { pload_current += (int32_t)pload_msg.u.steps.arg0[pload_step_index]; dac_set(ma_to_dac((uint32_t)pload_current)); #if 0 /* DEBUG */ SERIAL_WRITE_STRING("dac_set:"); serial_write(uint32_to_string((uint32_t)pload_current), 8); SERIAL_WRITE_STRING("\r\n"); #endif /* DEBUG */ pload_tick_count = (uint32_t)pload_msg.u.steps.arg1[pload_step_index]; break ; } case PLOAD_STEP_OP_WAIT: { pload_tick_count = (uint32_t)pload_msg.u.steps.arg1[pload_step_index]; break ; } case PLOAD_STEP_OP_REPEAT: { const int32_t repeat_count = pload_msg.u.steps.arg0[pload_step_index]; if ((++pload_repeat_index) == (uint32_t)repeat_count) { #if 0 /* DEBUG */ SERIAL_WRITE_STRING("stopping\r\n"); #endif /* DEBUG */ pit_stop(1); goto on_done; } if (repeat_count == -1) { pload_repeat_index = 0; } /* next step */ pload_step_index = 0; goto const_case; break ; } default: break ; } on_done: pit_clear_int(1); }
int main(void) { uint32_t msize; uint32_t rsize; #ifdef DAC_USE_VREF vref_setup(); #endif /* DAC_USE_VREF */ dac_setup(); dac_enable(); serial_setup(); msize = 0; while (1) { rsize = serial_get_rsize(); if (rsize > (sizeof(pload_msg) - msize)) rsize = sizeof(pload_msg) - msize; if (rsize == 0) continue ; /* stop the generator if active */ if (pload_flags & PLOAD_FLAG_IS_STARTED) { #if 0 /* DEBUG */ SERIAL_WRITE_STRING("stopping\r\n"); #endif /* DEBUG */ pload_flags &= ~PLOAD_FLAG_IS_STARTED; pit_stop(1); } serial_read((uint8_t*)&pload_msg + msize, rsize); msize += rsize; if (msize != sizeof(pload_msg)) continue ; /* new message */ msize = 0; if (pload_msg.op != PLOAD_MSG_OP_SET_STEPS) continue ; /* start the generator */ if ((pload_flags & PLOAD_FLAG_IS_STARTED) == 0) { #if 0 /* DEBUG */ SERIAL_WRITE_STRING("starting\r\n"); #endif /* DEBUG */ pload_step_index = 0; pload_tick_count = (uint32_t)pload_msg.u.steps.arg1[0]; pload_repeat_index = 0; pload_current = (int32_t)pload_msg.u.steps.arg0[0]; dac_set(ma_to_dac((uint32_t)pload_current)); #if 0 /* DEBUG */ SERIAL_WRITE_STRING("dac_set:"); serial_write(uint32_to_string((uint32_t)pload_current), 8); SERIAL_WRITE_STRING("\r\n"); #endif /* DEBUG */ pload_flags |= PLOAD_FLAG_IS_STARTED; pit_start(1, F_BUS / PLOAD_CLOCK_FREQ); } } return 0; }
/** * Writes the browse host data of the context ``ctx'' to the buffer * ``dest''. This must be called multiple times to retrieve the complete * data until zero is returned i.e., the end of file is reached. * * This routine deals with HTML data generation. * * @param ctx an initialized browse host context. * @param dest the destination buffer. * @param size the amount of bytes ``dest'' can hold. * * @return -1 on failure, zero at the end-of-file condition or if size * was zero. On success, the amount of bytes copied to ``dest'' * is returned. */ static ssize_t browse_host_read_html(struct special_upload *ctx, void *const dest, size_t size) { static const char header[] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\r\n" "<html>\r\n" "<head>\r\n" "<title>Browse Host</title>\r\n" "</head>\r\n" "<body>\r\n"; static const char trailer[] = "</ul>\r\n</body>\r\n</html>\r\n"; struct browse_host_upload *bh = cast_to_browse_host_upload(ctx); char *p = dest; g_assert(NULL != bh); g_assert(NULL != dest); g_assert(size <= INT_MAX); g_assert(UNSIGNED(bh->state) < NUM_BH_STATES); g_assert(bh->b_size <= INT_MAX); g_assert(bh->b_offset <= bh->b_size); do { switch (bh->state) { case BH_STATE_HEADER: if (!bh->b_data) { bh->b_data = header; bh->b_size = CONST_STRLEN(header); } p += browse_host_read_data(bh, p, &size); if (bh->b_size == bh->b_offset) browse_host_next_state(bh, BH_STATE_LIBRARY_INFO); break; case BH_STATE_LIBRARY_INFO: if (!bh->b_data) { bh->w_buf_size = w_concat_strings(&bh->w_buf, "<h1>", product_get_name(), "</h1>\r\n" "<h3>", version_get_string(), " sharing ", uint64_to_string(shared_files_scanned()), " file", shared_files_scanned() == 1 ? "" : "s", " ", short_kb_size(shared_kbytes_scanned(), GNET_PROPERTY(display_metric_units)), " total</h3>\r\n" "<ul>\r\n", (void *) 0); bh->b_data = bh->w_buf; bh->b_size = bh->w_buf_size - 1; /* minus trailing NUL */ bh->b_offset = 0; } p += browse_host_read_data(bh, p, &size); if (bh->b_size == bh->b_offset) browse_host_next_state(bh, BH_STATE_FILES); break; case BH_STATE_TRAILER: if (!bh->b_data) { bh->b_data = trailer; bh->b_size = CONST_STRLEN(trailer); } p += browse_host_read_data(bh, p, &size); if (bh->b_size == bh->b_offset) browse_host_next_state(bh, BH_STATE_EOF); break; case BH_STATE_FILES: if (bh->b_data && bh->b_size == bh->b_offset) { g_assert(bh->w_buf == bh->b_data); wfree(bh->w_buf, bh->w_buf_size); bh->w_buf = NULL; bh->w_buf_size = 0; bh->b_data = NULL; } if (!bh->b_data) { const shared_file_t *sf; bh->file_index++; sf = shared_file_sorted(bh->file_index); if (!sf) { if (bh->file_index > shared_files_scanned()) browse_host_next_state(bh, BH_STATE_TRAILER); /* Skip holes in the file_index table */ } else if (SHARE_REBUILDING == sf) { browse_host_next_state(bh, BH_STATE_REBUILDING); } else { const char * const name_nfc = shared_file_name_nfc(sf); const filesize_t file_size = shared_file_size(sf); size_t html_size; char *html_name; { const char *dir; char *name; dir = shared_file_relative_path(sf); if (dir) { name = h_strconcat(dir, "/", name_nfc, (void *) 0); } else { name = deconstify_char(name_nfc); } html_size = 1 + html_escape(name, NULL, 0); html_name = walloc(html_size); html_escape(name, html_name, html_size); if (name != name_nfc) { HFREE_NULL(name); } } if (sha1_hash_available(sf)) { const struct sha1 *sha1 = shared_file_sha1(sf); bh->w_buf_size = w_concat_strings(&bh->w_buf, "<li><a href=\"/uri-res/N2R?urn:sha1:", sha1_base32(sha1), "\">", html_name, "</a> [", short_html_size(file_size, GNET_PROPERTY(display_metric_units)), "]</li>\r\n", (void *) 0); } else { char *escaped; escaped = url_escape(name_nfc); bh->w_buf_size = w_concat_strings(&bh->w_buf, "<li><a href=\"/get/", uint32_to_string(shared_file_index(sf)), "/", escaped, "\">", html_name, "</a>" " [", short_html_size(file_size, GNET_PROPERTY(display_metric_units)), "]</li>\r\n", (void *) 0); if (escaped != name_nfc) { HFREE_NULL(escaped); } } wfree(html_name, html_size); bh->b_data = bh->w_buf; bh->b_size = bh->w_buf_size - 1; /* minus trailing NUL */ bh->b_offset = 0; } } if (bh->b_data) p += browse_host_read_data(bh, p, &size); break; case BH_STATE_REBUILDING: if (!bh->b_data) { static const char msg[] = "<li>" "<b>" "The library is currently being rebuild. Please, " "try again in a moment." "</b>" "</li>"; bh->b_data = msg; bh->b_size = CONST_STRLEN(msg); } p += browse_host_read_data(bh, p, &size); if (bh->b_size == bh->b_offset) browse_host_next_state(bh, BH_STATE_TRAILER); break; case BH_STATE_EOF: return p - cast_to_char_ptr(dest); case NUM_BH_STATES: g_assert_not_reached(); } } while (size > 0); return p - cast_to_char_ptr(dest); }
static void cell_renderer(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer udata) { const struct result_data *data; const struct results_set *rs; const gchar *text; enum c_sr_columns id; if (!gtk_tree_view_column_get_visible(column)) return; text = NULL; /* default to nothing */ id = GPOINTER_TO_UINT(udata); data = get_result_data(model, iter); rs = data->record->results_set; switch (id) { case c_sr_filename: text = data->record->utf8_name; break; case c_sr_ext: text = data->record->ext; break; case c_sr_mime: text = mime_type_to_string(mime_type_from_extension(data->record->ext)); break; case c_sr_vendor: if (!(ST_LOCAL & rs->status)) text = vendor_code_get_name(rs->vendor); break; case c_sr_info: text = data->record->info; break; case c_sr_size: text = compact_size(data->record->size, show_metric_units()); break; case c_sr_count: text = data->children ? uint32_to_string(1 + data->children) : NULL; break; case c_sr_loc: if (ISO3166_INVALID != rs->country) text = iso3166_country_cc(rs->country); break; case c_sr_charset: if (!(ST_LOCAL & rs->status)) text = data->record->charset; break; case c_sr_route: text = search_gui_get_route(rs); break; case c_sr_protocol: if (!((ST_LOCAL | ST_BROWSE) & rs->status)) text = ST_UDP & rs->status ? (ST_SR_UDP & rs->status ? N_("UDP (semi-reliable)") : "UDP") : "TCP"; break; case c_sr_hops: if (!((ST_LOCAL | ST_BROWSE) & rs->status)) text = uint32_to_string(rs->hops); break; case c_sr_ttl: if (!((ST_LOCAL | ST_BROWSE) & rs->status)) text = uint32_to_string(rs->ttl); break; case c_sr_spam: if (SR_SPAM & data->record->flags) { text = "S"; /* Spam */ } else if (ST_SPAM & rs->status) { text = "maybe"; /* maybe spam */ } break; case c_sr_owned: if (SR_OWNED & data->record->flags) { text = _("owned"); } else if (SR_PARTIAL & data->record->flags) { text = _("partial"); } else if (SR_SHARED & data->record->flags) { text = _("shared"); } break; case c_sr_hostile: if (ST_HOSTILE & rs->status) { text = "H"; } break; case c_sr_sha1: if (data->record->sha1) { text = sha1_base32(data->record->sha1); } break; case c_sr_ctime: if ((time_t) -1 != data->record->create_time) { text = timestamp_to_string(data->record->create_time); } break; case c_sr_num: g_assert_not_reached(); break; } g_object_set(cell, "text", text, "foreground-gdk", gui_color_get(data->color), "background-gdk", gui_color_get(GUI_COLOR_BACKGROUND), (void *) 0); }