void free_global_memory_packet_assembly() { _stop_packet_assembly_thread = 1; while (!_packet_assembly_thread_stopped) { usleep(500); } free_packet_list(&_receive_packet_list); free_packet_list(&_to_send_packet_list); }
void ff_free_parser_state(AVFormatContext *s, AVParserState *state) { int i; AVParserStreamState *ss; if (!state) return; for (i = 0; i < state->nb_streams; i++) { ss = &state->stream_states[i]; if (ss->parser) av_parser_close(ss->parser); av_free_packet(&ss->cur_pkt); } free_packet_list(state->packet_buffer); free_packet_list(state->raw_packet_buffer); av_free(state->stream_states); av_free(state); }
/** * iterate_keys - call a function once for each key in the db. * @iterfunc: The function to call. * @ctx: A context pointer * * Calls iterfunc once for each key in the database. ctx is passed * unaltered to iterfunc. This function is intended to aid database dumps * and statistic calculations. * * Returns the number of keys we iterated over. */ static int keyd_iterate_keys(struct onak_dbctx *dbctx, void (*iterfunc)(void *ctx, struct openpgp_publickey *key), void *ctx) { int keyd_fd = (intptr_t) dbctx->priv; struct buffer_ctx keybuf; struct openpgp_packet_list *packets = NULL; struct openpgp_publickey *key = NULL; ssize_t bytes = 0; ssize_t count = 0; int numkeys = 0; if (keyd_send_cmd(keyd_fd, KEYD_CMD_KEYITER)) { keybuf.offset = 0; read(keyd_fd, &keybuf.size, sizeof(keybuf.size)); while (keybuf.size > 0) { keybuf.buffer = malloc(keybuf.size); bytes = count = 0; logthing(LOGTHING_TRACE, "Getting %d bytes of key data.", keybuf.size); while (bytes >= 0 && count < keybuf.size) { bytes = read(keyd_fd, &keybuf.buffer[count], keybuf.size - count); logthing(LOGTHING_TRACE, "Read %d bytes.", bytes); count += bytes; } read_openpgp_stream(buffer_fetchchar, &keybuf, &packets, 0); parse_keys(packets, &key); if (iterfunc != NULL && key != NULL) { iterfunc(ctx, key); } free_publickey(key); key = NULL; free_packet_list(packets); packets = NULL; free(keybuf.buffer); keybuf.buffer = NULL; keybuf.size = keybuf.offset = 0; numkeys++; read(keyd_fd, &keybuf.size, sizeof(keybuf.size)); } } return numkeys; }
static int keyd_fetch_key_fp(struct onak_dbctx *dbctx, struct openpgp_fingerprint *fingerprint, struct openpgp_publickey **publickey, bool intrans) { int keyd_fd = (intptr_t) dbctx->priv; struct buffer_ctx keybuf; struct openpgp_packet_list *packets = NULL; ssize_t bytes = 0; ssize_t count = 0; uint8_t size; if (fingerprint->length > MAX_FINGERPRINT_LEN) { return 0; } if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET_FP)) { size = fingerprint->length; write(keyd_fd, &size, sizeof(size)); write(keyd_fd, fingerprint->fp, size); keybuf.offset = 0; read(keyd_fd, &keybuf.size, sizeof(keybuf.size)); if (keybuf.size > 0) { keybuf.buffer = malloc(keybuf.size); bytes = count = 0; logthing(LOGTHING_TRACE, "Getting %d bytes of key data.", keybuf.size); while (bytes >= 0 && count < keybuf.size) { bytes = read(keyd_fd, &keybuf.buffer[count], keybuf.size - count); logthing(LOGTHING_TRACE, "Read %d bytes.", bytes); count += bytes; } read_openpgp_stream(buffer_fetchchar, &keybuf, &packets, 0); parse_keys(packets, publickey); free_packet_list(packets); packets = NULL; free(keybuf.buffer); keybuf.buffer = NULL; keybuf.size = 0; } } return (count > 0) ? 1 : 0; }
/** * store_key - Takes a key and stores it. * @publickey: A pointer to the public key to store. * @intrans: If we're already in a transaction. * @update: If true the key exists and should be updated. * * This function stores a public key in whatever storage mechanism we are * using. intrans indicates if we're already in a transaction so don't * need to start one. update indicates if the key already exists and is * just being updated. * * TODO: Do we store multiple keys of the same id? Or only one and replace * it? */ static int keyd_store_key(struct onak_dbctx *dbctx, struct openpgp_publickey *publickey, bool intrans, bool update) { int keyd_fd = (intptr_t) dbctx->priv; struct buffer_ctx keybuf; struct openpgp_packet_list *packets = NULL; struct openpgp_packet_list *list_end = NULL; struct openpgp_publickey *next = NULL; uint64_t keyid; enum keyd_ops cmd = KEYD_CMD_STORE; if (get_keyid(publickey, &keyid) != ONAK_E_OK) { logthing(LOGTHING_ERROR, "Couldn't find key ID for key."); return 0; } if (update) { cmd = KEYD_CMD_UPDATE; } if (keyd_send_cmd(keyd_fd, cmd)) { keybuf.offset = 0; keybuf.size = 8192; keybuf.buffer = malloc(keybuf.size); next = publickey->next; publickey->next = NULL; flatten_publickey(publickey, &packets, &list_end); publickey->next = next; write_openpgp_stream(buffer_putchar, &keybuf, packets); logthing(LOGTHING_TRACE, "Sending %d bytes.", keybuf.offset); write(keyd_fd, &keybuf.offset, sizeof(keybuf.offset)); write(keyd_fd, keybuf.buffer, keybuf.offset); free_packet_list(packets); packets = list_end = NULL; free(keybuf.buffer); keybuf.buffer = NULL; keybuf.size = keybuf.offset = 0; } return 0; }
/** * fetch_key_text - Trys to find the keys that contain the supplied text. * @search: The text to search for. * @publickey: A pointer to a structure to return the key in. * * This function searches for the supplied text and returns the keys that * contain it. */ static int keyd_fetch_key_text(struct onak_dbctx *dbctx, const char *search, struct openpgp_publickey **publickey) { int keyd_fd = (intptr_t) dbctx->priv; struct buffer_ctx keybuf; struct openpgp_packet_list *packets = NULL; ssize_t bytes = 0; ssize_t count = 0; if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET_TEXT)) { bytes = strlen(search); write(keyd_fd, &bytes, sizeof(bytes)); write(keyd_fd, search, bytes); keybuf.offset = 0; read(keyd_fd, &keybuf.size, sizeof(keybuf.size)); if (keybuf.size > 0) { keybuf.buffer = malloc(keybuf.size); bytes = count = 0; logthing(LOGTHING_TRACE, "Getting %d bytes of key data.", keybuf.size); while (bytes >= 0 && count < keybuf.size) { bytes = read(keyd_fd, &keybuf.buffer[count], keybuf.size - count); logthing(LOGTHING_TRACE, "Read %d bytes.", bytes); count += bytes; } read_openpgp_stream(buffer_fetchchar, &keybuf, &packets, 0); parse_keys(packets, publickey); free_packet_list(packets); packets = NULL; free(keybuf.buffer); keybuf.buffer = NULL; keybuf.size = 0; } } return (count > 0) ? 1 : 0; return 0; }
DNSSession :: ~ DNSSession() { //PR_ASSERT(awake); PR_DestroyCondVar(cvar); PR_DestroyLock(lock); hostname = "grmblll"; free_packet_list(); PRInt32 host_cnt = 0; while (re_he.h_addr_list[host_cnt]) { free(re_he.h_addr_list[host_cnt++]); } if (re_he.h_name) { free(re_he.h_name); } ar_free_hostent(&ar_host, 0); }
void marshal_publickey(int (*putchar_func)(void *ctx, size_t count, void *c), void *ctx, const struct openpgp_publickey *key) { uint32_t len; struct openpgp_packet_list *packets = NULL, *list_end = NULL; struct buffer_ctx buf; buf.buffer = calloc(1, 1024); buf.size = 1024; buf.offset = 0; flatten_publickey((struct openpgp_publickey *) key, &packets, &list_end); write_openpgp_stream(buffer_putchar, &buf, packets); len = htonl(buf.offset); putchar_func(ctx, sizeof(len), &len); putchar_func(ctx, buf.offset, buf.buffer); free_packet_list(packets); }