コード例 #1
0
char *SD_getServiceWSDL(const char *name, SDException *exception) {
    SDServiceDetails *serviceDetails = NULL;
    char *wsdl = NULL;

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);


    wsdl = sd_bdii_getServiceWSDL(name, exception);
    if (!wsdl) {
        SD_freeException(exception);
        serviceDetails = SD_getServiceDetails(name, exception);
    }


    if (serviceDetails) {
        /* If we are emulating the getServiceWSDL method, we have to
         * make a copy of the value */
        if (serviceDetails->wsdl) {
            wsdl = dupstr(serviceDetails->wsdl);
            if (!wsdl)
                SD_setException(exception, SDStatus_FAILURE, ERROR_OUTOFMEMORY, NULL, 0);
        } else
            wsdl = NULL;

        SD_freeServiceDetails(serviceDetails);
    }

    return wsdl;
}
コード例 #2
0
int g2_sd_get_storage_path(const char *host, const char *spacetokendesc,
        char **sa_path, char **sa_root, char *errbuf, int errbufsz) {

    int rc = 0;
    SDException exception;
    LDAP *ld = NULL;

    if (!host || !sa_path) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_storage_path]: Invalid Arguments passed to retrieve storage path", errbuf, errbufsz);
        errno = EINVAL;
        return (-1);
    }

    if ((ld = get_connection(&exception, errbuf, errbufsz)) == NULL) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_storage_path]: Cannot connect to BDII", errbuf, errbufsz);
        return (-1);
    }


    *sa_path = *sa_root = NULL;

    rc = g2_get_voinfo(ld, host, spacetokendesc, sa_path, errbuf, errbufsz);

    if (ld)
        close_connection(ld);

    return (rc);
}
コード例 #3
0
char *SD_getServiceSite(const char *name, SDException *exception) {
    SDServiceDetails *serviceDetails = NULL;
    char *site = NULL;

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);

    serviceDetails = SD_getServiceDetails(name, exception);
    if (serviceDetails) {
        /* If we are emulating the getServiceSite method, we have to
         * make a copy of the value */
        if (serviceDetails->site) {
            site = dupstr(serviceDetails->site);
            if (!site)
                SD_setException(exception, SDStatus_FAILURE, ERROR_OUTOFMEMORY, NULL, 0);
        } else
            site = NULL;

        SD_freeServiceDetails(serviceDetails);
    }

     if(!site){
        SD_freeServiceDetails(serviceDetails);
	SD_freeException(exception);
	site = sd_bdii_getServiceSite(name, exception);
	if(!site)
		SD_freeServiceDetails(serviceDetails);
	}

    return site;
}
コード例 #4
0
SDServiceList *SD_listServices(const char *type, const char *site, const SDVOList *vos, SDException *exception) {
    SDServiceList *result = NULL;
    SDVOList *tmpvos;

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);

    if (!site) {
        site = getenv(SDEnv_SITE);
        /* treat empty string as if it does not exist */
        if (site && (strlen(site) == 0))
            site = NULL;
    }
    tmpvos = NULL;
    /* Let the user override the VO if the caller did not specify
     * one explicitely */
    if (!vos || !vos->numNames)
        tmpvos = checkVOEnv();


    result = SD_listServicesByData(NULL, type, site,
            tmpvos ? tmpvos : vos,
            exception);

    if (tmpvos)
        SD_freeVOList(tmpvos);

    return result;
}
コード例 #5
0
SDServiceDetails *SD_getServiceDetails(const char *name,
        SDException *exception) {
    SDServiceDetails *serviceDetails = NULL;
    char delims[] = ",";
    char *plugin = NULL;
    plugin = plugin_is_set();

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);

    if (plugin == NULL) /*env is not set, query file,bdii with this order */ {
        serviceDetails = sd_file_getServiceDetails(name, exception);
        if (!serviceDetails) {
    	    sd_file_freeServiceDetails(serviceDetails);
            SD_freeException(exception);
            serviceDetails = sd_bdii_getServiceDetails(name, exception);
        }
    } else /*env is set, check the order*/ {
        char *comma = strchr(plugin, ',');

        if (plugin && comma) {
            char *result = NULL;
            result = strtok(plugin, delims);
            while (result != NULL) {
                if (0 == strcmp(result, available_plungins[0])) /*file*/ {
                    SD_freeException(exception);
                    serviceDetails = sd_file_getServiceDetails(name, exception);
                    if (serviceDetails) {
                        break;
                    }
		    else
		       sd_file_freeServiceDetails(serviceDetails);
                } else if (0 == strcmp(result, available_plungins[1])) /*bdii*/ {
                    SD_freeException(exception);
                    serviceDetails = sd_bdii_getServiceDetails(name, exception);
                    if (serviceDetails) {
                        break;
                    }
		    else
		       sd_bdii_freeServiceDetails(serviceDetails);
                } else {
                    break;
                }
                result = strtok(NULL, delims);
            }
        } else {
            if (plugin && 0 == strcmp(plugin, available_plungins[0])) /*file*/ {
                SD_freeException(exception);
                serviceDetails = sd_file_getServiceDetails(name, exception);
            } else if (plugin && 0 == strcmp(plugin, available_plungins[1])) /*bdii*/ {
                SD_freeException(exception);
                serviceDetails = sd_bdii_getServiceDetails(name, exception);
            }
        }
    }

    if (plugin)
        free(plugin);

    return serviceDetails;
}
コード例 #6
0
/*
return Glue2ServiceID as output, 
by looking for an SRM Endpoint with the hostname matching the
EndpointURL and getting the Service ID from the EndpointServiceForeignKey.
*/
int g2_sd_get_service_id(LDAP *ld, const char *host, char **service_id, char **endpoint_id, char *errbuf, int errbufsz)
{
    LDAPMessage *entry = NULL;
    SDException exception;
    LDAPMessage *reply = NULL;
    struct berval **value = NULL;
    char *query = NULL;
    int sav_errno = 0;
    *service_id = NULL;
    *endpoint_id = NULL;
    int rc = 0;

    if (!host) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_service_id]: Hostname is not specified", errbuf, errbufsz);
        return (-1);
    }

    query = g_strdup_printf(GLUE2_SERVICE_ID, host);
    
   
        rc = connect_search_ldap(glue2_base, query, all_attrs, ld, &exception, &reply, errbuf, errbufsz);
        if (rc != LDAP_SUCCESS) {
            if (reply)
                ldap_msgfree(reply);
            if (query)
            	g_free(query);	       		
          return (-1);
        }


        if ((1 > ldap_count_entries(ld, reply))) {
            if (reply)
                ldap_msgfree(reply);
            if (query)
               g_free(query);	       	       
            return (-1);
        }


        for (entry = ldap_first_entry(ld, reply); entry != NULL && rc == 0; entry
                = ldap_next_entry(ld, entry)) {

        if ( (value = ldap_get_values_len(ld, entry, GLUE2EndpointServiceForeignKey))) {
            if (value && value[0]->bv_val) {
                if ((*service_id = strdup(value[0]->bv_val)) == NULL) {
                    sav_errno = errno ? errno : ENOMEM;
                }
                ber_bvecfree(value);
            }
        }
        if ( (value = ldap_get_values_len(ld, entry, GLUE2EndpointID))) {
            if (value && value[0]->bv_val) {
                if ((*endpoint_id = strdup(value[0]->bv_val)) == NULL) {
                    sav_errno = errno ? errno : ENOMEM;
                }
                ber_bvecfree(value);
            }
        }
		
        if (reply)
		ldap_msgfree(reply);        
	if(*service_id)
		break;

     }

    if (query)
        g_free(query);

    if (!*service_id) {
        if (!sav_errno) {
            sav_errno = EINVAL;
        }
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_service_id]: failed", errbuf, errbufsz);
        errno = sav_errno;
        return (-1);
    }
    return (0);
}
コード例 #7
0
int g2_get_voinfo(LDAP *ld, const char *host, const char *spacetokendesc, char **sa_path, char *errbuf, int errbufsz) {

    int i = 0;
    LDAPMessage *entry = NULL;
    char *filter = NULL;
    int rc = 0;
    LDAPMessage *reply = NULL;
    struct berval **value = NULL;
    int sav_errno = 0;
    SDException exception;
    char *vo = NULL;
    storages *storage_shares = NULL;
    storages *storage_shares_temp = NULL;
    GSList* list = NULL;
    char *GLUE2ShareID = NULL;
    char *GLUE2StorageSharePath = NULL;
    int list_length = 0;
    char *service_id = NULL;
    char *endpoint_id = NULL;
    
    g_setenv("G_SLICE", "always-malloc", 1);

    if ((vo = vo_global) == NULL) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_get_voinfo]: Invalid Arguments.", errbuf, errbufsz);
        errno = EINVAL;
        return (-1);
    }

    if (!host || !sa_path) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_get_voinfo]: Invalid Arguments.", errbuf, errbufsz);
        errno = EINVAL;
        return (-1);
    }

    g2_sd_get_service_id(ld, host, &service_id, &endpoint_id, errbuf, errbufsz);
    if(!service_id)
    {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_get_voinfo]: ServiceID cannot be found", errbuf, errbufsz);
	if(ld)
		close_connection(ld);
	return (-1);      
	
    }    


    if (spacetokendesc)
        rc = asprintf(&filter, GLUE2_STORAGE_PATH, service_id, spacetokendesc);
    else
        rc = asprintf(&filter, GLUE2_STORAGE_PATH_NO_ST, service_id);



    if (rc < 0) return (-1);

    *sa_path = NULL;

    while (!*sa_path && !sav_errno) {

        rc = connect_search_ldap(glue2_base, filter, g2_storage_path_attrs, ld, &exception, &reply, errbuf, errbufsz);
        if (rc != LDAP_SUCCESS) {
            if (reply) {
                ldap_msgfree(reply);
            }
            if (filter)
                free(filter);
            sav_errno = errno;
            goto out;
        }

        if ((1 > ldap_count_entries(ld, reply))) {
            if (reply)
                ldap_msgfree(reply);
            if (filter)
                free(filter);
            goto out;
        }

        for (entry = ldap_first_entry(ld, reply); entry != NULL && rc == 0; entry
                = ldap_next_entry(ld, entry)) {

            if ((value = ldap_get_values_len(ld, entry, GLUE2_GLUE2ShareID)) != NULL) { /*get GLUE2_GLUE2ShareID*/
                if (value && value[0]->bv_val) {
                    GLUE2ShareID = strdup(value[0]->bv_val);
                    if (value)
                        ber_bvecfree(value);
                }
            }


            if ((value = ldap_get_values_len(ld, entry, GLUE2_GLUE2StorageSharePath)) != NULL) { /*get GLUE2_GLUE2ShareID*/
                if (value && value[0]->bv_val) {
                    GLUE2StorageSharePath = strdup(value[0]->bv_val);
                    if (value)
                        ber_bvecfree(value);
                }
            }

            /*append to the list*/
            if (GLUE2StorageSharePath && GLUE2ShareID) {
                storage_shares = g_new0(storages, 1);
                storage_shares->GLUE2ShareID = GLUE2ShareID;
                storage_shares->GLUE2StorageSharePath = GLUE2StorageSharePath;
                list = g_slist_append(list, storage_shares);

            }

        } /*end for*/


        if (reply)
            ldap_msgfree(reply);
        if (GLUE2StorageSharePath && GLUE2ShareID)
            break;

    } /*end while*/

    if (filter)
        free(filter);

    if (list) {
        list_length = g_slist_length(list);
        for (i = 0; i < list_length; i++) {
            storage_shares_temp = (storages *) g_slist_nth(list, i)->data;
            rc = asprintf(&filter, GLUE2_STORAGE_POLICY, endpoint_id, vo);



            rc = connect_search_ldap(glue2_base, filter, all_attrs, ld, &exception, &reply, errbuf, errbufsz);
            if (rc != LDAP_SUCCESS) {
                if (reply) {
                    ldap_msgfree(reply);
                }
                sav_errno = errno;
                goto out;
            }

            if ((1 > ldap_count_entries(ld, reply))) {
                if (reply)
                    ldap_msgfree(reply);
                if (filter)
                    free(filter);
                goto out;
            } else {
                if (filter)
                    free(filter);
                if (storage_shares_temp->GLUE2StorageSharePath)
                    *sa_path = strdup(storage_shares_temp->GLUE2StorageSharePath);
            }

        }
    }
