static void write_value(io::stream& e, const void* object, const bsreq* req, int level) { if(req->type == number_type) { auto value = req->get(object); e << value; } else if(req->type == text_type) { auto value = (const char*)req->get(object); e << "\"" << value << "\""; } else if(req->reference) { auto value = (const void*)req->get(object); write_key(e, value, req->type); } else if(req->isenum) { auto value = req->get(object); auto pd = bsdata::find(req->type); if(pd) write_key(e, pd->get(value), req->type); else e << value; } else { if(level > 0) e << "("; auto count = 0; for(auto f = req->type; *f; f++) { if(count) e << ", "; write_array(e, object, f, level + 1); count++; } if(level > 0) e << ")"; } }
static bool_t audpl_save (const char * path, VFSFile * file, const char * title, Index * filenames, Index * tuples) { if (! write_key (file, "title", title)) return FALSE; int count = index_count (filenames); for (int i = 0; i < count; i ++) { if (! write_key (file, "uri", index_get (filenames, i))) return FALSE; const Tuple * tuple = tuples ? index_get (tuples, i) : NULL; if (tuple) { int keys = 0; for (int f = 0; f < TUPLE_FIELDS; f ++) { if (f == FIELD_FILE_PATH || f == FIELD_FILE_NAME || f == FIELD_FILE_EXT) continue; TupleValueType type = tuple_get_value_type (tuple, f, NULL); if (type == TUPLE_STRING) { char * str = tuple_get_str (tuple, f, NULL); if (! write_key (file, tuple_field_get_name (f), str)) { str_unref (str); return FALSE; } str_unref (str); keys ++; } else if (type == TUPLE_INT) { char buf[32]; snprintf (buf, sizeof buf, "%d", tuple_get_int (tuple, f, NULL)); if (! write_key (file, tuple_field_get_name (f), buf)) return FALSE; keys ++; } } /* distinguish between an empty tuple and no tuple at all */ if (! keys && ! write_key (file, "empty", "1")) return FALSE; } } return TRUE; }
gboolean ostree_bootconfig_parser_write (OstreeBootconfigParser *self, GFile *output, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GHashTableIter hashiter; gpointer hashkey, hashvalue; GString *buf = g_string_new (""); gs_unref_bytes GBytes *bytes = NULL; guint i; gs_unref_hashtable GHashTable *written_overrides = NULL; written_overrides = g_hash_table_new (g_str_hash, g_str_equal); for (i = 0; i < self->lines->len; i++) { GVariant *linedata = self->lines->pdata[i]; const char *key; const char *value; const char *line; g_variant_get (linedata, "(&s&s)", &key, &line); value = g_hash_table_lookup (self->options, key); if (value == NULL) { g_string_append (buf, line); g_string_append_c (buf, '\n'); } else { write_key (self, buf, key, value); g_hash_table_insert (written_overrides, (gpointer)key, (gpointer)key); } } g_hash_table_iter_init (&hashiter, self->options); while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue)) { if (g_hash_table_lookup (written_overrides, hashkey)) continue; write_key (self, buf, hashkey, hashvalue); } bytes = g_string_free_to_bytes (buf); buf = NULL; if (!ot_gfile_replace_contents_fsync (output, bytes, cancellable, error)) goto out; ret = TRUE; out: if (buf) g_string_free (buf, TRUE); return ret; }
gboolean ostree_bootconfig_parser_write_at (OstreeBootconfigParser *self, int dfd, const char *path, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; GHashTableIter hashiter; gpointer hashkey, hashvalue; GString *buf = g_string_new (""); guint i; g_autoptr(GHashTable) written_overrides = NULL; written_overrides = g_hash_table_new (g_str_hash, g_str_equal); for (i = 0; i < self->lines->len; i++) { GVariant *linedata = self->lines->pdata[i]; const char *key; const char *value; const char *line; g_variant_get (linedata, "(&s&s)", &key, &line); value = g_hash_table_lookup (self->options, key); if (value == NULL) { g_string_append (buf, line); g_string_append_c (buf, '\n'); } else { write_key (self, buf, key, value); g_hash_table_add (written_overrides, (gpointer)key); } } g_hash_table_iter_init (&hashiter, self->options); while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue)) { if (g_hash_table_lookup (written_overrides, hashkey)) continue; write_key (self, buf, hashkey, hashvalue); } if (!glnx_file_replace_contents_at (dfd, path, (guint8*)buf->str, buf->len, GLNX_FILE_REPLACE_NODATASYNC, cancellable, error)) goto out; ret = TRUE; out: if (buf) g_string_free (buf, TRUE); return ret; }
// Step #3: execute keystroke sequence // void usb_keyboard_class::write_keycode(KEYCODE_TYPE keycode) { if (!keycode) return; #ifdef DEADKEYS_MASK KEYCODE_TYPE deadkeycode = deadkey_to_keycode(keycode); if (deadkeycode) write_key(deadkeycode); #endif write_key(keycode); }
void usb_keyboard_write_unicode(uint16_t cpoint) { KEYCODE_TYPE keycode; keycode = unicode_to_keycode(cpoint); if (keycode) { #ifdef DEADKEYS_MASK KEYCODE_TYPE deadkeycode = deadkey_to_keycode(keycode); if (deadkeycode) write_key(deadkeycode); #endif write_key(keycode); } }
int newagent::account(const char * user, const char * password) { int res=0; #ifdef _WIN32 if (user) write_key("01",(LPBYTE)user,strlen((char*)user)+1); if (password) write_key("02",(LPBYTE)password,strlen((char*)password)+1); unmap_drive(); CloseHandle(server_user); server_user=0; logon(res); #endif return res; }
// Step #3: execute keystroke sequence // void usb_keyboard_class::write_keycode(KEYCODE_TYPE key) { if (!key) return; #ifdef DEADKEYS_MASK KEYCODE_TYPE deadkey = key & DEADKEYS_MASK; #ifdef ACUTE_ACCENT_BITS if (deadkey == ACUTE_ACCENT_BITS) write_key(DEADKEY_ACUTE_ACCENT); #endif #ifdef CEDILLA_BITS if (deadkey == CEDILLA_BITS) write_key(DEADKEY_CEDILLA); #endif #ifdef CIRCUMFLEX_BITS if (deadkey == CIRCUMFLEX_BITS) write_key(DEADKEY_CIRCUMFLEX); #endif #ifdef DIAERESIS_BITS if (deadkey == DIAERESIS_BITS) write_key(DEADKEY_DIAERESIS); #endif #ifdef GRAVE_ACCENT_BITS if (deadkey == GRAVE_ACCENT_BITS) write_key(DEADKEY_GRAVE_ACCENT); #endif #ifdef TILDE_BITS if (deadkey == TILDE_BITS) write_key(DEADKEY_TILDE); #endif #ifdef RING_ABOVE_BITS if (deadkey == RING_ABOVE_BITS) write_key(DEADKEY_RING_ABOVE); #endif #endif // DEADKEYS_MASK write_key(key); }
/* \brief Private helper. Common code for writing OBJECT & ARRAY signatures * * \param writer binson_writer* Context * \param key const char* Optional key. Use NULL to output ARRAY items * \param sig uint8_t Signature to specify type of OBJECT * \return binson_res Result code */ binson_res write_frame_sig( binson_writer *writer, const char* key, uint8_t sig ) { binson_res res = BINSON_RES_OK; /* Initial parameter validation */ if (!writer) return BINSON_RES_ERROR_ARG_WRONG; #ifdef WITH_BINSON_JSON_OUTPUT if (sig == BINSON_SIG_OBJ_END || sig == BINSON_SIG_ARRAY_END) { writer->depth--; writer->idx_stack[writer->depth]++; } #endif /* write key if needed */ res = write_key( writer, key, (sig == BINSON_SIG_OBJ_END || sig == BINSON_SIG_ARRAY_END)? true : false ); if (FAILED(res)) return res; #ifdef WITH_BINSON_JSON_OUTPUT /* Updating tracking vars for new nesting level */ if (sig == BINSON_SIG_OBJ_BEGIN || sig == BINSON_SIG_ARRAY_BEGIN) { writer->sig_stack[writer->depth] = sig; writer->depth++; writer->idx_stack[writer->depth] = 0; } else if (sig != BINSON_SIG_OBJ_END && sig != BINSON_SIG_ARRAY_END) { writer->idx_stack[writer->depth]++; } #endif switch (writer->format) { case BINSON_WRITER_FORMAT_RAW: res = binson_io_write_byte( writer->io, sig ); break; case BINSON_WRITER_FORMAT_HEX: res = binson_io_printf(writer->io, "%02x \n", sig ); break; #ifdef WITH_BINSON_JSON_OUTPUT case BINSON_WRITER_FORMAT_JSON: case BINSON_WRITER_FORMAT_JSON_NICE: res = binson_io_write_str( writer->io, sig == BINSON_SIG_OBJ_BEGIN? "{ ": (sig == BINSON_SIG_OBJ_END? "} " : (sig == BINSON_SIG_ARRAY_BEGIN? "[ " : (sig == BINSON_SIG_ARRAY_END? "] " : " "))), true ); if (FAILED(res)) return res; break; #endif default: return BINSON_RES_ERROR_ARG_WRONG; } return res; }
// Step #2: translate Unicode code point to keystroke sequence // void usb_keyboard_class::write_unicode(uint16_t cpoint) { // Unicode code points beyond U+FFFF are not supported // technically this input should probably be called UCS-2 if (cpoint < 32) { if (cpoint == 10) write_key(KEY_ENTER); return; } if (cpoint < 128) { if (sizeof(KEYCODE_TYPE) == 1) { write_keycode(pgm_read_byte(keycodes_ascii + (cpoint - 0x20))); } else if (sizeof(KEYCODE_TYPE) == 2) { write_keycode(pgm_read_word(keycodes_ascii + (cpoint - 0x20))); } return; } #ifdef ISO_8859_1_A0 if (cpoint <= 0xA0) return; if (cpoint < 0x100) { if (sizeof(KEYCODE_TYPE) == 1) { write_keycode(pgm_read_byte(keycodes_iso_8859_1 + (cpoint - 0xA0))); } else if (sizeof(KEYCODE_TYPE) == 2) { write_keycode(pgm_read_word(keycodes_iso_8859_1 + (cpoint - 0xA0))); } return; } #endif #ifdef UNICODE_20AC if (cpoint == 0x20AC) write_keycode(UNICODE_20AC); #endif }
/** \brief Write output to io for single \c int8_t .. \c int64_t value * with automatic type downgrade according to real bytes used * * \param writer binson_writer* Context * \param key const char* Optional key. Use NULL to output ARRAY items * \param val int64_t Integer argument * \return binson_res Result code */ binson_res binson_writer_write_integer( binson_writer *writer, const char* key, int64_t val ) { const uint8_t binson_int_map[] = { BINSON_SIG_INTEGER_8, /* for 0 bytes of int data */ BINSON_SIG_INTEGER_8, /* for 1 bytes of int data */ BINSON_SIG_INTEGER_16, /* for 2 bytes of int data */ BINSON_SIG_INTEGER_32, /* for 3 bytes of int data */ BINSON_SIG_INTEGER_32, /* for 4 bytes of int data */ BINSON_SIG_INTEGER_64, /* for 5 bytes of int data */ BINSON_SIG_INTEGER_64, /* for 6 bytes of int data */ BINSON_SIG_INTEGER_64, /* for 7 bytes of int data */ BINSON_SIG_INTEGER_64 }; /* for 8 bytes of int data */ binson_res res = BINSON_RES_OK; uint8_t bbuf[sizeof(int64_t)+1] = {0,0,0,0,0,0,0,0,0}; /* this initialization prevents aggressive optimization from breaking the code */ size_t bsize; unsigned int i; /* Initial parameter validation */ if (!writer) return BINSON_RES_ERROR_ARG_WRONG; /* write key if needed */ res = write_key( writer, key, false ); if (FAILED(res)) return res; #ifdef WITH_BINSON_JSON_OUTPUT writer->idx_stack[writer->depth]++; #endif /* Convert value to INTEGER primitive and store it in specified byte buffer */ bsize = binson_util_pack_integer( val, &bbuf[1] ); bbuf[0] = binson_int_map[bsize]; /* Format dependent output */ switch (writer->format) { case BINSON_WRITER_FORMAT_RAW: res = binson_io_write( writer->io, bbuf, bsize+1 ); break; case BINSON_WRITER_FORMAT_HEX: for (i=0; i<bsize+1; i++) res = binson_io_printf( writer->io, "%02x ", bbuf[i] ); res = binson_io_write_str( writer->io, "\n", true ); break; #ifdef WITH_BINSON_JSON_OUTPUT case BINSON_WRITER_FORMAT_JSON: case BINSON_WRITER_FORMAT_JSON_NICE: res = binson_io_printf( writer->io, "%ld", val ); /* \todo fix printing int64_t in C89 */ if (FAILED(res)) return res; break; #endif default: return BINSON_RES_ERROR_ARG_WRONG; } return res; }
static void write_const(Context* ctx, const WasmConst* const_) { wasm_writef(&ctx->json_stream, "{"); write_key(ctx, "type"); /* Always write the values as strings, even though they may be representable * as JSON numbers. This way the formatting is consistent. */ switch (const_->type) { case WASM_TYPE_I32: write_string(ctx, "i32"); write_separator(ctx); write_key(ctx, "value"); wasm_writef(&ctx->json_stream, "\"%u\"", const_->u32); break; case WASM_TYPE_I64: write_string(ctx, "i64"); write_separator(ctx); write_key(ctx, "value"); wasm_writef(&ctx->json_stream, "\"%" PRIu64 "\"", const_->u64); break; case WASM_TYPE_F32: { /* TODO(binji): write as hex float */ write_string(ctx, "f32"); write_separator(ctx); write_key(ctx, "value"); wasm_writef(&ctx->json_stream, "\"%u\"", const_->f32_bits); break; } case WASM_TYPE_F64: { /* TODO(binji): write as hex float */ write_string(ctx, "f64"); write_separator(ctx); write_key(ctx, "value"); wasm_writef(&ctx->json_stream, "\"%" PRIu64 "\"", const_->f64_bits); break; } default: assert(0); } wasm_writef(&ctx->json_stream, "}"); }
static void write_object(io::stream& e, const void* object) { auto pd = bsdata::findbyptr(object); if(!pd) return; e << "#" << pd->id << " "; auto skip = write_key(e, object, pd->fields); e << " "; write_fields(e, object, pd->fields, skip); }
static void write_action(Context* ctx, const WasmAction* action) { write_key(ctx, "action"); wasm_writef(&ctx->json_stream, "{"); write_key(ctx, "type"); if (action->type == WASM_ACTION_TYPE_INVOKE) { write_string(ctx, "invoke"); } else { assert(action->type == WASM_ACTION_TYPE_GET); write_string(ctx, "get"); } write_separator(ctx); if (action->module_var.type != WASM_VAR_TYPE_INDEX) { write_key(ctx, "module"); write_var(ctx, &action->module_var); write_separator(ctx); } if (action->type == WASM_ACTION_TYPE_INVOKE) { write_key(ctx, "field"); write_escaped_string_slice(ctx, action->invoke.name); write_separator(ctx); write_key(ctx, "args"); write_const_vector(ctx, &action->invoke.args); } else { write_key(ctx, "field"); write_escaped_string_slice(ctx, action->get.name); } wasm_writef(&ctx->json_stream, "}"); }
/** \brief Write STRING object to io * * \param writer binson_writer* Context * \param key const char* Optional key. Use NULL to output ARRAY items * \param str const char* Source string * \return binson_res Result code */ binson_res binson_writer_write_str( binson_writer *writer, const char* key, const char* str ) { binson_res res = BINSON_RES_OK; /* write key if needed */ res = write_key( writer, key, false ); if (FAILED(res)) return res; res = write_bytes( writer, (uint8_t *)str, str? strlen(str):0, BINSON_SIG_STRING_8 ); if (FAILED(res)) return res; return res; }
/** \brief Write BYTES object to io * * \param writer binson_writer* Context * \param key const char* Optional key. Use NULL to output ARRAY items * \param src_ptr uint8_t* Byte buffer * \param src_size size_t Size of data in byte buffer * \return binson_res Result code */ binson_res binson_writer_write_bytes( binson_writer *writer, const char* key, uint8_t *src_ptr, size_t src_size ) { binson_res res = BINSON_RES_OK; /* write key if needed */ res = write_key( writer, key, false ); if (FAILED(res)) return res; res = write_bytes( writer, (uint8_t *)src_ptr, src_size, BINSON_SIG_BYTES_8 ); if (FAILED(res)) return res; return res; }
/** \brief Write output to io for single \c double value * * \param writer binson_writer* Context * \param key const char* Optional key. Use NULL to output ARRAY items * \param val double Value * \return binson_res Result code */ binson_res binson_writer_write_double( binson_writer *writer, const char* key, double val ) { binson_res res = BINSON_RES_OK; uint8_t bbuf[sizeof(double)+1] = {0,0,0,0,0,0,0,0,0}; /* this initialization prevents aggressive optimization from breaking the code */ size_t i; /* Initial parameter validation */ if (!writer) return BINSON_RES_ERROR_ARG_WRONG; /* write key if needed */ res = write_key( writer, key, false ); if (FAILED(res)) return res; #ifdef WITH_BINSON_JSON_OUTPUT writer->idx_stack[writer->depth]++; #endif binson_util_pack_double( val, bbuf+1 ); bbuf[0] = BINSON_SIG_DOUBLE; /* Format dependent output */ switch (writer->format) { case BINSON_WRITER_FORMAT_RAW: res = binson_io_write( writer->io, bbuf, sizeof(double)+1 ); break; case BINSON_WRITER_FORMAT_HEX: for (i=0; i<sizeof(double)+1; i++) res = binson_io_printf( writer->io, "%02x ", bbuf[i] ); res = binson_io_write_str( writer->io, "\n", true ); break; #ifdef WITH_BINSON_JSON_OUTPUT case BINSON_WRITER_FORMAT_JSON: case BINSON_WRITER_FORMAT_JSON_NICE: res = binson_io_printf( writer->io, "%g", val ); if (FAILED(res)) return res; break; #endif default: return BINSON_RES_ERROR_ARG_WRONG; } return res; }
size_t rewriteHandlers(std::string &local, std::set<std::string> &handlersSets) { HKEY localClassesKey = NULL; if (RegOpenKeyExA(HKEY_USERS, local.c_str(), 0, KEY_READ | KEY_WRITE, &localClassesKey) != ERROR_SUCCESS) { return 0; } size_t added = 0; std::set<std::string>::iterator hItr; for (hItr = handlersSets.begin(); hItr != handlersSets.end(); hItr++) { std::string handlerName = *hItr; if (is_blacklisted(handlerName)) { continue; } if (!key_exist(localClassesKey, handlerName.c_str()) ) { BYTE path_buffer[MAX_KEY_LENGTH]; DWORD val_len = MAX_KEY_LENGTH; DWORD type;//RRF_RT_ANY std::string commandKey = handlerName + "\\shell\\open\\command"; printf("+%s\n", commandKey.c_str()); if (!read_key(HKEY_CLASSES_ROOT, commandKey, path_buffer, val_len, type)) { continue; } if (type != REG_SZ) { continue; } if (is_path_blacklisted((char*) path_buffer)) { printf("[BLACKLISTED] %s\n", path_buffer); continue; } // if (!write_key(localClassesKey, commandKey, path_buffer, val_len, type)) { continue; } printf("[+] %s\n", path_buffer); added++; } else { printf("Already exist: "); printf("%s\n", handlerName.c_str()); } } RegCloseKey(localClassesKey); return added; }
bool copy_key(HKEY srcBaseKey, HKEY dstBaseKey, std::string subKey) { BYTE path_buffer[MAX_KEY_LENGTH]; DWORD val_len = MAX_KEY_LENGTH; DWORD type;//RRF_RT_ANY size_t changed = 0; printf("+%s\n", subKey.c_str()); if (!read_key(srcBaseKey, subKey, path_buffer, val_len, type)) { return false; } // if (!write_key(dstBaseKey, subKey, path_buffer, val_len, type)) { return false; } return true; }
static void write_command_type(Context* ctx, const WasmCommand* command) { static const char* s_command_names[] = { "module", "action", "register", "assert_malformed", "assert_invalid", "assert_unlinkable", "assert_uninstantiable", "assert_return", "assert_return_nan", "assert_trap", }; WASM_STATIC_ASSERT(WASM_ARRAY_SIZE(s_command_names) == WASM_NUM_COMMAND_TYPES); write_key(ctx, "type"); write_string(ctx, s_command_names[command->type]); }
rc_t write_packed_to_lookup_writer( struct lookup_writer * writer, uint64_t key, const String * bases_as_packed_4na ) { size_t num_writ; /* first write the key ( combination of seq-id and read-id ) */ rc_t rc = KFileWriteAll( writer -> f, writer -> pos, &key, sizeof key, &num_writ ); if ( rc != 0 ) { ErrMsg( "KFileWriteAll( key ) -> %R", rc ); } else if ( num_writ != sizeof key ) { rc = RC( rcVDB, rcNoTarg, rcWriting, rcFormat, rcInvalid ); ErrMsg( "KFileWriteAll( key ) -> %R", rc ); } else { uint64_t start_pos = writer -> pos; /* store the pos to be written later to the index... */ writer -> pos += num_writ; /* now write the packed 4na ( length + packed data ) */ rc = KFileWriteAll( writer -> f, writer -> pos, bases_as_packed_4na -> addr, bases_as_packed_4na -> size, &num_writ ); if ( rc != 0 ) ErrMsg( "KFileWriteAll( bases ) -> %R", rc ); else if ( num_writ != bases_as_packed_4na -> size ) { rc = RC( rcVDB, rcNoTarg, rcWriting, rcFormat, rcInvalid ); ErrMsg( "KFileWriteAll( bases ) -> %R", rc ); } else { if ( writer -> idx != NULL ) rc = write_key( writer -> idx, key, start_pos ); writer->pos += num_writ; } } return rc; }
void keyboard_handler(registers r) { (void)r; u8 scancode = inb(0x60); // Read from the keyboard's data buffer if (scancode & 0x80) { // Key released // handle shift, alt, ctrl ... if (scancode == 0xB6 || scancode == 0xAA) { // Rshift or Lshift SHIFT_PRESSED = false; return; } } else { // Key pressed. If a key is hold down it repeats the key press interrupts if (scancode == 0x36 || scancode == 0x2A) { // Rshift or Lshift SHIFT_PRESSED = true; return; } write_key(scancode); } }
int newagent::set_map_dir(char * dir) { int res=0; #ifdef _WIN32 if (dir) write_key("03",(LPBYTE)dir,strlen((char*)dir)+1); do_map_drive(res); #else strcpy(cur_dir, dir); char *p, *c_d; c_d=cur_dir; for (p=dir; p<(dir+strlen(dir)); p++, c_d++) { if (*p == '\\') *p = '/'; else *p = *c_d; } *p = '\0'; #endif logfile("set_map_dir %s\n",dir); return res; }
/** \brief Write output to io for single bool value * * \param writer binson_writer* Context * \param key const char* Optional key. Use NULL to output ARRAY items * \param val bool Value * \return binson_res Result code */ binson_res binson_writer_write_boolean( binson_writer *writer, const char* key, bool val ) { binson_res res = BINSON_RES_OK; /* Initial parameter validation */ if (!writer) return BINSON_RES_ERROR_ARG_WRONG; /* write key if needed */ res = write_key( writer, key, false ); if (FAILED(res)) return res; #ifdef WITH_BINSON_JSON_OUTPUT writer->idx_stack[writer->depth]++; #endif switch (writer->format) { case BINSON_WRITER_FORMAT_RAW: res = binson_io_write_byte( writer->io, val? BINSON_SIG_TRUE : BINSON_SIG_FALSE ); break; case BINSON_WRITER_FORMAT_HEX: res = binson_io_printf( writer->io, "%02x \n", val? BINSON_SIG_TRUE : BINSON_SIG_FALSE); break; #ifdef WITH_BINSON_JSON_OUTPUT case BINSON_WRITER_FORMAT_JSON: case BINSON_WRITER_FORMAT_JSON_NICE: res = binson_io_printf( writer->io, "%s", val? "true" : "false" ); if (FAILED(res)) return res; break; #endif default: return BINSON_RES_ERROR_ARG_WRONG; } return res; }
bool btree_insert(btree * btree, btree_key_t key, btree_data_t datum) { // what we return bool result = false; // make sure the arguments make sense if (btree != NULL) { // search for the key btree_page * root = btree->m_root; if (root != NULL) { search_result insert_info = search(btree,root,key); write_key(btree,&insert_info,key,datum); ++btree->m_count; ++btree->m_ticker; result = true; } } // done return result; }
/************************************************************************* * *N write_next_row * *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * This function writes the next row of the table. * The parameter row must be initialized prior to this functional, either * by being read in from an existing table or set to valid values. * A row with any empty columns should not be written out. * The parameter table must be a valid table and initialized prior to * this function, by vpf_open_table. It is assumed that there is * enough free disk space to write to the file. It is also assumed that * the file pointer (table->fp) is already opened for writing. The * variable count, set to the values in row, must be greater than 0, * otherwise, if count is -1 the vpf_write functions will lock up * (row[].count should never have a value of 0). Note that if errorfp * is used, it must be opened prior to this function. * *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Parameters: *A * row <input> == (row_type) the row to write to the table. * table <input> == (vpf_table_type *) vpf table structure. *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Dave Flinn July 1991 Based on read_next_row. * Barry Michaels Oct 1991 Added row as a parameter. * JTB 10/91 guaranteed function always * returns a value: * 0: record written * -1: unknown field type *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * External Variables: *X * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Functions Called: *F * None *E *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Portability: *O * This module should be ANSI C compatible. *E *************************************************************************/ long int write_next_row(row_type row, vpf_table_type * table ) { register long int i, j; char * tptr, * output ; long int recordsize = 0; long int count; id_triplet_type * keys; unsigned long int pos_for_ndx, length; int retn_val = 0; coordinate_type dummycoord = {0.0,0.0}; STORAGE_BYTE_ORDER = table->byte_order; table->nrows++; fseek(table->fp, 0L, SEEK_END); pos_for_ndx = ftell(table->fp); /* begining of new row */ for (i = 0; i < table->nfields; i++) { /* for each column */ count = row[i].count ; /* Retrieve count from row. Should be 0 if variable length null */ /* In case this column is variable length, write out count */ if (count == 0) count = 1; if ( table->header[i].count < 0 ) { Write_Vpf_Int ( &count, table->fp, 1 ) ; recordsize += sizeof ( long int ) ; } /* Now write out the data type */ switch (table->header[i].type) { case 'T': if ( count == 0 ) /* Assume this is variable length text and don't do anything */ break ; /* This loop insures that the exact number of characters are written out to disk. */ output = (char *) vpfmalloc ( count + 1 ) ; /* include null byte */ for (j = 0, tptr = (char*)row[i].ptr; j < count; j++, tptr++) if ( *tptr ) output[j] = *tptr ; else output[j] = SPACE ; output[count] = '\0' ; Write_Vpf_Char( output ,table->fp, count) ; free ( output ) ; recordsize += sizeof ( char ) * count ; break; case 'I': Write_Vpf_Int (row[i].ptr, table->fp, count ) ; recordsize += sizeof ( long int ) * count ; break; case 'S': Write_Vpf_Short (row[i].ptr, table->fp, count ) ; recordsize += sizeof ( short int ) * count ; break; case 'F': Write_Vpf_Float (row[i].ptr, table->fp, count ) ; recordsize += sizeof ( float ) * count ; break; case 'R': Write_Vpf_Double (row[i].ptr, table->fp, count ) ; recordsize += sizeof ( double ) * count ; break; case 'D': /* date has 21 chars in memory, not on disk */ Write_Vpf_Date (row[i].ptr, table->fp, count ) ; recordsize += ( sizeof ( date_type ) - 1 ) * count ; break; case 'C': if (row[i].ptr) { Write_Vpf_Coordinate(row[i].ptr,table->fp,count); } else { for (j=0;j<count;j++) Write_Vpf_Coordinate(&dummycoord,table->fp,count); } recordsize += sizeof ( coordinate_type ) * count ; break; case 'B': Write_Vpf_DoubleCoordinate(row[i].ptr,table->fp,count); recordsize += sizeof ( double_coordinate_type ) * count ; break; case 'Z': Write_Vpf_CoordinateZ(row[i].ptr,table->fp,count); recordsize += sizeof ( tri_coordinate_type ) * count ; break; case 'Y': Write_Vpf_DoubleCoordinateZ(row[i].ptr,table->fp,count); recordsize += sizeof ( double_tri_coordinate_type ) * count ; break; case 'K': keys = (id_triplet_type *) vpfmalloc (count*sizeof(id_triplet_type)) ; memcpy ( keys, row[i].ptr, count*sizeof(id_triplet_type) ) ; for (j=0;j<count;j++) recordsize += write_key ( keys[j], table->fp); free ( keys ) ; break; case 'X': /* do nothing */ break; default: return(-1); } } if ( table->xfp ) { /* only for variable length columns */ length = recordsize ; fseek( table->xfp, 0, SEEK_END ); Write_Vpf_Int ( &pos_for_ndx, table->xfp, 1 ) ; Write_Vpf_Int ( &length, table->xfp, 1 ) ; } return retn_val; }
static void release_key (int code) { struct key key = { code, STATE_UP }; write_key (&key); }
static void press_key (int code) { struct key key = { code, STATE_DOWN }; write_key (&key); }
int main (int argc, char **argv) { gaainfo info; int ret; struct passwd *pwd; unsigned char key[MAX_KEY_SIZE]; char hex_key[MAX_KEY_SIZE * 2 + 1]; gnutls_datum_t dkey; size_t hex_key_size = sizeof (hex_key); if ((ret = gnutls_global_init ()) < 0) { fprintf (stderr, "global_init: %s\n", gnutls_strerror (ret)); exit (1); } umask (066); if (gaa (argc, argv, &info) != -1) { fprintf (stderr, "Error in the arguments.\n"); return -1; } if (info.passwd == NULL) info.passwd = KPASSWD; if (info.username == NULL) { #ifndef _WIN32 pwd = getpwuid (getuid ()); if (pwd == NULL) { fprintf (stderr, "No such user\n"); return -1; } info.username = pwd->pw_name; #else fprintf (stderr, "Please specify a user\n"); return -1; #endif } if (info.key_size > MAX_KEY_SIZE) { fprintf (stderr, "Key size is too long\n"); exit (1); } if (info.netconf_hint) { char *passwd; if (info.key_size != 0 && info.key_size != 20) { fprintf (stderr, "For netconf, key size must always be 20.\n"); exit (1); } passwd = getpass ("Enter password: "******"Please specify a password\n"); exit (1); } ret = gnutls_psk_netconf_derive_key (passwd, info.username, info.netconf_hint, &dkey); } else { if (info.key_size < 1) info.key_size = 16; printf ("Generating a random key for user '%s'\n", info.username); ret = _gnutls_rnd (GNUTLS_RND_RANDOM, (char *) key, info.key_size); if (ret < 0) { fprintf (stderr, "Not enough randomness\n"); exit (1); } dkey.data = key; dkey.size = info.key_size; } ret = gnutls_hex_encode (&dkey, hex_key, &hex_key_size); if (info.netconf_hint) gnutls_free (dkey.data); if (ret < 0) { fprintf (stderr, "HEX encoding error\n"); exit (1); } ret = write_key (info.username, hex_key, hex_key_size, info.passwd); if (ret == 0) printf ("Key stored to %s\n", info.passwd); return ret; }
int main (int argc, char **argv) { gaainfo info; int ret; #ifndef _WIN32 struct passwd *pwd; #endif unsigned char key[MAX_KEY_SIZE]; char hex_key[MAX_KEY_SIZE * 2 + 1]; gnutls_datum_t dkey; size_t hex_key_size = sizeof (hex_key); set_program_name (argv[0]); if ((ret = gnutls_global_init ()) < 0) { fprintf (stderr, "global_init: %s\n", gnutls_strerror (ret)); exit (1); } umask (066); if (gaa (argc, argv, &info) != -1) { fprintf (stderr, "Error in the arguments.\n"); return -1; } if (info.passwd == NULL) info.passwd = (char *) KPASSWD; if (info.username == NULL) { #ifndef _WIN32 pwd = getpwuid (getuid ()); if (pwd == NULL) { fprintf (stderr, "No such user\n"); return -1; } info.username = pwd->pw_name; #else fprintf (stderr, "Please specify a user\n"); return -1; #endif } if (info.key_size > MAX_KEY_SIZE) { fprintf (stderr, "Key size is too long\n"); exit (1); } if (info.key_size < 1) info.key_size = 16; printf ("Generating a random key for user '%s'\n", info.username); ret = gnutls_rnd (GNUTLS_RND_RANDOM, (char *) key, info.key_size); if (ret < 0) { fprintf (stderr, "Not enough randomness\n"); exit (1); } dkey.data = key; dkey.size = info.key_size; ret = gnutls_hex_encode (&dkey, hex_key, &hex_key_size); if (ret < 0) { fprintf (stderr, "HEX encoding error\n"); exit (1); } ret = write_key (info.username, hex_key, hex_key_size, info.passwd); if (ret == 0) printf ("Key stored to %s\n", info.passwd); return ret; }