Example #1
0
static expression *
get_expression(const char *selector)
{
   freesasa_yyscan_t scanner;
   YY_BUFFER_STATE state;
   int err;
   expression *expression = NULL;

   if (freesasa_yylex_init(&scanner)) {
       fail_msg("lexer failed");
   } else {
       state = freesasa_yy_scan_string(selector, scanner);
       err = freesasa_yyparse(&expression, scanner);
       if (err) {
           if (err == 1) fail_msg("parser failed");
           if (err == 2) mem_fail();
           expression_free(expression);
           expression = NULL;
       }
       freesasa_yy_delete_buffer(state, scanner);
       freesasa_yylex_destroy(scanner);
   }

   return expression;
}
Example #2
0
static int
k4ping(krb5_context ctx, const char *host, krb5_principal princ,
    const char *passwd, krb5_principal sprinc)
{
	krb5_error_code	kerr;
	int		ret;
	char		name[ANAME_SZ];
	char		instance[INST_SZ];
	char		realm[REALM_SZ];

	VERBOSE(1, (stderr, "initiating kerberos4/udp ping to %s\n", host));
	parse_kdc(host);
	kerr = krb5_524_conv_principal(ctx, princ, name, instance, realm);
	if (kerr) {
		fail_msg("kerberos4", SOCK_DGRAM, host, error_message(kerr));
		ret = 1;
		goto bail;
	}

	ret = krb_get_pw_in_tkt(name, instance, realm, "krbtgt",
	    realm, 3600 /* seconds */, (char *)passwd);
	if (ret) {
		fail_msg("kerberos4", SOCK_DGRAM, host, krb_get_err_text(ret));
		goto bail;
	}
	ret = kvno4(ctx, host, sprinc);
	/* XXXrcd */
	k_logout_k4(ctx, NULL, K_OPT_NONE);

bail:
	return ret;
}
Example #3
0
static int
kvno4(krb5_context ctx, const char *host, krb5_principal sprinc)
{
	krb5_error_code	kerr;
	KTEXT_ST	req;
	CREDENTIALS	creds;
	int		err = 0;
	char		name[ANAME_SZ];
	char		instance[INST_SZ];
	char		realm[REALM_SZ];

	VERBOSE(1, (stderr, "initiating kvno4/udp ping to %s\n", host));

	kerr = krb5_524_conv_principal(ctx, sprinc, name, instance, realm);
	if (kerr) {
		fail_msg("kvno4", SOCK_DGRAM, host, error_message(kerr));
		goto bail;
	}

	err = krb_mk_req(&req, name, instance, realm, 0);
	if (err)
		goto bail;

        err = krb_get_cred(name, instance, realm, &creds);
        if (err)
		goto bail;

	VERBOSE(2, (stderr, "%s.%s@%s kvno = %d\n", name, instance, realm,
	    creds.kvno));

bail:
	if (err)
		fail_msg("kvno4", SOCK_DGRAM, host, krb_get_err_text(err));
	return err;
}
Example #4
0
/**
    Read a line specifying an atom, store it in the config. Use
    supplied types to add assign radius and class. Returns
    FREESASA_WARN for duplicates. Returns FREESASA_FAIL for syntax
    errors or memory allocation errors. FREESASA_SUCCESS else.
 */
