20 #include <names_client.h>
44 if (!addid) addid =
"";
58 if (!addid && gb_other_main && gb_other_main != gb_main) {
71 for (
int c = 0; nameservers[c]; c++) serverCount++;
73 if (serverCount == 0) {
77 char **fieldNames = ARB_alloc<char*>(serverCount);
78 for (
int c = 0; c<serverCount; c++) {
89 char *equal = strchr(fieldNames[c],
'=');
90 if (equal) equal[0] = 0;
96 if (serverCount == 1) {
97 error =
set_addid(gb_main, fieldNames[0]);
102 int len = serverCount;
103 const char *nofield =
"None (only 'acc')";
105 for (
int c = 0; c<serverCount; c++) {
106 if (fieldNames[c]) len += strlen(fieldNames[c]);
107 else len += strlen(nofield);
110 char *buttons = ARB_alloc<char>(len);
112 for (
int c = 0; c<serverCount; c++) {
113 if (c) strcat(buttons,
",");
114 strcat(buttons, fieldNames[c] ? fieldNames[c] : nofield);
118 "Select if and which additional DB field you want to use",
119 buttons,
false,
"namesadmin.hlp");
121 error =
set_addid(gb_main, fieldNames[answer]);
127 for (
int c = 0; c<serverCount; c++) free(fieldNames[c]);
147 int init_local_com_names()
151 MAIN_LOCAL, AN_LOCAL, locs,
152 LOCAL_WHOAMI,
"i bin der arb_tree",
160 int old_persistent = persistent;
162 printf(
"Reconnecting name server\n");
166 persistent = old_persistent;
171 char *fieldUsedByServer(
GB_ERROR& err) {
174 MAIN_ADD_FIELD, &field,
176 err =
"Connection Problems with the NAME_SERVER";
182 GB_ERROR expectServerUsesField(
const char *expected_field) {
184 char *server_field = fieldUsedByServer(err);
186 if (!err && strcmp(expected_field, server_field) != 0) {
187 err =
GBS_global_string(
"Additional field doesn't match (expected='%s', server uses='%s')", expected_field, server_field);
223 linktime = time(
NULp);
226 if (init_local_com_names()) {
230 err = expectServerUsesField(add_field);
237 long linkAge =
int(time(
NULp)-linktime);
238 bool doReconnect =
false;
240 #if defined(DEBUG) && 0
242 static long lastage = -1;
243 if (linkAge != lastage) {
244 printf(
"Age of NameServerConnection: %li\n", linkAge);
249 if (linkAge > (5*60)) {
258 printf(
"Error: %s\n", error);
264 err = reconnect(gb_main);
272 if (persistent == 0) {
288 if (persistent <= 0) {
297 const T_AN_LOCAL&
getLocs()
const {
return locs; }
312 return name_server.
connect(gb_main);
331 static char *shrt =
NULp;
332 if (strlen(full_name)) {
334 LOCAL_FULL_NAME, full_name,
335 LOCAL_ACCESSION, acc,
336 LOCAL_ADDID, null2empty(addid),
339 err =
"Connection Problems with the NAME_SERVER";
342 LOCAL_GET_SHORT, &shrt,
344 err =
"Connection Problems with the NAME_SERVER";
357 err =
GB_export_errorf(
"Failed to generate species ID (shortname) for '%s'", full_name);
385 char *full_name = gb_full_name ?
GB_read_string (gb_full_name) : strdup(
"");
393 LOCAL_FULL_NAME, full_name,
394 LOCAL_ACCESSION, acc,
399 LOCAL_DEL_SHORT, &deleted,
402 LOCAL_GET_SHORT, &shrt,
405 error =
"Connection Problems with the NAME_SERVER";
416 for (
int count = 2; !done && !error && count<10; count++) {
420 if (!error) done = 1;
424 if (!done && !error) {
425 error =
"Failed to regenerate species ID. Please use 'Species/Synchronize IDs'";
447 char *newshort =
NULp;
450 ARB_alloc(newshort, strlen(shortname)+20);
452 sprintf(newshort,
"%s.%i", shortname, i);
457 "There are duplicated species!\n"
458 "The IDs of these species ('name') contain a '.' character followed by a number.\n"
459 "We strongly recommend you try understand and solve this problem\n"
460 "(see HELP in 'Species/Synchronize IDs' window)";
469 arb_progress gen_progress(
"Generating new shortnames (IDs)");
471 bool isWarning =
false;
500 char *full_name = gb_full_name ?
GB_read_string (gb_full_name) : strdup(
"");
506 if (full_name[0] || acc[0] || addid[0]) {
508 LOCAL_FULL_NAME, full_name,
509 LOCAL_ACCESSION, acc,
513 err =
"Connection Problems with the NAME_SERVER";
516 LOCAL_GET_SHORT, &shrt,
518 err =
"Connection Problems with the NAME_SERVER";
526 if (newshrt) freeset(shrt, newshrt);
553 if (warning) isWarning =
true;
559 if (isWarningPtr) *isWarningPtr = isWarning;
574 AW_window_simple *aws =
new AW_window_simple;
575 aws->init(root,
"AUTORENAME_SPECIES",
"Synchronize species IDs");
581 aws->create_button(
"CLOSE",
"CLOSE",
"C");
585 aws->create_button(
"HELP",
"HELP",
"H");
589 aws->create_autosize_button(
"CONFIG_NAMESERVER",
"Configure nameserver",
"n");
594 aws->create_button(
"GO",
"GO",
"G");
618 int prefix_len = strlen(prefix);
622 const int max_nums[8] = { 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10 };
623 static int next_try[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
625 int max_num = max_nums[prefix_len];
627 strcpy(short_name, prefix);
629 char *dig_pos = short_name+prefix_len;
630 int num = next_try[prefix_len];
631 int stop = num ? num-1 : max_num;
633 while (num != stop) {
634 sprintf(dig_pos,
"%i", num);
637 result = strdup(short_name);
640 if (num == max_num && stop != max_num) num = 0;
642 if (num == max_num) num = 0;
643 next_try[prefix_len] = num;
654 int len = strlen(prefix);
656 strncpy(p, prefix, 8);
660 if (len == 0) p[len++] =
'x';
661 while (len<8) p[len++] =
'0';
668 for (
int l = len-1; l>0 && !
result; --l) {
673 aw_assert(!result || strlen(result) <= 8);
674 if (!result)
GB_export_errorf(
"Failed to create unique species ID (prefix='%s')", prefix);
680 char *new_species_name =
NULp;
688 for (
int x=1; x<8; ++x) {
690 short_name[x] = r<10 ? (
'0'+r) : (
'a'+r-10);
694 new_species_name = strdup(short_name);
699 if (!new_species_name) {
700 aw_message(
"Failed to generate a random name - retrying (this might hang forever)");
704 return new_species_name;
716 while (
char c = short_name[++len]) {
717 alnum_count += (isalnum(c) != 0);
718 ascii_count += (c > 32 && c < 127);
723 if (len == alnum_count)
return 0;
725 if (len == ascii_count)
return 1;
bool name_known(const char *name)
#define AWAR_NAMESERVER_ADDID
AW_window * AWTC_create_rename_window(AW_root *root, GBDATA *gb_main)
GB_ERROR GBT_rename_species(const char *oldname, const char *newname, bool ignore_protection)
GBDATA * GB_child(GBDATA *father)
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
char * AWTC_generate_random_name(UniqueNameDetector &existingNames)
void load_xfig(const char *file, bool resize=true)
long GBS_incr_hash(GB_HASH *hs, const char *key)
int aisc_close(aisc_com *link, AISC_Object &object)
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
GB_ERROR AWTC_generate_one_name(GBDATA *gb_main, const char *full_name, const char *acc, const char *addid, char *&new_name)
char * GB_read_as_string(GBDATA *gbd)
GB_ERROR arb_look_and_start_server(long magic_number, const char *arb_tcp_env)
static char * makeUniqueShortName(const char *prefix, UniqueNameDetector &existing)
const char * GBS_global_string(const char *templat,...)
GB_ERROR AWTC_pars_names(GBDATA *gb_main, bool *isWarningPtr)
void warning(int warning_num, const char *warning_message)
int aisc_nput(aisc_com *link, int o_type, const AISC_Object &object,...)
void AW_POPDOWN(AW_window *window)
void GBS_free_hash(GB_HASH *hs)
GB_ERROR GB_push_transaction(GBDATA *gbd)
char * AWTC_makeUniqueShortName(const char *prefix, UniqueNameDetector &existingNames)
const T_AN_LOCAL & getLocs() const
void sub_progress_skipped()
const char * AW_get_nameserver_addid(GBDATA *gb_main)
GB_ERROR GB_await_error()
WindowCallback makeHelpCallback(const char *helpfile)
const char * GBS_read_arb_tcp(const char *env)
static void show_comment(const char *comment)
TYPE * ARB_alloc(size_t nelem)
const char * GBS_scan_arb_tcp_param(const char *ipPort, const char *wantedParam)
GB_ERROR connect(GBDATA *gb_main)
long GB_number_of_subentries(GBDATA *gbd)
GB_ERROR GBT_begin_rename_session(GBDATA *gb_main, int all_flag)
int AWTC_name_quality(const char *short_name)
static void error(const char *msg)
GBDATA * GB_get_root(GBDATA *gbd)
#define AWAR_TREE_REFRESH
UniqueNameDetector(GBDATA *gb_item_data, long additionalEntries=0)
~PersistentNameServerConnection()
static NameServerConnection name_server
AW_awar * awar(const char *awar)
GB_ERROR GBT_abort_rename_session(void)
GB_ERROR GBT_commit_rename_session(void) __ATTR__USERESULT
static void awt_rename_cb(AW_window *aww, GBDATA *gb_main)
#define AISC_MAGIC_NUMBER
int aw_question(const char *unique_id, const char *question, const char *buttons, bool sameSizeButtons, const char *helpfile)
const char *const * GBS_get_arb_tcp_entries(const char *matching)
GB_ERROR AWTC_recreate_name(GBDATA *gb_species)
GB_ERROR GB_export_errorf(const char *templat,...)
static const char * get_addid(GBDATA *gb_main)
const char * GBS_nameserver_tag(const char *add_field)
GB_ERROR GBT_write_string(GBDATA *gb_container, const char *fieldpath, const char *content)
aisc_com * aisc_open(const char *path, AISC_Object &main_obj, long magic, GB_ERROR *error)
char * AWTC_create_numbered_suffix(GB_HASH *species_name_hash, const char *shortname, GB_ERROR &warning)
void AW_popup_namesadmin_window(AW_window *parent_win, GBDATA *gb_main)
char * GB_read_string(GBDATA *gbd)
static GB_ERROR set_addid(GBDATA *gb_main, const char *addid)
GBDATA * GBT_gen_accession_number(GBDATA *gb_species, const char *ali_name)
GBDATA * GBT_first_species(GBDATA *gb_main)
void aw_message(const char *msg)
GBDATA * GBT_next_species(GBDATA *gb_species)
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
int aisc_get(aisc_com *link, int o_type, const AISC_Object &object,...)
void persistence(bool persist)
char * GBT_get_default_alignment(GBDATA *gb_main)
GB_ERROR AW_test_nameserver(GBDATA *gb_main)
GBDATA * GB_nextChild(GBDATA *child)
long GBT_get_species_count(GBDATA *gb_main)
GB_transaction ta(gb_var)
virtual ~NameServerConnection()
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
PersistentNameServerConnection()
GB_ERROR AW_select_nameserver(GBDATA *gb_main, GBDATA *gb_other_main)
long GBS_read_hash(const GB_HASH *hs, const char *key)
GBDATA * GB_entry(GBDATA *father, const char *key)
void inc_and_check_user_abort(GB_ERROR &error)
int aisc_create(aisc_com *link, int father_type, const AISC_Object &father, int attribute, int object_type, AISC_Object &object,...)
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)