out:
    if (list) {
        for (i = 0; i < list_length; i++) {
            storage_shares_temp = (storages *) g_slist_nth(list, i)->data;
            g_free(storage_shares_temp->GLUE2StorageSharePath);
            g_free(storage_shares_temp->GLUE2ShareID);
            g_free(storage_shares_temp);
        }
        g_slist_free(list);
    }
    
    if(service_id)
    	free(service_id);
    if(endpoint_id)
    	free(endpoint_id);
		
    if (!*sa_path) {
        if (!sav_errno) {
            if (spacetokendesc) {
                SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_storage_path]: no GLUE2StorageSharePath information found about tag and SE ", errbuf, errbufsz);
            } else {
                SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_storage_path]: no information found about SE  (with no tag) ", errbuf, errbufsz);

            }
            sav_errno = EINVAL;
        }
        errno = sav_errno;
        return (-1);
    }

    return (0);
}
コード例 #8
0
/* get from the BDII the endpoint for the LFC */
int g2_sd_get_lfc_endpoint(char **lfc_endpoint, char *errbuf, int errbufsz) {
    LDAPMessage *entry = NULL;
    char *filter = NULL, *filter_tmp = NULL;
    int rc = 0;
    LDAPMessage *reply = NULL;
    struct berval **value = NULL;
    int sav_errno = 0;
    *lfc_endpoint = NULL;
    SDException exception;
    char *query_policy = NULL;
    char *lfc_fk = NULL;
    LDAP *ld = NULL;

    if ((filter_tmp = g2_generate_acbr("GLUE2PolicyID")) == NULL) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_lfc_endpoint]: No GLUE2PolicyID found", errbuf, errbufsz);
        return (-1);
    }

    if ((ld = get_connection(&exception, errbuf, errbufsz)) == NULL) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_lfc_endpoint]: Cannot connect to BDII", errbuf, errbufsz);
        return (-1);
    }

    query_policy = g_strdup_printf(GLUE2_QUERY_LFC_POLICY, filter_tmp);
    free(filter_tmp);



    while (!*lfc_endpoint && !sav_errno) {

        /*get first the policy rule for a particular vo*/
        rc = connect_search_ldap(glue2_base, query_policy, g2_lfc_endpoint_foreign_key_attrs, ld, &exception, &reply, errbuf, errbufsz);
        if (rc != LDAP_SUCCESS) {
            if (reply) {
                ldap_msgfree(reply);
            }
            sav_errno = errno;
            break;
        }
        if ((entry = ldap_first_entry(ld, reply)) && (value = ldap_get_values_len(ld, entry, GLUE2_ACCESS_POLICY_FK))) {
            if (value && value[0]->bv_val) {
                if ((lfc_fk = strdup(value[0]->bv_val)) == NULL)
                    sav_errno = errno ? errno : ENOMEM;
                ldap_value_free_len(value);
            }
        }

        /*now get the lfc endpoint*/
        rc = asprintf(&filter, GLUE2_QUERY_LFC_ENDPOINT, lfc_fk);
        free(lfc_fk);



        if (rc < 0) {
            if (reply) {
                ldap_msgfree(reply);
            }
            if (filter)
                free(filter);
            break;
        }

        rc = connect_search_ldap(glue2_base, filter, g2_lfc_endpoint_attrs, ld, &exception, &reply, errbuf, errbufsz);
        if (rc != LDAP_SUCCESS) {
            if (reply) {
                ldap_msgfree(reply);
            }
            if (filter)
                free(filter);
            sav_errno = errno;
            break;
        }
        if ((entry = ldap_first_entry(ld, reply)) && (value = ldap_get_values_len(ld, entry, GLUE2_ATTR_ENDPOINT))) {
            if (value && value[0]->bv_val) {
                if ((*lfc_endpoint = strdup(value[0]->bv_val)) == NULL)
                    sav_errno = errno ? errno : ENOMEM;
                ldap_value_free_len(value);
            }
        }

        if (reply)
            ldap_msgfree(reply);
        if (filter)
            free(filter);
	    
	if(!*lfc_endpoint)
	  break;
    }

    if (query_policy)
        g_free(query_policy);
    if (ld)
        close_connection(ld);


    if (!*lfc_endpoint) {
        if (!sav_errno) {            
            sav_errno = EINVAL;
        }
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_lfc_endpoint]: No LFC Endpoint found", errbuf, errbufsz);
        errno = sav_errno;
        return (-1);
    }

    return 0;
}
コード例 #9
0
int g2_sd_get_ce_ap(const char *host, char **ce_ap, char *errbuf, int errbufsz) {
    LDAPMessage *entry = NULL;
    SDException exception;
    LDAPMessage *reply = NULL;
    struct berval **value = NULL;
    char *query = NULL;
    int sav_errno = 0;
    *ce_ap = NULL;
    int rc = 0;
    LDAP *ld = NULL;
    char *service_id = NULL;
    char *endpoint_id = NULL;

    if (!host) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_ce_ap]: Hostname is not specified", errbuf, errbufsz);
        return (-1);
    }



    if ((ld = get_connection(&exception, errbuf, errbufsz)) == NULL) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_ce_ap]: Cannot connect to BDII", errbuf, errbufsz);
        if (query)
            g_free(query);
        return (-1);
    }

    g2_sd_get_service_id(ld, host, &service_id, &endpoint_id, errbuf, errbufsz);
    if(!service_id)
    {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_ce_ap]: ServiceID cannot be found", errbuf, errbufsz);
        if(endpoint_id)
		free(endpoint_id);
	if(ld)
		close_connection(ld);
	return (-1);      
	
    }        

    query = g_strdup_printf(GLUE2_QUERY_CESE_BIND, service_id);



       rc = connect_search_ldap(glue2_base, query, g2_ce_ap_attrs, ld, &exception, &reply, errbuf, errbufsz);
        if (rc != LDAP_SUCCESS) {
           if (reply)
                ldap_msgfree(reply);
            if (query)
               g_free(query);
	    if (ld)
        	close_connection(ld);
	    if(service_id)
	    	free(service_id);		
            sav_errno = errno;
	    rc = -1;
	    goto out;
            
        }



        if ((1 > ldap_count_entries(ld, reply))) {
            if (reply)
                ldap_msgfree(reply);
            if (query)
               g_free(query);
	    if (ld)
        	close_connection(ld);	       
	    if(service_id)
	    	free(service_id);				
            goto out;
        }


        for (entry = ldap_first_entry(ld, reply); entry != NULL && rc == 0; entry
                = ldap_next_entry(ld, entry)) {


        if ((entry = ldap_first_entry(ld, reply)) && (value
                = ldap_get_values_len(ld, entry, GLUE2_ATTR_CE_AP_ATNM))) {
            if (value && value[0]->bv_val) {
                if ((*ce_ap = strdup(value[0]->bv_val)) == NULL) {
                    sav_errno = errno ? errno : ENOMEM;
                }
                ber_bvecfree(value);
            }
        }

        if (reply)
            ldap_msgfree(reply);
        if(*ce_ap)
	    break;
    }

    if (query)
        g_free(query);
    if (ld)
        close_connection(ld);
    if(service_id)
	    	free(service_id);			
    if(endpoint_id)
	    	free(endpoint_id);					