static int
read_atoms_line(struct classifier_config *config,
                const struct classifier_types *types,
                const char* line)
{
    size_t blen=100;
    char buf1[blen], buf2[blen], buf3[blen];
    int res, type, atom;
    if (sscanf(line,"%s %s %s",buf1,buf2,buf3) == 3) {
        type = find_string(types->name, buf3, types->n_types);
        if (type < 0) 
            return freesasa_fail("Unknown atom type '%s' in line '%s'",buf3,line);
        res = add_residue(config,buf1);
        if (res == FREESASA_FAIL) return fail_msg("");
        atom = add_atom(config->residue[res],
                        buf2,
                        types->type_radius[type],
                        types->type_class[type]);

        if (atom == FREESASA_FAIL) return fail_msg("");
        if (atom == FREESASA_WARN) return FREESASA_WARN;
        
    } else {
        return freesasa_fail("in %s(): Could not parse line '%s', expecting triplet of type "
                             "'RESIDUE ATOM CLASS', for example 'ALA CB C_ALI'.",
                             __func__, line);
    }
    return FREESASA_SUCCESS;
}
void CDBConnection::execute(const TUpdateReservationTxnInput* pIn, TUpdateReservationTxnOutput* pOut){
	pOut->status = CBaseTxnErr::SUCCESS;


	char query[4096];
	sql_result_t result;
	int length;
	char* val;
	int r = 0;
	uint64_t r_f_id = pIn->flight_id;
	uint64_t r_seat = pIn->seat;
	uint64_t c_id = pIn->customer_id;
	uint64_t r_id;
	string attr_val("random attr");
	TIMESTAMP cur_dts;
	char cur_dts_string[100];
	uint64_t new_r_f_id, new_r_id, new_r_seat;

	sprintf(cur_dts_string, "%hd-%hd-%hd %hd:%hd:%hd.%*d",
			&cur_dts.year,
			&cur_dts.month,
			&cur_dts.day,
			&cur_dts.hour,
			&cur_dts.minute,
			&cur_dts.second);


	sprintf(query, CHECK_SEAT, r_f_id, r_seat);
	r = dbt5_sql_execute(query, &result, "CHECK_SEAT");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);

		r_id = atol(dbt5_sql_getvalue(&result, 0, length));
		dbt5_sql_close_cursor(&result);
	}else{
		string fail_msg("check seats failed");
		throw fail_msg.c_str();
	}

	sprintf(query, CHECK_CUSTOMER, r_f_id, c_id);
	r = dbt5_sql_execute(query, &result, "CHECK_CUSTOMER");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);

		new_r_id = atol(dbt5_sql_getvalue(&result, 0, length));
		dbt5_sql_close_cursor(&result);
	}else{
		string fail_msg("check customer failed");
		throw fail_msg.c_str();
	}

	sprintf(query, UPDATE_RESERVATION, r_seat, cur_dts_string, attr_val.c_str(), r_id, c_id, f_id);
	r = dbt5_sql_execute(query, &result, "UPDATE_RESERVATION");
	if (!r){
		string fail_msg("update reservation failed");
		throw fail_msg.c_str();
	}


}
Example #6
0
static int
sr_do_threads(int n_threads,
              sr_data *sr)
{
    pthread_t thread[n_threads];
    sr_data srt[n_threads];
    int thread_block_size = sr->n_atoms/n_threads;
    int res, return_value = FREESASA_SUCCESS;
    int threads_created = 0;

    // divide atoms evenly over threads
    for (int t = 0; t < n_threads; ++t) {
        srt[t] = *sr;
        srt[t].i1 = t*thread_block_size;
        if (t == n_threads-1) srt[t].i2 = sr->n_atoms;
        else srt[t].i2 = (t+1)*thread_block_size;
        res = pthread_create(&thread[t], NULL, sr_thread, (void *) &srt[t]);
        if (res) {
            return_value = fail_msg(freesasa_thread_error(res));
            break;
        }
        ++threads_created;
    }
    for (int t = 0; t < threads_created; ++t) {
        int res = pthread_join(thread[t], NULL);
        if (res) {
            return_value = fail_msg(freesasa_thread_error(res));
        }
    }
    return return_value;
}
VOID
Security_Tests_Validate_Interface(
    void **state
    )
{
    PSECURITY_TEST_STATE pState = *state;

    if (!pState->pInterface)
    {
        fail_msg("Interface not loaded. pInterface = NULL\n");
        goto error;
    }

    if (!pState->pInterface->pFnInitialize ||
        !pState->pInterface->pFnGetCaps ||
        !pState->pInterface->pFnCapOverride ||
        !pState->pInterface->pFnAddKeyPair ||
        !pState->pInterface->pFnCreateKeyPair ||
        !pState->pInterface->pFnSign ||
        !pState->pInterface->pFnVerify ||
        !pState->pInterface->pFnCloseHandle ||
        !pState->pInterface->pFnFreeMemory)
    {
        fail_msg("Interface table is not valid. missing entries\n");
    }

error:
    return;
}
Example #8
0
File: t-thread.c Project: 1587/npth
int
main (int argc, char *argv[])
{
  int rc;
  npth_attr_t tattr;
  int state;
  npth_t tid1, tid2;
  void *retval;

  if (argc >= 2 && !strcmp (argv[1], "--verbose"))
    opt_verbose = 1;

  rc = npth_init ();
  fail_if_err (rc);

  rc = npth_mutex_init (&counter_mutex, NULL);
  fail_if_err (rc);

  rc = npth_attr_init (&tattr);
  fail_if_err (rc);
  rc = npth_attr_getdetachstate (&tattr, &state);
  fail_if_err (rc);
  if ( state != NPTH_CREATE_JOINABLE )
    fail_msg ("new tattr is not joinable");

  info_msg ("creating thread-one");
  rc = npth_create (&tid1, &tattr, thread_one, NULL);
  fail_if_err (rc);
  npth_setname_np (tid1, "thread-one");

  info_msg ("creating thread-two");
  rc = npth_create (&tid2, &tattr, thread_two, NULL);
  fail_if_err (rc);
  npth_setname_np (tid2, "thread-two");

  rc = npth_attr_destroy (&tattr);
  fail_if_err (rc);

  info_msg ("waiting for thread-one to terminate");
  rc = npth_join (tid1, &retval);
  fail_if_err (rc);
  if (retval != (void*)4711)
    fail_msg ("thread-one returned an unexpected value");

  info_msg ("waiting for thread-two to terminate");
  rc = npth_join (tid2, &retval);
  fail_if_err (rc);
  if (retval != (void*)4722)
    fail_msg ("thread-two returned an unexpected value");

  if (counter != 100)
    fail_msg ("counter value not as expected");

  return 0;
}
Example #9
0
/* Root is not converted to xmlNodePtr, we skip immediately to children */
static int
node2xml(xmlNodePtr *xml_node,
         freesasa_node *node,
         int exclude_type,
         int options)
{
    freesasa_node *child;
    xmlNodePtr xml_child = NULL;

    assert(xml_node);
    assert(node);

    child = freesasa_node_children(node);
    *xml_node = NULL;

    if (freesasa_node_type(node) == exclude_type) return FREESASA_SUCCESS;

    switch (freesasa_node_type(node)) {
    case FREESASA_NODE_STRUCTURE:
        *xml_node = structure2xml(node, options);
        break;
    case FREESASA_NODE_CHAIN:
        *xml_node = chain2xml(node, options);
        break;
    case FREESASA_NODE_RESIDUE:
        *xml_node = residue2xml(node, options);
        break;
    case FREESASA_NODE_ATOM:
        *xml_node = atom2xml(node, options);
        break;
    case FREESASA_NODE_ROOT:
    default:
        assert(0 && "tree illegal");
    }
    if (*xml_node == NULL)
        return fail_msg("error creating XML-node");

    /* simplify? */
    while (child != NULL) {
        if (node2xml(&xml_child, child, exclude_type, options) == FREESASA_FAIL) {
            return fail_msg("");
        }

        if (xml_child != NULL &&
            xmlAddChild(*xml_node, xml_child) == NULL) {
            xmlFreeNode(*xml_node);
            xmlFreeNode(xml_child);
            return fail_msg("");
        }
        child = freesasa_node_next(child);
    }

    return FREESASA_SUCCESS;
}
Example #10
0
static int
select_list(expression_type parent_type,
            struct selection *selection,
            const freesasa_structure *structure,
            const expression *expr)
{
    int resr, resl;
    expression *left, *right;

    if (expr == NULL)
        return fail_msg("NULL expression");

    left = expr->left;
    right = expr->right;

    switch(expr->type) {
    case E_PLUS:
        if (left == NULL || right == NULL)
            return fail_msg("NULL expression");
        resl = select_list(parent_type, selection, structure, left);
        resr = select_list(parent_type, selection, structure, right);
        if (resl == FREESASA_WARN || resr == FREESASA_WARN)
            return FREESASA_WARN;
        break;
    case E_RANGE:
        if (left == NULL || right == NULL)
            return fail_msg("NULL expression");
        return select_range(E_RANGE, parent_type, selection, structure, left, right);
    case E_RANGE_OPEN_L:
        if (left != NULL || right == NULL)
            return fail_msg("NULL expression");
        return select_range(E_RANGE_OPEN_L, parent_type, selection, structure, left, right);
    case E_RANGE_OPEN_R:
        if (left == NULL || right != NULL)
            return fail_msg("NULL expression");
        return select_range(E_RANGE_OPEN_R, parent_type, selection, structure, left, right);
    case E_ID:
    case E_NUMBER:
        if (is_valid_id(parent_type, expr) == FREESASA_SUCCESS)
            select_id(parent_type, selection, structure, expr->value);
        else return freesasa_warn("select: %s: '%s' invalid %s",
                                  e_str(parent_type), expr->value, e_str(expr->type));
        break;
    default:
        return freesasa_fail("select: parse error (expression: '%s %s')",
                             e_str(parent_type), e_str(expr->type));
    }
    return FREESASA_SUCCESS;
}
Example #11
0
static int
kvno5(krb5_context ctx, const char *host, int socktype, krb5_principal princ,
    krb5_principal sprinc, krb5_ccache ccache)
{
	krb5_error_code	 kerr = 0;
	krb5_creds	 increds;
	krb5_creds	*outcreds = NULL;
	krb5_ticket	*ticket = NULL;

	VERBOSE(1, (stderr, "initiating kvno5/%s ping to %s\n",
	    socktype == SOCK_DGRAM ? "udp" : "tcp", host));

	memset(&increds, 0x0, sizeof(increds));
	increds.client = princ;
	increds.server = sprinc;
	kerr = krb5_get_credentials(ctx, 0, ccache, &increds, &outcreds);
	if (kerr)
		goto bail;

        kerr = krb5_decode_ticket(&outcreds->ticket, &ticket);
        if (kerr)
		goto bail;

	VERBOSE(2, (stderr, "kvno5 says kvno = %d\n", ticket->enc_part.kvno));

bail:
	if (kerr)
		fail_msg("kvno5", socktype, host, error_message(kerr));
	if (ticket)
		krb5_free_ticket(ctx, ticket);
	if (outcreds)
		krb5_free_creds(ctx, outcreds);

	return kerr;
}
Example #12
0
freesasa_selection *
freesasa_selection_new(const char *command,
                       const freesasa_structure *structure,
                       const freesasa_result *result)
{
    char name[FREESASA_MAX_SELECTION_NAME];
    double area;
    freesasa_selection *selection;
    int n_atoms;

    n_atoms = select_area_impl(command, name, &area, structure, result);

    if (n_atoms == FREESASA_FAIL) {
        fail_msg("");
        return NULL;
    }

    selection = freesasa_selection_alloc(name, command);
    if (selection == NULL) {
        mem_fail();
        return NULL;
    }

    selection->area = area;
    selection->n_atoms = n_atoms;

    return selection;
}
Example #13
0
static int
selection_join(struct selection *target,
               const struct selection *s1,
               const struct selection *s2,
               int type)
{
    int n, i;

    if (s1 == NULL || s2 == NULL || target == NULL)
        return fail_msg("trying to join NULL selections");

    assert(s1->size == s2->size);
    assert(s1->size == target->size);

    n = target->size;

    switch (type) {
    case E_AND:
        for (i = 0; i < n; ++i)
            target->atom[i] = s1->atom[i] && s2->atom[i];
        break;
    case E_OR:
        for (i = 0; i < n; ++i)
            target->atom[i] = s1->atom[i] || s2->atom[i];
        break;
    default:
        assert(0);
    }

    return FREESASA_SUCCESS;
}
Example #14
0
static coord_t *
test_points(int N) 
{
    // Golden section spiral on a sphere
    // from http://web.archive.org/web/20120421191837/http://www.cgafaq.info/wiki/Evenly_distributed_points_on_sphere
    double dlong = M_PI*(3-sqrt(5)), dz = 2.0/N, longitude = 0, z = 1-dz/2, r;
    coord_t *coord = freesasa_coord_new();
    double *tp = malloc(3*N*sizeof(double));
    if (tp == NULL || coord == NULL) {
        freesasa_coord_free(coord);
        free(tp);
        mem_fail();
        return NULL;
    }

    for (double *p = tp; p-tp < 3*N; p += 3) {
        r = sqrt(1-z*z);
        p[0] = cos(longitude)*r;
        p[1] = sin(longitude)*r;
        p[2] = z;
        z -= dz;
        longitude += dlong;
    }

    if (freesasa_coord_append(coord,tp,N) == FREESASA_FAIL) {
        fail_msg("");
        freesasa_coord_free(coord);
        coord = NULL;
    }
    free(tp);

    return coord;
}
Example #15
0
/******************************************************************************
 *                                                                            *
 * Function: zbx_mock_str_to_return_code                                      *
 *                                                                            *
 * Purpose: converts common function return code from text format             *
 *                                                                            *
 ******************************************************************************/
