void prune_tree(struct base_tree_node *n, int fasta_id) { if (n->A != NULL) { if (n->A->fasta_id < fasta_id) { remove_subtree(n->A); n->A = NULL; } else { prune_tree(n->A, fasta_id); } } if (n->C != NULL) { if (n->C->fasta_id < fasta_id) { remove_subtree(n->C); n->C = NULL; } else { prune_tree(n->C, fasta_id); } } if (n->G != NULL) { if (n->G->fasta_id < fasta_id) { remove_subtree(n->G); n->G = NULL; } else { prune_tree(n->G, fasta_id); } } if (n->T != NULL) { if (n->T->fasta_id < fasta_id) { remove_subtree(n->T); n->T = NULL; } else { prune_tree(n->T, fasta_id); } } }
bool PulseSink::on_shmdata_disconnect() { pmanage<MPtr(&PContainer::enable)>(devices_enum_id_); prune_tree(".shmdata.reader." + shmpath_); shm_sub_.reset(); On_scope_exit { gst_pipeline_ = std::make_unique<GstPipeliner>(nullptr, nullptr); }; return remake_elements(); }
bool GTKVideo::on_shmdata_disconnect() { prune_tree(".shmdata.reader." + shmpath_); shm_sub_.reset(); On_scope_exit{gst_pipeline_ = std2::make_unique<GstPipeliner>(nullptr, [this](GstMessage *msg){ return this->bus_sync(msg); });}; return remake_elements(); }
bool PulseSrc::stop() { shm_sub_.reset(nullptr); prune_tree(".shmdata.writer." + shmpath_); pmanage<MPtr(&PContainer::remove)>(volume_id_); volume_id_ = 0; pmanage<MPtr(&PContainer::remove)>(mute_id_); mute_id_ = 0; if (!remake_elements()) return false; volume_id_ = pmanage<MPtr(&PContainer::push)>( "volume", GPropToProp::to_prop(G_OBJECT(pulsesrc_.get_raw()), "volume")); mute_id_ = pmanage<MPtr(&PContainer::push)>( "mute", GPropToProp::to_prop(G_OBJECT(pulsesrc_.get_raw()), "mute")); gst_pipeline_ = std::make_unique<GstPipeliner>(nullptr, nullptr); return true; }
void HTTPSDPDec::uri_to_shmdata() { destroy_httpsdpdec(); prune_tree(".shmdata.writer"); init_httpsdpdec(); g_object_set_data( G_OBJECT(sdpdemux_.get_raw()), "on-error-gsource", (gpointer)on_error_.back().get()); g_debug("httpsdpdec: to_shmdata set uri %s", uri_.c_str()); if (!is_dataurisrc_) // for souphttpsrc g_object_set(G_OBJECT(souphttpsrc_.get_raw()), "location", uri_.c_str(), nullptr); else // for dataurisrc g_object_set(G_OBJECT(souphttpsrc_.get_raw()), "uri", uri_.c_str(), nullptr); gst_bin_add_many( GST_BIN(gst_pipeline_->get_pipeline()), souphttpsrc_.get_raw(), sdpdemux_.get_raw(), nullptr); gst_element_link(souphttpsrc_.get_raw(), sdpdemux_.get_raw()); gst_pipeline_->play(true); }
void go(void) { prune_tree(rootNode); // Generate move tree //printf("[DEBUG] Building move tree\n"); build_move_tree(rootNode, 0, board, isWhitesMove, 0); // display_move_tree(rootNode, 0); // Work out optimal moves from move tree //printf("[DEBUG] Parsing move tree\n"); find_best_move(); //printf("[DEBUG] Displaying best move\n"); uci_bestmove(); // Clean up // printf("[DEBUG] Cleanup\n"); // prune_tree(rootNode); }
int main(void) { FILE *f = fopen("data", "r"); if (f == NULL) { puts("Failed to open data file"); return 1; } struct fasta_list fastas; fastas.head = NULL; fastas.current_node = NULL; ssize_t chars_read; char *current_line = NULL; size_t current_line_alloc = 0; while ((chars_read = getline(¤t_line, ¤t_line_alloc, f)) > -1) { //printf("READ FROM FILE: %s\n", current_line); if (*current_line == '>') { // fasta name - skip '>' character char *name = malloc((chars_read-1)*sizeof(char)); if (sscanf(current_line, ">%s\n", name) != 1) { puts("Failed to read line name"); return 1; } //printf("%s\n", name); struct fasta_node *fn = new_fasta_node(name); if (fastas.head == NULL) { // first entry fastas.current_node = fastas.head = fn; } else if (fastas.current_node->fasta.dna.len == 0) { puts("Found title line but current fasta is empty"); return 1; } else { //printf("%s: %s", fastas.current_node->fasta.name, fastas.current_node->fasta.dna.data); fastas.current_node = fastas.current_node->next = fn; } } else { //printf("Adding chars to %s: %s", fastas.current_node->fasta.name, current_line); if (current_line[chars_read] == '\0' && current_line[chars_read-1] == '\n') { current_line[chars_read-1] = '\0'; } else { puts("Failed end of dna string newline replacement"); return 1; } append_chars(&(fastas.current_node->fasta.dna), current_line); } } free(current_line); fclose(f); struct base_tree_node *base = new_base_tree_node("", ""); struct fasta_node *fn = fastas.head; int fasta_id = 0; while (fn != NULL) { //printf("%s\n%s\n", fn->fasta.name, fn->fasta.dna.data); char *start = fn->fasta.dna.data; while (*start != '\0') { //printf("next substring: %s\n", start); suffix_tree_add(start, base, fasta_id); start++; } prune_tree(base, fasta_id); fn = fn->next; fasta_id++; } char *longest = NULL; int longest_level=-1; find_longest_substring(base, 0, &longest, &longest_level); printf("%s\n", longest); remove_subtree(base); free_fasta_nodes(&fastas); }
void apply_scheme(FENC_SCHEME_TYPE scheme, char *public_params, char *data, char *outfile) { FENC_ERROR result; fenc_context context; fenc_group_params group_params; fenc_global_params global_params; fenc_function_input func_input; fenc_ciphertext ciphertext; fenc_key master_key; pairing_t pairing; FILE *fp; char *public_params_buf = NULL, *scheme_text = NULL; char session_key[SESSION_KEY_LEN]; fenc_plaintext rec_session_key; size_t serialized_len; clock_t start, stop; uint32 num_leaves; fenc_attribute_policy *parsed_policy = NULL; fenc_attribute_list *parsed_attributes = NULL; memset(&context, 0, sizeof(fenc_context)); memset(&group_params, 0, sizeof(fenc_group_params)); memset(&global_params, 0, sizeof(fenc_global_params)); memset(&ciphertext, 0, sizeof(fenc_ciphertext)); memset(&master_key, 0, sizeof(fenc_key)); /* Initialize the library. */ result = libfenc_init(); report_error("Initializing library", result); /* Create a Sahai-Waters context. */ result = libfenc_create_context(&context, scheme); report_error("Creating context for Waters CP scheme", result); /* Load group parameters from a file. */ fp = fopen(PARAM, "r"); if (fp != NULL) { libfenc_load_group_params_from_file(&group_params, fp); libfenc_get_pbc_pairing(&group_params, pairing); } else { perror("Could not open type-d parameters file.\n"); return; } fclose(fp); /* Set up the global parameters. */ result = context.generate_global_params(&global_params, &group_params); result = libfenc_gen_params(&context, &global_params); /* Set up the publci parameters */ fp = fopen(public_params, "r"); if(fp != NULL) { size_t pub_len = read_file(fp, &public_params_buf); /* base-64 decode */ uint8 *bin_public_buf = NewBase64Decode((const char *) public_params_buf, pub_len, &serialized_len); /* Import the parameters from binary buffer: */ result = libfenc_import_public_params(&context, bin_public_buf, serialized_len); report_error("Importing public parameters", result); free(public_params_buf); free(bin_public_buf); } else { perror("Could not open public parameters\n"); return; } fclose(fp); if(scheme == FENC_SCHEME_LSW) { /* convert the list of attributes into a fenc_attribute_list structure */ parsed_attributes = (fenc_attribute_list *) malloc(sizeof(fenc_attribute_list)); fenc_buffer_to_attribute_list(&data, parsed_attributes); func_input.input_type = FENC_INPUT_ATTRIBUTE_LIST; func_input.scheme_input = (void *) parsed_attributes; /* store attribute list for future reference */ char attr_str[SIZE]; memset(attr_str, 0, SIZE); size_t attr_str_len; fenc_attribute_list_to_buffer((fenc_attribute_list*)(func_input.scheme_input), (uint8 *)attr_str, SIZE, &attr_str_len); printf("Attribute list: %s\n", attr_str); /* test */ num_leaves = 0; } else { //else if(scheme == FENC_SCHEME_WATERSCP) { /* encrypt under given policy */ // fenc_attribute_policy *parsed_policy = construct_test_policy2(); parsed_policy = (fenc_attribute_policy *) malloc(sizeof(fenc_attribute_policy)); memset(parsed_policy, 0, sizeof(fenc_attribute_policy)); fenc_policy_from_string(parsed_policy, data); func_input.input_type = FENC_INPUT_NM_ATTRIBUTE_POLICY; func_input.scheme_input = (void *) parsed_policy; /* store the policy for future reference */ char policy_str[SIZE]; memset(policy_str, 0, SIZE); fenc_attribute_policy_to_string(parsed_policy->root, policy_str, SIZE); printf("POLICY => '%s'\n", policy_str); } /* perform encryption */ result = libfenc_kem_encrypt(&context, &func_input, SESSION_KEY_LEN, (uint8 *) session_key, &ciphertext); printf("Decryption key:\t"); print_buffer_as_hex((uint8 *)session_key, SESSION_KEY_LEN); /* now perform decryption with session key */ if(scheme == FENC_SCHEME_LSW) { printf("Successful import => '%d'\n", get_key(kp_abe_priv_keyfile, &context, &master_key)); fenc_key_LSW *key_LSW = (fenc_key_LSW *) master_key.scheme_key; num_leaves = prune_tree(key_LSW->policy->root, parsed_attributes); scheme_text = "KP"; } else if(scheme == FENC_SCHEME_WATERSCP) { printf("Successful import => '%d'\n", get_key(cp_abe_priv_keyfile, &context, &master_key)); fenc_key_WatersCP *key_WatersCP = (fenc_key_WatersCP *) master_key.scheme_key; num_leaves = prune_tree(parsed_policy->root, &(key_WatersCP->attribute_list)); scheme_text = "CP"; } else { printf("Successful import => '%d'\n", get_key(scp_abe_priv_keyfile, &context, &master_key)); fenc_key_WatersSimpleCP *key_WatersSimpleCP = (fenc_key_WatersSimpleCP *) master_key.scheme_key; num_leaves = prune_tree(parsed_policy->root, &(key_WatersSimpleCP->attribute_list)); scheme_text = "SCP"; } printf("Start timer.\n"); /* start timer */ start = clock(); /* Descrypt the resulting ciphertext. */ result = libfenc_decrypt(&context, &ciphertext, &master_key, &rec_session_key); /* stop timer */ stop = clock(); printf("Stop timer.\n"); double diff = ((double)(stop - start))/CLOCKS_PER_SEC; printf("Recovered session key:\t"); print_buffer_as_hex(rec_session_key.data, rec_session_key.data_len); if(memcmp(rec_session_key.data, session_key, rec_session_key.data_len) == 0) { printf("\nDECRYPTION TIME => %f secs.\n", diff); printf("NUMBER OF LEAVES => %d\n", num_leaves); fp = fopen(outfile, "a"); fprintf(fp, "%s:%d:%f\n", scheme_text, num_leaves, diff); fclose(fp); } if(parsed_attributes != NULL) free(parsed_attributes); if(parsed_policy != NULL) free(parsed_policy); /* Shutdown the library. */ result = libfenc_shutdown(); report_error("Shutting down library", result); }