out:
    if (!*ce_ap) {
        if (!sav_errno) {
            sav_errno = EINVAL;
        }
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_ce_ap]: No GLUE2ToComputingServiceID or GLUE2ToComputingServiceLocalPath found.", errbuf, errbufsz);
        errno = sav_errno;
        return (-1);
    }
    return (0);
}
コード例 #10
0
int g2_sd_is_online(char *host, char *errbuf, int errbufsz) {
    char host_tmp[255];
    LDAPMessage *reply = NULL;
    SDException exception;
    LDAP *ld = NULL;
    char *query = NULL;
    int rc = 0;
    int is_production = 0;
    char *service_id = NULL;
    char *endpoint_id = NULL;    

    if (!host) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_is_online]: Host is empty", errbuf, errbufsz);
        return (-1);
    }

    if ((ld = get_connection(&exception, errbuf, errbufsz)) == NULL) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_is_online]: Cannot connect to BDII", errbuf, errbufsz);
        return (-1);
    }

    g2_sd_get_service_id(ld, host, &service_id, &endpoint_id, errbuf, errbufsz);
    if(!service_id)
    {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_is_online]: ServiceID cannot be found", errbuf, errbufsz);
	if(ld)
		close_connection(ld);
	return (-1);      
        	
    }        

    strncpy(host_tmp, host, 255);

    query = g_strdup_printf(GLUE2_QUERY_SE_STATUS, service_id);



    rc = connect_search_ldap(glue2_base, query, NULL, ld, &exception, &reply, errbuf, errbufsz);
    if (rc != LDAP_SUCCESS) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_is_online]: No available information", errbuf, errbufsz);
        goto out;
    }

    if ((ldap_count_entries(ld, reply)) < 1)
        is_production = 0;
    else
        is_production = 1;