int	zbx_mock_str_to_return_code(const char *str)
{
	if (0 == strcmp(str, "SUCCEED"))
		return SUCCEED;

	if (0 == strcmp(str, "FAIL"))
		return FAIL;

	if (0 == strcmp(str, "NOTSUPPORTED"))
		return NOTSUPPORTED;

	if (0 == strcmp(str, "NETWORK_ERROR"))
		return NETWORK_ERROR;

	if (0 == strcmp(str, "TIMEOUT_ERROR"))
		return TIMEOUT_ERROR;

	if (0 == strcmp(str, "AGENT_ERROR"))
		return AGENT_ERROR;

	if (0 == strcmp(str, "GATEWAY_ERROR"))
		return GATEWAY_ERROR;

	if (0 == strcmp(str, "CONFIG_ERROR"))
		return CONFIG_ERROR;

	if (0 == strcmp(str, "SYSINFO_RET_OK"))
		return SYSINFO_RET_OK;

	if (0 == strcmp(str, "SYSINFO_RET_FAIL"))
		return SYSINFO_RET_FAIL;

	fail_msg("Unknown return code  \"%s\"", str);
	return 0;
}
Example #16
0
int main(VOID)
{
    int ret = 0;

    const struct CMUnitTest VMCASrvPlugin_Tests[] =
    {
        cmocka_unit_test_setup_teardown(
                VMCAPluginInitialize_Valid,
                NULL,
                NULL),
        cmocka_unit_test_setup_teardown(
                VMCAPluginInitialize_NoEntryPoint,
                NULL,
                NULL),
        cmocka_unit_test_setup_teardown(
                VMCAPluginInitialize_InvalidVTable,
                NULL,
                NULL),
    };

    ret = cmocka_run_group_tests(VMCASrvPlugin_Tests, NULL, NULL);
    if (ret)
    {
        fail_msg("%s", "VMCA plugin tests failed");
    }

    return ret;
}
Example #17
0
int main(VOID)
{
    int ret = 0;

    const struct CMUnitTest tests[] = {
        cmocka_unit_test(Test_LwCAInitCA_Valid),
        cmocka_unit_test(Test_LwCAInitCA_Invalid),
        cmocka_unit_test(Test_LwCACreateRootCA_Valid),
        cmocka_unit_test(Test_LwCACreateRootCA_Invalid),
        cmocka_unit_test(Test_LwCAGetCACertificates_Valid),
        cmocka_unit_test(Test_LwCAGetCACertificates_Invalid),
        cmocka_unit_test(Test_LwCAGetSignedCertificate_Valid),
        cmocka_unit_test(Test_LwCAGetSignedCertificate_Invalid),
        cmocka_unit_test(Test_LwCACreateIntermediateCA_Valid),
        cmocka_unit_test(Test_LwCACreateIntermediateCA_Invalid),
        cmocka_unit_test(Test_LwCARevokeCertificate_Valid),
        cmocka_unit_test(Test_LwCARevokeCertificate_Invalid),
        cmocka_unit_test(Test_LwCARevokeIntermediateCA_Valid),
        cmocka_unit_test(Test_LwCARevokeIntermediateCA_Invalid),
        cmocka_unit_test(Test_LwCAGetCACrl_Valid),
        cmocka_unit_test(Test_LwCAGetCACrl_Invalid),
    };

    ret = cmocka_run_group_tests(tests, Test_LwCAAPITests_Setup, Test_LwCAAPI_Teardown);

    if (ret)
    {
        fail_msg("%s", "MutentCA API tests failed");
    }

    return ret;
}
Example #18
0
/******************************************************************************
 *                                                                            *
 * Function: zbx_mock_str_to_token_type                                       *
 *                                                                            *
 * Purpose: converts token type from text format                              *
 *                                                                            *
 ******************************************************************************/
