예제 #1
0
파일: tools.c 프로젝트: xtools/xt
xt_core_bool_t xt_file_count_lines_in_file(char *filename,
    unsigned long *line_count)
{
  assert(filename);
  assert(line_count);
  xt_core_bool_t success;
  xt_file_basic_t *file;

  file = xt_file_basic_create(filename, XT_FILE_MODE_OPEN_FOR_READ);
  if (file) {
    success = xt_file_basic_get_line_count(file, line_count);
    xt_file_basic_destroy(file);
  } else {
    success = xt_core_bool_false;
    xt_core_trace("x_file_basic_create");
  }

  return success;
}
예제 #2
0
파일: ta.bin.c 프로젝트: talkanonymous/ta
int main(int argc, char *argv[])
{
  ta_system_t *ta_system;
  ta_server_t ta_server;
  xt_net_server_system_t *http_server;
  unsigned short http_server_min_port;
  unsigned short http_server_max_port;
  xt_net_engine_iengine_t http_iengine;
  xt_core_imessage_t http_imessage;
  xt_net_post_ipost_t http_ipost;
  xt_core_objects_t objects;
  xt_file_basic_t *log_file;
  xt_core_log_t *log;
  FILE *log_file_file;
  xt_config_system_t *config;
  char *atom_directory;
  unsigned long identities_shard_count;
  unsigned short clear_all_identities_period_minutes;

  xt_core_objects_init(&objects);

  log_file = xt_file_basic_create
    (LOG_FILENAME, XT_FILE_MODE_TRUNCATE_OR_CREATE_FOR_WRITE);
  if (!log_file) {
    xt_core_trace_exit("xt_file_basic_create");
  }

  log = xt_core_log_create(stdout);
  if (!log) {
    xt_core_trace_exit("xt_core_log_create");
  }

  log_file_file = xt_file_basic_get_file(log_file);
  if (log_file_file) {
    if (!xt_core_log_add_file(log, log_file_file)) {
      xt_core_log_trace_exit(log, " ta ", "xt_core_log_add_file");
    }
  } else {
    xt_core_log_trace_exit(log, " ta ", "xt_file_basic_get_file");
  }

#ifdef XT_BUILD_DEMO
  xt_core_log_enter(log, " ta ", "demo build");
#endif
#ifdef XT_BUILD_DEVELOPMENT
  xt_core_log_enter(log, " ta ", "development build");
#endif
#ifdef XT_BUILD_RELEASE
  xt_core_log_enter(log, " ta ", "release build");
#endif

  config = xt_config_system_create(argc, argv, CONF_FILENAME, &objects);
  if (!config) {
    xt_core_log_trace_exit(log, " ta ", "xt_config_system_create");
  }

  xt_config_system_find_as_string(config, "atom_directory", &atom_directory,
      DEFAULT_ATOM_DIRECTORY);
  xt_core_log_enter(log, " ta ", "using atom directory %s", atom_directory);

  xt_config_system_find_as_unsigned_short(config, "http_server_min_port",
      &http_server_min_port, DEFAULT_HTTP_SERVER_MIN_PORT);
  xt_config_system_find_as_unsigned_short(config, "http_server_max_port",
      &http_server_max_port, DEFAULT_HTTP_SERVER_MAX_PORT);
  xt_core_log_enter(log, " ta ", "using http server port range %i..%i",
      http_server_min_port, http_server_max_port);

  xt_config_system_find_as_unsigned_long(config, "identities_shard_count",
      &identities_shard_count, DEFAULT_IDENTITIES_SHARD_COUNT);
  xt_core_log_enter(log, " ta ", "identities_shard_count is %i",
      identities_shard_count);

  xt_config_system_find_as_unsigned_short(config,
      "clear_all_identities_period_minutes",
      &clear_all_identities_period_minutes,
      DEFAULT_CLEAR_ALL_IDENTITIES_PERIOD_MINUTES);
  xt_core_log_enter(log, " ta ", "clear_all_identities_period_minutes is %i",
      clear_all_identities_period_minutes);

  xt_net_engine_iengine_init(&http_iengine, ta_http_engine_create,
      ta_http_engine_destroy, ta_http_engine_get_handler_for_message,
      ta_http_engine_maintain, ta_http_engine_run, ta_http_engine_start,
      ta_http_engine_stop);

  xt_core_imessage_init(&http_imessage, xt_net_http_message_destroy,
      xt_net_http_message_get_client_socket, xt_net_http_message_get_engine_id,
      xt_net_http_message_get_type);

  xt_net_post_ipost_init(&http_ipost, xt_net_http_post_compare,
      xt_net_http_post_create, xt_net_http_post_create_decoy,
      xt_net_http_post_destroy, xt_net_http_post_destroy_decoy,
      xt_net_http_post_get_last_receive_activity_time,
      xt_net_http_post_get_socket, xt_net_http_post_get_stats,
      xt_net_http_post_receive_message, xt_net_http_post_receive_messages,
      xt_net_http_post_send_message, xt_net_http_post_send_messages,
      xt_net_http_post_is_socket_closed, xt_net_http_post_mod,
      xt_net_http_post_compare_equal);

  ta_system = ta_system_create(identities_shard_count,
      clear_all_identities_period_minutes, log);
  if (!ta_system) {
    xt_core_log_trace_exit(log, " ta ", "ta_system_create");
  }

  ta_server_init(&ta_server, atom_directory, ta_system, log);

  http_server = xt_net_server_system_create("ta", http_server_min_port,
      http_server_max_port, HTTP_SERVER_MAX_THREADS, &http_imessage,
      &http_ipost, ta_get_engine_name, XT_NET_SERVER_SYSTEM_NO_CONFIG_SYSTEM,
      log);
  if (!http_server) {
    xt_core_log_trace_exit(log, " ta ", "xt_net_server_system_create");
  }

  if (!xt_net_server_system_register_engine(http_server, XT_NET_ENGINE_HTTP,
          &ta_server, &http_iengine, 4, 8, XT_NET_MAINTAIN_1_MINUTE,
          XT_NET_MESSAGE_TYPE_COUNT_NONE)) {
    xt_core_log_trace_exit(log, " ta ", "xt_net_server_register_engine");
  }

  if (!xt_net_server_system_start(http_server)) {
    xt_core_log_trace_exit(log, " ta ", "xt_net_server_start");
  }

  xt_net_server_system_destroy(http_server);
  ta_server_free(&ta_server);
  ta_system_destroy(ta_system);
  xt_file_basic_destroy(log_file);
  xt_config_system_destroy(config);
  xt_core_log_destroy(log);

  return 0;
}
예제 #3
0
파일: csv.c 프로젝트: xtools/xt
xt_file_csv_t *xt_file_csv_create_extended(char *filename,
    unsigned long start_object, unsigned long end_object)
{
  assert(filename);
  xt_file_csv_t *csv;
  xt_core_bool_t so_far_so_good;
  xt_file_basic_t *file;

  file = NULL;

  csv = malloc(sizeof *csv);
  if (csv) {
    csv->name_to_index = NULL;
    csv->index_to_name = NULL;
    csv->objects = NULL;
    xt_core_objects_init();
    file = xt_file_basic_create(filename, XT_FILE_MODE_OPEN_FOR_READ);
    if (file) {
      so_far_so_good = xt_core_bool_true;
    } else {
      xt_core_trace("x_file_basic_create");
      so_far_so_good = xt_core_bool_false;
    }
  } else {
    so_far_so_good = xt_core_bool_false;
    xt_core_trace("malloc");
  }

  if (so_far_so_good) {
    csv->name_to_index = create_name_to_index_map(csv, file);
    if (!csv->name_to_index) {
      so_far_so_good = xt_core_bool_false;
      xt_core_trace("create_name_to_index_map");
    }
  }

  if (so_far_so_good) {
    csv->index_to_name = create_index_to_name_array(csv, file);
    if (!csv->index_to_name) {
      so_far_so_good = xt_core_bool_false;
      xt_core_trace("create_index_to_name_array");
    }
  }

  if (so_far_so_good) {
    csv->objects = create_objects_array(csv, file, start_object, end_object);
    if (!csv->objects) {
      so_far_so_good = xt_core_bool_false;
      xt_core_trace("create_objects_array");
    }
  }

  if (!so_far_so_good && csv) {
    if (csv->name_to_index) {
      xt_case_map_destroy(csv->name_to_index);
    }
    if (csv->index_to_name) {
      xt_case_array_destroy(csv->index_to_name);
    }
    if (csv->objects) {
      xt_case_array_destroy(csv->objects);
    }
  }

  if (file) {
    xt_file_basic_destroy(file);
  }

  return csv;
}