out:
    if (service_id)
    	free(service_id);
    if (endpoint_id)
    	free(endpoint_id);	
    if (reply)
        ldap_msgfree(reply);
    if (query)
        g_free(query);
    if (ld)
        close_connection(ld);

    if (is_production == 0)
        return (-1);

    return 0;
}
コード例 #11
0
SDServiceList *SD_listAssociatedServices(const char *name,
        const char *type, const char *site, const SDVOList *vos,
        SDException *exception) {
    SDServiceList *serviceDetails = NULL;
    SDVOList *tmpvos;
    char delims[] = ",";
    char *plugin = NULL;
    plugin = plugin_is_set();

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);

    if (!site) {
        site = getenv(SDEnv_SITE);
        /* treat empty string as if it does not exist */
        if (site && (strlen(site) == 0))
            site = NULL;
    }

    tmpvos = NULL;
    /* Let the user override the VO if the caller did not specify
     * one explicitely */
    if (!vos || !vos->numNames)
        tmpvos = checkVOEnv();

    if (NULL == plugin) /*env is not set, query file,bdii with this order */ {
        serviceDetails = sd_file_listAssociatedServices(name, type, site, tmpvos ? tmpvos : vos, exception);
        if (!serviceDetails) { 
	    sd_file_freeServiceList(serviceDetails);          
            SD_freeException(exception);
            serviceDetails = sd_bdii_listAssociatedServices(name, type, site, tmpvos ? tmpvos : vos, exception);            
        }
    } else /*env is set, check the order*/ {
        char *comma = strchr(plugin, ',');

        if (plugin && comma) {
            char *result = NULL;
            result = strtok(plugin, delims);
            while (result != NULL) {
                if (0 == strcmp(result, available_plungins[0])) /*file*/ {
                    SD_freeException(exception);
                    serviceDetails = sd_file_listAssociatedServices(name, type, site, tmpvos ? tmpvos : vos, exception);
                    if (serviceDetails) {
                        break;
                    }
		    else
		    	sd_file_freeServiceList(serviceDetails);
                } else if (0 == strcmp(result, available_plungins[1])) /*bdii*/ {
                    SD_freeException(exception);
                    serviceDetails = sd_bdii_listAssociatedServices(name, type, site, tmpvos ? tmpvos : vos, exception);
                    if (serviceDetails) {
                        break;
                    }
		    else
			    sd_file_freeServiceList(serviceDetails);
                } else {
                    break;
                }
                result = strtok(NULL, delims);
            }
        } else {
            if (plugin && 0 == strcmp(plugin, available_plungins[0])) /*file*/ {
                SD_freeException(exception);
                serviceDetails = sd_file_listAssociatedServices(name, type, site, tmpvos ? tmpvos : vos, exception);
            } else if (plugin && 0 == strcmp(plugin, available_plungins[1])) /*bdii*/ {
                SD_freeException(exception);
                serviceDetails = sd_bdii_listAssociatedServices(name, type, site, tmpvos ? tmpvos : vos, exception);
            }
        }
    }

    if (tmpvos)
        SD_freeVOList(tmpvos);
    if (plugin)
        free(plugin);

    return serviceDetails;
}
コード例 #12
0
SDServiceList *SD_listServicesByHost(const char *type, const char *host,
        const SDVOList *vos, SDException *exception) {

    SDServiceList *result = NULL;
    SDVOList *tmpvos = NULL;
    int i=0, j=0;
    int numServices=0;

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);

    tmpvos = NULL;
    /* Let the user override the VO if the caller did not specify
     * one explicitely */
    if (!vos || !vos->numNames)
        tmpvos = checkVOEnv();