void	zbx_mock_str_to_token_type(const char *str, int *out)
{
	if (0 == strcmp(str, "ZBX_TOKEN_OBJECTID"))
		*out = ZBX_TOKEN_OBJECTID;
	else if (0 == strcmp(str, "ZBX_TOKEN_MACRO"))
		*out = ZBX_TOKEN_MACRO;

	else if (0 == strcmp(str, "ZBX_TOKEN_LLD_MACRO"))
		*out = ZBX_TOKEN_LLD_MACRO;

	else if (0 == strcmp(str, "ZBX_TOKEN_USER_MACRO"))
		*out = ZBX_TOKEN_USER_MACRO;

	else if (0 == strcmp(str, "ZBX_TOKEN_FUNC_MACRO"))
		*out = ZBX_TOKEN_FUNC_MACRO;

	else if (0 == strcmp(str, "ZBX_TOKEN_SIMPLE_MACRO"))
		*out = ZBX_TOKEN_SIMPLE_MACRO;

	else if (0 == strcmp(str, "ZBX_TOKEN_REFERENCE"))
		*out = ZBX_TOKEN_REFERENCE;

	else if (0 == strcmp(str, "ZBX_TOKEN_LLD_FUNC_MACRO"))
		*out = ZBX_TOKEN_LLD_FUNC_MACRO;
	else
		fail_msg("Unknown token type \"%s\"", str);
}
Example #19
0
void CDBConnection::execute(const TSendPaymentTxnInput* pIn, TSendPaymentTxnOutput* pOut){
	pOut->status = CBaseTxnErr::SUCCESS;

	char query[1024];
	sql_result_t result;
	int length;
	char* val;
	int r = 0;
	uint64_t send_acct = pIn->send_acct;
	uint64_t dest_acct = pIn->dest_acct;
	float balance = 0;
	float amount = pIn->amount;

	sprintf(query, SP_GET_SENDACCOUNT, send_acct);
	r = dbt5_sql_execute(query, &result, "GET_SENDACCOUNT");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);
		dbt5_sql_close_cursor(&result);
	}else{
		string fail_msg("get sendaccount fails");
		throw fail_msg.c_str();
	}

	sprintf(query, SP_GET_DESTACCOUNT, dest_acct);
	r = dbt5_sql_execute(query, &result, "GET_DEST_ACCOUNT");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);
		dbt5_sql_close_cursor(&result);
	}else{
		string fail_msg("get destaccount fails");
		throw fail_msg.c_str();
	}

	sprintf(query, SP_GET_CHECKINGBALANCE, send_acct);
	r = dbt5_sql_execute(query, &result, "GET_CHECKING_BALANCE");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);
		dbt5_sql_close_cursor(&result);
	}else{
		string fail_msg("get checking balance fails");
		throw fail_msg.c_str();
	}

	sprintf(query, SP_UPDATE_CHECKINGBALANCE, amount*(-1), sned_acct);
	r = dbt5_sql_execute

}
Example #20
0
static xmlNodePtr
parameters2xml(const freesasa_parameters *p)
{
    xmlNodePtr xml_node = xmlNewNode(NULL, BAD_CAST "parameters");
    char buf[20];

    if (xml_node == NULL) {
        fail_msg("");
        return NULL;
    }

    if (xmlNewProp(xml_node, BAD_CAST "algorithm", BAD_CAST freesasa_alg_name(p->alg)) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%f", p->probe_radius);
    if (xmlNewProp(xml_node, BAD_CAST "probeRadius", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    switch(p->alg) {
    case FREESASA_SHRAKE_RUPLEY:
        sprintf(buf, "%d", p->shrake_rupley_n_points);
        break;
    case FREESASA_LEE_RICHARDS:
        sprintf(buf, "%d", p->lee_richards_n_slices);
        break;
    default:
        assert(0);
        break;
    }
    if (xmlNewProp(xml_node, BAD_CAST "resolution", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    return xml_node;

 cleanup:
    xmlFreeNode(xml_node);
    return NULL;
}
Example #21
0
static xmlNodePtr
chain2xml(const freesasa_node *node,
          int options)
{
    xmlNodePtr xml_node = NULL, xml_area = NULL;
    char buf[20];

    xml_node = xmlNewNode(NULL, BAD_CAST "chain");
    if (xml_node == NULL) {
        fail_msg("");
        return NULL;
    }

    if (xmlNewProp(xml_node, BAD_CAST "label",
                   BAD_CAST freesasa_node_name(node)) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%d", freesasa_node_chain_n_residues(node));
    if (xmlNewProp(xml_node, BAD_CAST "nResidues", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    xml_area = nodearea2xml(freesasa_node_area(node), "area");
    if (xml_area == NULL) {
        fail_msg("");
        goto cleanup;
    }

    if (xmlAddChild(xml_node, xml_area) == NULL) {
        fail_msg("");
        xmlFreeNode(xml_area);
        goto cleanup;
    }

    return xml_node;

 cleanup:
    xmlFreeNode(xml_node);
    return NULL;
}
Example #22
0
static xmlNodePtr
nodearea2xml(const freesasa_nodearea *area,
             const char *name)
{
    xmlNodePtr xml_node = xmlNewNode(NULL, BAD_CAST name);
    char buf[20];

    sprintf(buf, "%.3f", area->total);
    if (xmlNewProp(xml_node, BAD_CAST "total", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->polar);
    if (xmlNewProp(xml_node, BAD_CAST "polar", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->apolar);
    if (xmlNewProp(xml_node, BAD_CAST "apolar", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->main_chain);
    if (xmlNewProp(xml_node, BAD_CAST "mainChain", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    sprintf(buf, "%.3f", area->side_chain);
    if (xmlNewProp(xml_node, BAD_CAST "sideChain", BAD_CAST buf) == NULL) {
        fail_msg("");
        goto cleanup;
    }

    return xml_node;

 cleanup:
    xmlFreeNode(xml_node);
    return NULL;
}
Example #23
0
zbx_mock_handle_t	zbx_mock_get_object_member_handle(zbx_mock_handle_t object, const char *name)
{
	zbx_mock_error_t	err;
	zbx_mock_handle_t	member;

	if (ZBX_MOCK_SUCCESS != (err = zbx_mock_object_member(object, name, &member)))
		fail_msg("Cannot read object member \"%s\": %s", name, zbx_mock_error_string(err));

	return member;
}
Example #24
0
zbx_mock_handle_t	zbx_mock_get_parameter_handle(const char *path)
{
	zbx_mock_error_t	err;
	zbx_mock_handle_t	parameter;

	if (ZBX_MOCK_SUCCESS != (err = zbx_mock_parameter(path, &parameter)))
		fail_msg("Cannot read parameter at \"%s\": %s", path, zbx_mock_error_string(err));

	return parameter;
}
Example #25
0
/******************************************************************************
 *                                                                            *
 * Function: zbx_mock_str_to_value_type                                       *
 *                                                                            *
 * Purpose: converts item value type from text format                         *
 *                                                                            *
 ******************************************************************************/
int	zbx_mock_str_to_family(const char *str)
{
	if (0 == strcmp(str, "AF_INET"))
		return AF_INET;

	if (0 == strcmp(str, "AF_INET6"))
		return AF_INET6;

	fail_msg("Unknown family \"%s\"", str);
	return AF_UNSPEC;
}
Example #26
0
freesasa_classifier*
freesasa_classifier_from_file(FILE *file)
{
    assert(file);

    struct classifier_config *config = read_config(file);
    if (config == NULL) {
        fail_msg("");
        return NULL;
    }
    return init_classifier(config);
}
Example #27
0
static xmlNodePtr
selection2xml(const freesasa_selection *selection)
{
    xmlNodePtr xml_selection = xmlNewNode(NULL, BAD_CAST "selection");
    char buf[20];

    sprintf(buf, "%.3f", freesasa_selection_area(selection));

    if (xml_selection == NULL) {
        fail_msg("");
    } else {
        if (xmlNewProp(xml_selection, BAD_CAST "name", BAD_CAST freesasa_selection_name(selection)) == NULL ||
            xmlNewProp(xml_selection, BAD_CAST "area", BAD_CAST buf) == NULL) {
            fail_msg("");
            xmlFreeNode(xml_selection);
            xml_selection = NULL;
        }
    }

    return xml_selection;
}
Example #28
0
static xmlNodePtr
add_selections_to_xmlNode(const freesasa_selection **selections,
                          xmlNodePtr parent)
{
    xmlNodePtr xml_selection;

    while (*selections) {
        xml_selection = selection2xml(*selections);
        if (xml_selection == NULL) {
            fail_msg("");
            return NULL;
        }

        if (xmlAddChild(parent, xml_selection) == NULL) {
            fail_msg("");
            xmlFreeNode(xml_selection);
            return NULL;
        }
        ++selections;
    }
    return parent;
}
Example #29
0
static int
selection_not(struct selection *s)
{
    int i;

    if (s == NULL) return fail_msg("NULL selection");

    for (i = 0; i < s->size; ++i) {
        s->atom[i] = ! s->atom[i];
    }

    return FREESASA_SUCCESS;
}
Example #30
0
static void	test_match(const char *prefix, zbx_mock_handle_t hmatch, zbx_prometheus_condition_test_t *match)
{
	char			buffer[MAX_STRING_LEN];
	zbx_mock_handle_t	hkey;

	if (-1 != hmatch && NULL == match)
		fail_msg("expected to parse %s filter", prefix);

	if (-1 == hmatch && NULL != match)
		fail_msg("did not expect to parse %s filter", prefix);

	if (-1 == hmatch)
		return;

	zbx_snprintf(buffer, sizeof(buffer), "%s filter key", prefix);

	if (ZBX_MOCK_SUCCESS != zbx_mock_object_member(hmatch, "key", &hkey))
		hkey = -1;

	if (-1 != hkey && NULL == match->key)
		fail_msg("expected to parse %s", buffer);

	if (-1 == hkey && NULL != match->key)
		fail_msg("did not expect to parse %s", buffer);

	if (-1 != hkey)
	{
		const char	*key;

		zbx_mock_string(hkey, &key);
		zbx_mock_assert_str_eq(buffer, key, match->key);
	}

	zbx_snprintf(buffer, sizeof(buffer), "%s filter pattern", prefix);
	zbx_mock_assert_str_eq(buffer, zbx_mock_get_object_member_string(hmatch, "pattern"), match->pattern);
	zbx_snprintf(buffer, sizeof(buffer), "%s filter operation", prefix);
	zbx_mock_assert_str_eq(buffer, zbx_mock_get_object_member_string(hmatch, "op"), match->op);
}