GError* meta0_backend_get_one(struct meta0_backend_s *m0, const guint8 *prefix, gchar ***u) { GError *err; EXTRA_ASSERT(m0 != NULL); EXTRA_ASSERT(u != NULL); GRID_TRACE("%s(%p,%02X%02X,%p)", __FUNCTION__, m0, prefix[0], prefix[1], u); if (NULL != (err = _reload(m0, TRUE))) { g_prefix_error(&err, "Reload error: "); return err; } g_rw_lock_reader_lock(&(m0->rwlock)); EXTRA_ASSERT(m0->array_by_prefix != NULL); *u = meta0_utils_array_get_urlv(m0->array_by_prefix, prefix); g_rw_lock_reader_unlock(&(m0->rwlock)); return *u ? NULL : NEWERROR(EINVAL, "META0 partially missing"); }
static struct meta0_assign_meta1_s* _select_dest_assign_m1(GList *lst, const struct meta0_assign_meta1_s *s_aM1, guint8 *prefixe, gboolean unref,gboolean force) { guint8 *prefix; if ( s_aM1 ) prefix = (guint8 *)(s_aM1->assignPrefixes)->data; else { if (prefixe) prefix=prefixe; else return NULL; } lst = g_list_last(lst); struct meta0_assign_meta1_s *d_aM1 = lst->data; gboolean loop = TRUE; gchar *shost=NULL, *dhost=NULL, *sport=NULL, *dport=NULL, *host=NULL, *port=NULL; guint i, len; guint avgscore = context->avgscore; if (s_aM1) l4_address_split(s_aM1->addr,&shost,&sport); do { if (d_aM1 == NULL || (d_aM1->score >= avgscore && !unref)) { loop=FALSE; d_aM1=NULL; } else { l4_address_split(d_aM1->addr,&dhost,&dport); gchar **urls = meta0_utils_array_get_urlv(context->array_meta1_by_prefix , prefix); if ( urls ) { len = g_strv_length(urls); for ( i=0;i < len ; i++) { if ( s_aM1 && g_ascii_strncasecmp(urls[i],s_aM1->addr,strlen(s_aM1->addr))==0) { continue; //meta1 to replace } if ( g_ascii_strncasecmp(urls[i],d_aM1->addr,strlen(d_aM1->addr))==0 ) { loop=TRUE; break; // meta1 manage this prefix, not OK } if (l4_address_split(urls[i],&host,&port)) { if (g_ascii_strncasecmp(host,dhost,strlen(dhost)) == 0 && ( shost==NULL || g_ascii_strncasecmp(host,shost,strlen(shost)) != 0)){ if (!force) { //nouveau meta1 host identique a un host deja present //meta1 remplace a un host different , on fait pire au niveau localisation loop=TRUE; break; } } loop=FALSE; if( host) { g_free(host); host=NULL; } if( port) { g_free(port); port=NULL; } } } g_strfreev(urls); } else { // New Init select this meta1 loop=FALSE; } if (loop==TRUE) { lst = g_list_previous(lst); if ( lst != NULL ) { d_aM1 = lst->data; } else { d_aM1=NULL; } } } if( dhost) { g_free(dhost); dhost=NULL; } if( host) { g_free(host); host=NULL; } if( dport) { g_free(dport); dport=NULL; } if( port) { g_free(port); port=NULL; } } while (loop==TRUE); if( shost) { g_free(shost); shost=NULL; } if( sport) { g_free(sport); sport=NULL; } if (!d_aM1) { GRID_TRACE("NO meta1 dest found"); } return d_aM1; }