/*
    result = sd_bdii_listServicesByHost(type, host, tmpvos ? tmpvos : vos, exception);

    if (!result) {
    
        sd_bdii_freeServiceList(result);
        SD_freeException(exception);
   */	
        /* filter the host and port from the result of */

        /* listServices on the client side */
        result = SD_listServices(type, NULL, tmpvos ? tmpvos : vos, exception);
        if (result != NULL && exception->status == SDStatus_SUCCESS) {
            /* Check for the host name in the endpoint in this order:
            //    1. ^host$
            //    2. ^host:
            //    3. /host:
            //    4. /host/
            //    5. host
            // Run the filtering with the first matching pattern.
            // TODO: implement the filtering in bdii-c */
            int f, fmatched;
            SD_matchEndpointHost matchFunction = NULL;
            for (f = 0; f < SD_num_matches; f++) {
                matchFunction = SD_matchEndpointHostFunctions[f];
                fmatched = 0;
                for (i = 0; i < result->numServices; i++) {
                    if (result->services[i]->endpoint != NULL) {
                        if (matchFunction(result->services[i]->endpoint, host)) {
                            fmatched++;
                        }
                    }
                } /* end for loop 
                // break the loop, if there was a match and use that for filtering */
                if (fmatched > 0) break;
            }
            /* in the worst case, when there was no match,
            // matchFunction will point to the last function */

            for (i = 0; i < result->numServices; i++) {
                if (result->services[i]->endpoint != NULL) {
                    /* check if the endpoint contains the host name */
                    if (!matchFunction(result->services[i]->endpoint, host)) {
                        /* no match. Delete the service entry and mark it as null 
                        // in the list */
                        SD_freeService(result->services[i]);
                        result->services[i] = NULL;
                    }
                }
            } /* end for loop 

            // Reorder the list so the nulls are at the end
            // Please Note: this algorithm may not be the best one but the 
            // number of expected elements should be quite limited, so it 
            // shouldn't be a real problem */
            numServices = 0;
            for (i = 0; i < result->numServices; ++i) {
                if (NULL == result->services[i]) {
                    /* Get the next valid one */
                    for (j = i + 1; j < result->numServices; ++j) {
                        if (NULL != result->services[j]) {
                            /* Swicth the two elements */
                            result->services[i] = result->services[j];
                            result->services[j] = 0;
                            ++numServices;
                            break;
                        }
                    }
                } else {
                    ++numServices;
                }
            } /* end reordering loop */
            result->numServices = numServices;
        } /* if result != NULL */
    //}
    if(numServices == 0){
	sd_file_freeServiceList(result);
	SD_freeException(exception);
    	result = sd_bdii_listServicesByHost(type, host, tmpvos ? tmpvos : vos, exception);

    if (!result) {
        sd_bdii_freeServiceList(result);
        SD_freeException(exception);
    	}
   }

    if (tmpvos)
        SD_freeVOList(tmpvos);

    return result;
}
コード例 #13
0
SDService *SD_getService(const char *name, SDException *exception) {
    SDServiceDetails *serviceDetails = NULL;
    SDService *service = NULL;
    char delims[] = ",";
    char *plugin = NULL;
    plugin = plugin_is_set();

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);

    if (NULL == plugin) /*env is not set, query file,bdii with this order */ {
        service = sd_file_getService(name, exception);
        if (!service) {
	    sd_file_freeService(service);
            SD_freeException(exception);
            service = sd_bdii_getService(name, exception);
            if (!service) {
	    	sd_bdii_freeService(service);
                SD_freeException(exception);
                serviceDetails = SD_getServiceDetails(name, exception);
		if(!serviceDetails){		        
			SD_freeServiceDetails(serviceDetails);
		}
            }
        }
    } else /*env is set, check the order*/ {
        char *comma = strchr(plugin, ',');
        if (plugin && comma) {
            char *result = NULL;
            result = strtok(plugin, delims);
            while (result != NULL) {
                if (0 == strcmp(result, available_plungins[0])) /*file*/ {
                    SD_freeException(exception);
                    service = sd_file_getService(name, exception);
                    if (service) {
                        break;
                    }
		    else
		    	    sd_file_freeService(service);
                } else if (0 == strcmp(result, available_plungins[1])) /*bdii*/ {
                    SD_freeException(exception);
                    service = sd_bdii_getService(name, exception);
                    if (service) {
                        break;
                    }
		    else
		    	sd_bdii_freeService(service);
                } else {
                    SD_freeException(exception);
                    serviceDetails = SD_getServiceDetails(name, exception);
                    if (serviceDetails) {
                        break;
                    }
		    else
			SD_freeServiceDetails(serviceDetails);
                }
                result = strtok(NULL, delims);
            }
        } else {
            if (plugin && 0 == strcmp(plugin, available_plungins[0])) /*file*/ {
                SD_freeException(exception);
                service = sd_file_getService(name, exception);
                if (!service) 
	            sd_file_freeService(service);
            } else if (plugin && 0 == strcmp(plugin, available_plungins[1])) /*bdii*/ {
                SD_freeException(exception);
                service = sd_bdii_getService(name, exception);
		if(!service)
			sd_bdii_freeService(service);
            } else {
                SD_freeException(exception);
                serviceDetails = SD_getServiceDetails(name, exception);
            }
        }
    }

    if (serviceDetails) {
        /* If we are emulating the getService method, we have to make
         * a copy of the data */
        service = (SDService *) calloc(1, sizeof (SDService));
        if (!service)
            SD_setException(exception, SDStatus_FAILURE, ERROR_OUTOFMEMORY, NULL, 0);
        else {
            /* Copy the basic service data */
            service->name = dupstr(serviceDetails->name);
            service->type = dupstr(serviceDetails->type);
            service->endpoint = dupstr(serviceDetails->endpoint);
            service->version = dupstr(serviceDetails->version);

            /* Check for failed dupstr()s */
            if (!service->name || !service->type || !service->endpoint ||
                    !service->version) {
                SD_setException(exception, SDStatus_FAILURE, ERROR_OUTOFMEMORY, NULL, 0);
                SD_freeService(service);
                service = NULL;
            }
        }

        SD_freeServiceDetails(serviceDetails);
    }

    if (plugin)
        free(plugin);

    return service;
}
コード例 #14
0
SDServiceDataList *SD_getServiceData(const char *name,
        SDException *exception) {
    SDServiceDetails *serviceDetails = NULL;
    SDServiceDataList *list = NULL;
    char delims[] = ",";
    char *plugin = NULL;
    plugin = plugin_is_set();

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);


    if (NULL == plugin) /*env is not set, query file,bdii with this order */ {
        list = sd_file_getServiceData(name, exception);
        if (!list) {
	    sd_file_freeServiceDataList(list);	     
            SD_freeException(exception);
            list = sd_bdii_getServiceData(name, exception);
            if (!list) {
	        sd_bdii_freeServiceDataList(list);	     
                SD_freeException(exception);
                serviceDetails = SD_getServiceDetails(name, exception);
            }
        }
    } else /*env is set, check the order*/ {
        char *comma = strchr(plugin, ',');

        if (plugin && comma) {
            char *result = NULL;
            result = strtok(plugin, delims);
            while (result != NULL) {
                if (0 == strcmp(result, available_plungins[0])) /*file*/ {
                    SD_freeException(exception);
                    list = sd_file_getServiceData(name, exception);
                    if (list) {
                        break;
                    }
		    else
		    	sd_file_freeServiceDataList(list);
                } else if (0 == strcmp(result, available_plungins[1])) /*bdii*/ {
                    SD_freeException(exception);
                    list = sd_bdii_getServiceData(name, exception);
                    if (list) {
                        break;
                    }
		    else
		    	sd_bdii_freeServiceDataList(list);
                } else {
                    SD_freeException(exception);
                    serviceDetails = SD_getServiceDetails(name, exception);
                    if (serviceDetails) {
                        break;
                    }
                }
                result = strtok(NULL, delims);
            }
        } else {
            if (plugin && 0 == strcmp(plugin, available_plungins[0])) /*file*/ {
                SD_freeException(exception);
                list = sd_file_getServiceData(name, exception);
            } else if (plugin && 0 == strcmp(plugin, available_plungins[1])) /*bdii*/ {
                SD_freeException(exception);
                list = sd_bdii_getServiceData(name, exception);
            } else {
                serviceDetails = SD_getServiceDetails(name, exception);
            }
        }
    }




    if (serviceDetails) {
        /* If we are emulating the getServiceData method, we have to make
         * a copy of the data list */
        int i;

        list = (SDServiceDataList *) malloc(sizeof (SDServiceDataList));
        if (!list)
            SD_setException(exception, SDStatus_FAILURE, ERROR_OUTOFMEMORY, NULL, 0);
        else {
            list->numItems = serviceDetails->data->numItems;
            list->items = (SDServiceData *) calloc(list->numItems, sizeof (SDServiceData));
            if (!list->items) {
                SD_setException(exception, SDStatus_FAILURE, ERROR_OUTOFMEMORY, NULL, 0);
                SD_freeServiceDataList(list);
                list = NULL;
            }
        }

        for (i = 0; list && i < list->numItems; i++) {
            list->items[i].key = dupstr(serviceDetails->data->items[i].key);
            list->items[i].value = dupstr(serviceDetails->data->items[i].value);
            if (!list->items[i].key || !list->items[i].value) {
                SD_setException(exception, SDStatus_FAILURE, ERROR_OUTOFMEMORY, NULL, 0);
                SD_freeServiceDataList(list);
                list = NULL;
                break;
            }
        }

        SD_freeServiceDetails(serviceDetails);
    }
    if (plugin)
        free(plugin);
    return list;
}
コード例 #15
0
int g2_sd_get_se_types_and_endpoints(const char *host, char ***se_types,
        char ***se_endpoints, char *errbuf, int errbufsz) {
    char host_tmp[255];
    int len_tmp = 0;
    char *port = NULL;
    LDAPMessage *entry = NULL;
    SDException exception;
    char *query = NULL;
    int i, nbentries = 0, n = 0, rc = 0;
    char **sep = NULL, **stp = NULL, **st = NULL, **sv = NULL, **ep = NULL;
    struct berval **value = NULL;
    int sav_errno = 0;
    LDAPMessage *reply = NULL;
    LDAP *ld = NULL;
    char *service_id = NULL;
    char *endpoint_id = NULL;    

    *se_types = NULL;
    *se_endpoints = NULL;

    if (!host) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_se_types_and_endpoints]: Hostname in empty", errbuf, errbufsz);
        return -1;
    }


    if ((ld = get_connection(&exception, errbuf, errbufsz)) == NULL) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_se_types_and_endpoints]: Cannot connect to BDII", errbuf, errbufsz);
        return (-1);
    }

    g2_sd_get_service_id(ld, host, &service_id, &endpoint_id, errbuf, errbufsz);
    if(!service_id)
    {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_se_types_and_endpoints]: ServiceID cannot be found", errbuf, errbufsz);
	if(ld)
		close_connection(ld);
	return (-1);      
	
    }       

    strncpy(host_tmp, host, 255);

    if ((port = strchr(host_tmp, ':')) != NULL)
        *port = 0;

    query = g_strdup_printf(GLUE2_QUERY_TYPE_ENDPOINTS, service_id);



    while (nbentries < 1 && !sav_errno) {

        rc = connect_search_ldap(glue2_base, query, NULL, ld, &exception, &reply, errbuf, errbufsz);
        if (rc != LDAP_SUCCESS) {
            if (reply) {
                ldap_msgfree(reply);
            }
            rc = -1;
            sav_errno = errno;
            break;
        }

        if ((nbentries = ldap_count_entries(ld, reply)) < 1) {
            SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_se_types_and_endpoints]: No entries found for host.", errbuf, errbufsz);
            if (reply) {
                ldap_msgfree(reply);
            }
            rc = -1;
            break;
        }

        ++nbentries;
        if ((st = calloc(nbentries, sizeof (char *))) == NULL || (sv = calloc(
                nbentries, sizeof (char *))) == NULL || (ep = calloc(nbentries,
                sizeof (char *))) == NULL || (stp = calloc(nbentries,
                sizeof (char *))) == NULL || (sep = calloc(nbentries,
                sizeof (char *))) == NULL) {
            if (reply) {
                ldap_msgfree(reply);
            }

            sav_errno = errno ? errno : ENOMEM;
            rc = -1;
            break;
        }

        for (entry = ldap_first_entry(ld, reply); entry != NULL && rc == 0; entry
                = ldap_next_entry(ld, entry)) {

            if ((value = ldap_get_values_len(ld, entry, GLUE2_ATTR_ENDPOINT)) != NULL) {
                if (value && value[0]->bv_val) {
                    ep[n] = strdup(value[0]->bv_val);
                    if (value)
                        ber_bvecfree(value);

                    if ((value = ldap_get_values_len(ld, entry, GLUE2_ATTR_TYPE)) == NULL) {
                        if (value && ep[n]) {
                            ber_bvecfree(value);
                            free(ep[n]);
                            continue;
                        }
                    }
                    if (st)
                        st[n] = strdup(value[0]->bv_val);
                    if (value)
                        ber_bvecfree(value);

                    if ((value = ldap_get_values_len(ld, entry, GLUE2_ATTR_VERSION))
                            == NULL) {
                        if (value && ep[n] && st[n]) {
                            ber_bvecfree(value);
                            free(ep[n]);
                            free(st[n]);
                            continue;
                        }
                    }
                    if (sv && value && value[0]->bv_val)
                        sv[n] = strdup(value[0]->bv_val);
                    if (value)
                        ber_bvecfree(value);
                    ++n;
                }
            } else {
                if (port == NULL) {
                    /* If port is not yet defined in host_tmp, and is available
                    // it is copied to host_tmp buffer
                    // ... But it will only be used if there is no GLUE2EndpointURL entry */
                    if (value)
                        ber_bvecfree(value);

                    value = ldap_get_values_len(ld, entry, "GLUE2EndpointURL");
                    if (value == NULL) {
                        if (nbentries == 1) {
                            sav_errno = EINVAL;
                            SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_se_types_and_endpoints]: No port published in the BDII for Glue2", errbuf, errbufsz);
                        }
                    } else if (value && value[0]->bv_val && len_tmp + strlen(value[0]->bv_val) + 1 < 255) {
                        port = host_tmp + len_tmp;
                        strcpy(port + 1, value[0]->bv_val);

                    } else {
                        if (value)
                            ber_bvecfree(value);
                        sav_errno = ENAMETOOLONG;
                        if (reply) {
                            ldap_msgfree(reply);
                        }

                        break;
                    }

                }
                if (value)
                    ber_bvecfree(value);
            }
        }
        if (reply) {
            ldap_msgfree(reply);
        }

    }

    if (rc < 0) {
        for (i = 0; i < n; ++i) {
            if (st && st[i])
                free(st[i]);
            if (sv && sv[i])
                free(sv[i]);
            if (ep && ep[i])
                free(ep[i]);
        }
        if (st)
            free(st);
        if (sv)
            free(sv);
        if (ep)
            free(ep);
        if (stp)
            free(stp);
        if (sep)
            free(sep);
        errno = sav_errno ? sav_errno : EINVAL;
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_se_types_and_endpoints]: No available information", errbuf, errbufsz);
    } else {
        if (n > 0) {

            for (i = 0; i < n; ++i) {
                if ((strcmp(st[i], "srm_v1") == 0 || strcmp(st[i], "srm_v2")
                        == 0) && ep[i]) {
                    stp[i] = strdup(st[i]);
                    sep[i] = strdup(ep[i]);
                } else if ((strcasecmp(st[i], "SRM") == 0) && (strncmp(sv[i],
                        "1.", 2)) == 0 && ep[i]) {
                    stp[i] = strdup("srm_v1");
                    sep[i] = strdup(ep[i]);
                } else if ((strcasecmp(st[i], "SRM") == 0) && (strncmp(sv[i],
                        "2.2", 3)) == 0 && ep[i]) {
                    stp[i] = strdup("srm_v2");
                    sep[i] = strdup(ep[i]);
                }
                free(st[i]);
                free(sv[i]);
                free(ep[i]);
            }
            free(st);
            free(sv);
            free(ep);
        } else if (n == 0 && port != NULL && stp && sep) {
            /* There were no GLUE2EndpointID entries...
            // ... so endpoint is hostname:port, and type is disk */
            *port = ':';
            stp[0] = strdup("disk");
            sep[0] = strdup(host_tmp);
        } else {
            free(stp);
            free(sep);
            rc = -1;
            SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_se_types_and_endpoints]: No available information found for SE", errbuf, errbufsz);
            errno = EINVAL;

        }

        if (rc == 0) {
            *se_types = stp;
            *se_endpoints = sep;
        }
    }

    if (ld)
        close_connection(ld);
    if (query)
        g_free(query);
    if (service_id)
    	free(service_id);	 
    if (endpoint_id)
    	free(endpoint_id);	 

    return (rc);
}
コード例 #16
0
/* get from the BDII the list of supported protocols with their associated
 * port number
 */
int g2_sd_get_seap_info(const char *host, char ***access_protocol, int **port, char *errbuf, int errbufsz) {
    char **ap = NULL, *attr = NULL;
    char *query = NULL;
    struct berval **value = NULL;
    BerElement *ber = NULL;
    int nbentries, i = 0, n = 0, rc = 0;
    int *pn = NULL;
    LDAPMessage *entry = NULL, *reply = NULL;
    SDException exception;
    int sav_errno = 0;
    char *tempUrl = NULL;
    char *base_scheme = NULL;
    char *base_host = NULL;
    char *base_path = NULL;
    int base_port = 0;
    LDAP *ld = NULL;
    char *service_id = NULL;
    char *endpoint_id = NULL;    

    if (!host) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_seap_info]: Hostname in null", errbuf, errbufsz);
        return -1;
    }


    if ((ld = get_connection(&exception, errbuf, errbufsz)) == NULL) {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_seap_info]: Cannot connect to BDII", errbuf, errbufsz);
        return (-1);
    }

    
    g2_sd_get_service_id(ld, host, &service_id, &endpoint_id, errbuf, errbufsz);
    if(!service_id)
    {
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_seap_info]: ServiceID cannot be found", errbuf, errbufsz);
	if(ld)
		close_connection(ld);	
	return (-1);      
	
    }       

    /*prepare the query */
    query = g_strdup_printf(GLUE2_QUERY_PROTO_PORT_TYPE, service_id);



    while (n < 1 && !sav_errno) {

        /*send query to bdii server*/
        rc = connect_search_ldap(glue2_base, query, g2_seap_attrs, ld, &exception, &reply, errbuf, errbufsz);
        if (rc != LDAP_SUCCESS) {
            if (reply) {
                ldap_msgfree(reply);
            }
            rc = -1;
            sav_errno = errno;
            break;
        }

        /*count entry # */
        if ((nbentries = ldap_count_entries(ld, reply)) < 1) {
            SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_seap_info]: No entries for host.", errbuf, errbufsz);
            if (reply) {
                ldap_msgfree(reply);
            }
            sav_errno = errno ? errno : ENOMEM;
            rc = -1;
            break;
        }


        nbentries++;
        /*allocate memory */
        if ((ap = (char **) calloc(nbentries, sizeof (char *))) == NULL || (pn
                = (int *) calloc(nbentries, sizeof (int))) == NULL) {
            if (reply) {
                ldap_msgfree(reply);
            }

            sav_errno = errno ? errno : ENOMEM;
            rc = -1;
            break;
        }


        for (entry = ldap_first_entry(ld, reply), n = 0; entry != NULL && rc
                == 0; entry = ldap_next_entry(ld, entry), ++n) {

            for (attr = ldap_first_attribute(ld, entry, &ber); attr != NULL
                    && rc == 0; attr = ldap_next_attribute(ld, entry, ber)) {

                if (!ap[n] && (value = ldap_get_values_len(ld, entry, attr))) {
                    if (value && value[0]->bv_val) {
                        if (strcmp(attr, "GLUE2EndpointURL") == 0) {
                            if ((ap[n] = strdup(value[0]->bv_val)) == NULL) {
                                rc = -1;
                                sav_errno = errno ? errno : ENOMEM;
                            } else {
                                tempUrl = ap[n];
                                if (tempUrl)
                                    parse_url(tempUrl, &base_scheme, &base_host, &base_port, &base_path);
                                if (base_scheme && base_port > 0) {
				    free(ap[n]);
                                    ap[n] = base_scheme; /* protocol */
                                    pn[n] = base_port; /* port */
                                } else {
                                    rc = -1;
                                    sav_errno = errno ? errno : ENOMEM;
                                }
                            }
                            if (value)
                                ber_bvecfree(value);
                        }
                    }
                }
                if (attr)
                    ldap_memfree(attr);
            }
            if (ber) {
                ber_free(ber, 0);
                ber = NULL;
            }
        }
        if (reply) {
            ldap_msgfree(reply);
        }

        if (base_host)
            free(base_host);
        if (base_path)
            free(base_path);
    }


    /* if something went wrong, give the memory free */
    if (rc < 0) {
        for (i = 0; i < n; ++i) {
            if (ap[i]) {
                free(ap[i]);
            }
        }
        if (ap && pn) {
            free(ap);
            free(pn);
        }
        SD_setException(&exception, SDStatus_FAILURE, "[BDII][g2_sd_get_seap_info]: No available information", errbuf, errbufsz);
        errno = sav_errno ? sav_errno : EINVAL;
    } else /*return the values via pointer*/ {
        *access_protocol = ap;
        *port = pn;
    }

    if (query)
        g_free(query);
    if (ld)
        close_connection(ld);
    if (service_id)
    	free(service_id);	
    if (endpoint_id)
    	free(endpoint_id);	

    return (rc);
}
コード例 #17
0
char *SD_getServiceDataItem(const char *name, const char *key,
        SDException *exception) {
    SDServiceDetails *serviceDetails = NULL;
    SDServiceDataList *list = NULL;
    char *value = NULL;
    char delims[] = ",";
    char *plugin = NULL;
    plugin = plugin_is_set();

    SD_setException(exception, SDStatus_SUCCESS, NULL, NULL, 0);

    if (NULL == plugin) /*env is not set*/ {
        list = sd_file_getServiceData(name, exception);
        if(!list){
		SD_freeException(exception);
		sd_file_freeServiceDataList(list);
		value = sd_bdii_getServiceDataItem(name, key, exception);
		if(!value){
			SD_freeException(exception);
			serviceDetails = SD_getServiceDetails(name, exception);
		}
	}

   
    } else /*env is set, check the order*/ {
        char *comma = strchr(plugin, ',');

        if (plugin && comma) {
            char *result = NULL;
            result = strtok(plugin, delims);
            while (result != NULL) {
                if (0 == strcmp(result, available_plungins[0])) /*file*/ {
                    SD_freeException(exception);
                    list = sd_file_getServiceData(name, exception);
                    if (list) {
                        break;
                    }
                } else if (0 == strcmp(result, available_plungins[1])) /*bdii*/ {
                    SD_freeException(exception);
                    value = sd_bdii_getServiceDataItem(name, key, exception);
                    if (value) {
                        break;
                    }
                } else {
                    SD_freeException(exception);
                    serviceDetails = SD_getServiceDetails(name, exception);
                    if (serviceDetails) {
                        break;
                    }
                }
                result = strtok(NULL, delims);
            }
        } else {
            if (plugin && 0 == strcmp(plugin, available_plungins[0])) /*file*/ {
                SD_freeException(exception);
                list = sd_file_getServiceData(name, exception);
            } else if (plugin && 0 == strcmp(plugin, available_plungins[1])) /*bdii*/ {
                SD_freeException(exception);
                list = sd_bdii_getServiceData(name, exception);
            } else {
                SD_freeException(exception);
                serviceDetails = SD_getServiceDetails(name, exception);
            }
        }
    }


    if (serviceDetails)
        list = serviceDetails->data;
    if (list) {
        /* If we are emulating the getServiceDataItem method, we have to
         * look up the key and make a copy of the value */
        int i;

        value = NULL;
        for (i = 0; i < list->numItems; i++) {
            if (!strcmp(list->items[i].key, key)) {
                value = dupstr(list->items[i].value);
                if (!value)
                    SD_setException(exception, SDStatus_FAILURE, ERROR_OUTOFMEMORY, NULL, 0);
                break; 
            }
        }
    }

    if (serviceDetails)
        SD_freeServiceDetails(serviceDetails);
    else if (list)
        SD_freeServiceDataList(list);


    if (plugin)
        free(plugin);
    return value;
}