Ejemplo n.º 1
0
unsigned long q_delete_ny(unsigned long qid)
{
	unsigned long rc;

	free(__itc_array[qid]->m.q);
	rc = sm_delete(qid);
	return (rc);
}
Ejemplo n.º 2
0
int
osip_sem_destroy (struct osip_sem *_sem)
{
  osip_sem_t *sem = (osip_sem_t *) _sem;
  if (sem == NULL)
    return 0;
  sm_delete (sem->id);
  osip_free (sem);
  return (0);
}
Ejemplo n.º 3
0
void
osip_mutex_destroy (struct osip_mutex *_mut)
{
  osip_mutex_t *mut = (osip_mutex_t *) _mut;
  if (mut)
    {
      sm_delete (mut->id);
      osip_free (mut);
    }
}
Ejemplo n.º 4
0
unsigned long q_vdelete_ny(unsigned long qid)
{
	unsigned long rc;
	unsigned int i;

	for (i = 0; i < __itc_array[qid]->sizeof_q; i++) {
		free(__itc_array[qid]->m.qv[i].mb);
	}
	free(__itc_array[qid]->m.qv);
	rc = sm_delete(qid);
	return (rc);
}
Ejemplo n.º 5
0
unsigned long q_create_ny(char name[4],
			  unsigned long count,
			  unsigned long flags, unsigned long *qid)
{
	unsigned long rc;

	if ((rc = sm_create(name, 0, flags, qid)) != ERR_OK)
		return (rc);

	if ((__itc_array[__itc_idx]->m.q =
	     (q_t *) calloc(count, sizeof(q_t))) == NULL) {
		sm_delete(*qid);
		return (ERR_NOMEM);
	}

	__itc_array[__itc_idx]->sizeof_q = count;

	__itc_array[__itc_idx]->b_type = S_QUEUE;
	__itc_array[__itc_idx]->min_idx = 0;
	__itc_array[__itc_idx]->mout_idx = 0;
	return (ERR_OK);
}
int main(void) {

	nw_matrix_t* matrix;
	substitution_matrix_t* three_param_nuc_subs_model = create_two_param_nuc_subs_matrix();
	substitution_matrix_t* blosum50_protein_subs_model = create_blosum50_subs_matrix();

	matrix = nw_align_sequences(
		"ATTAAG",
		"AATCTAGC",
		three_param_nuc_subs_model,
		2
	);
	
	nw_print_scores(matrix);
	printf("%s\n", matrix->gappedSequenceA);
	printf("%s\n", matrix->gappedSequenceB);
	printf("score = %d\n\n", matrix->score);
	nw_free_matrix(matrix);


	matrix = nw_align_sequences(
		"TAATGGA",
		"AACGGTA",
		three_param_nuc_subs_model,
		2
	);
	
	nw_print_scores(matrix);
	printf("%s\n", matrix->gappedSequenceA);
	printf("%s\n", matrix->gappedSequenceB);
	printf("score = %d\n\n", matrix->score);
	nw_free_matrix(matrix);

	
	matrix = nw_align_sequences(
		"TAATGGATACCGGAA",
		"AACGGTAAAGGAAAATTAAGG",
		three_param_nuc_subs_model,
		2
	);
	
	nw_print_scores(matrix);
	printf("%s\n", matrix->gappedSequenceA);
	printf("%s\n", matrix->gappedSequenceB);
	printf("score = %d\n\n", matrix->score);
	nw_free_matrix(matrix);



	matrix = nw_align_sequences(
		"HEAGAWGHEE",
		"PAWHEAE", 
		blosum50_protein_subs_model,
		8);

	nw_print_scores(matrix);
	nw_print_vectors(matrix);
	printf("%s\n", matrix->gappedSequenceA);
	printf("%s\n", matrix->gappedSequenceB);
	printf("score = %d\n\n", matrix->score);

	sm_delete(three_param_nuc_subs_model);
	sm_delete(blosum50_protein_subs_model);

	return 0;
}
Ejemplo n.º 7
0
/** register set handler */
static void _authreg_register_set(c2s_t c2s, sess_t sess, nad_t nad)
{
    int ns = 0, elem, attr;
    char username[1024], password[1024];

    /* if we're not configured for registration (or pw changes), or we can't set passwords, fail outright */
    if(!(sess->host->ar_register_enable || sess->host->ar_register_password) || c2s->ar->set_password == NULL) {
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_NOT_ALLOWED), 0));
        return;
    }

    ns = nad_find_scoped_namespace(nad, uri_REGISTER, NULL);

    /* removals */
    if(sess->active && nad_find_elem(nad, 1, ns, "remove", 1) >= 0) {
        /* only if full reg is enabled */
        if(!sess->host->ar_register_enable) {
            sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_NOT_ALLOWED), 0));
            return;
        }

        log_debug(ZONE, "user remove requested");

        /* make sure we can delete them */
        if(c2s->ar->delete_user == NULL) {
            sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_NOT_ALLOWED), 0));
            return;
        }

        /* otherwise, delete them */
        if((c2s->ar->delete_user)(c2s->ar, sess->resources->jid->node, sess->host->realm) != 0) {
            log_debug(ZONE, "user delete failed");
            sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_INTERNAL_SERVER_ERROR), 0));
            return;
        }

        log_write(c2s->log, LOG_NOTICE, "[%d] deleted user: user=%s; realm=%s", sess->s->tag, sess->resources->jid->node, sess->host->realm);

        log_write(c2s->log, LOG_NOTICE, "[%d] registration remove succeeded, requesting user deletion: jid=%s", sess->s->tag, jid_user(sess->resources->jid));

        /* make a result nad */
        sess->result = nad_new();

        ns = nad_add_namespace(sess->result, uri_CLIENT, NULL);

        nad_append_elem(sess->result, ns, "iq", 0);
        nad_set_attr(sess->result, 0, -1, "type", "result", 6);

        /* extract the id */
        attr = nad_find_attr(nad, 0, -1, "id", NULL);
        if(attr >= 0)
            nad_set_attr(sess->result, 0, -1, "id", NAD_AVAL(nad, attr), NAD_AVAL_L(nad, attr));

        nad_free(nad);

        sx_nad_write(sess->s, sess->result);
        sess->result = NULL;

        /* get the sm to delete them (it will force their sessions to end) */
        sm_delete(sess, sess->resources);

        return;
    }

    /* username is required */
    elem = nad_find_elem(nad, 1, ns, "username", 1);
    if(elem < 0)
    {
        log_debug(ZONE, "register set with no username, bouncing it");
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_BAD_REQUEST), 0));
        return;
    }

    snprintf(username, 1024, "%.*s", NAD_CDATA_L(nad, elem), NAD_CDATA(nad, elem));
    if(stringprep_xmpp_nodeprep(username, 1024) != 0) {
        log_debug(ZONE, "register set username failed nodeprep, bouncing it");
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_JID_MALFORMED), 0));
        return;
    }

    elem = nad_find_elem(nad, 1, ns, "password", 1);
    if(elem < 0)
    {
        log_debug(ZONE, "register set with no password, bouncing it");
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_BAD_REQUEST), 0));
        return;
    }

    /* if they're already auth'd, its a password change */
    if(sess->active)
    {
        /* confirm that the username matches their auth id */
        if(strcmp(username, sess->resources->jid->node) != 0)
        {
            log_debug(ZONE, "%s is trying to change password for %s, bouncing it", jid_full(sess->resources->jid), username);
            sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_OLD_UNAUTH), 0));
            return;
        }
    }

    /* can't go on if we're not doing full reg */
    else if(!sess->host->ar_register_enable) {
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_NOT_ALLOWED), 0));
        return;
    }

    /* if they exist, bounce */
    else if((c2s->ar->user_exists)(c2s->ar, username, sess->host->realm))
    {
        log_debug(ZONE, "attempt to register %s, but they already exist", username);
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_CONFLICT), 0));
        return;
    }

    /* make sure we can create them */
    else if(c2s->ar->create_user == NULL)
    {
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_NOT_ALLOWED), 0));
        return;
    }

    /* otherwise, create them */
    else if((c2s->ar->create_user)(c2s->ar, username, sess->host->realm) != 0)
    {
        log_debug(ZONE, "user create failed");
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_INTERNAL_SERVER_ERROR), 0));
        return;
    }

    else
        log_write(c2s->log, LOG_NOTICE, "[%d] created user: user=%s; realm=%s", sess->s->tag, username, sess->host->realm);

    /* extract the password */
    snprintf(password, 257, "%.*s", NAD_CDATA_L(nad, elem), NAD_CDATA(nad, elem));

    /* change it */
    if((c2s->ar->set_password)(c2s->ar, username, sess->host->realm, password) != 0)
    {
        log_debug(ZONE, "password store failed");
        sx_nad_write(sess->s, stanza_tofrom(stanza_error(nad, 0, stanza_err_INTERNAL_SERVER_ERROR), 0));
        return;
    }

    log_debug(ZONE, "updated auth creds for %s", username);

    /* make a result nad */
    sess->result = nad_new();

    ns = nad_add_namespace(sess->result, uri_CLIENT, NULL);

    nad_append_elem(sess->result, ns, "iq", 0);
    nad_set_attr(sess->result, 0, -1, "type", "result", 6);

    /* extract the id */
    attr = nad_find_attr(nad, 0, -1, "id", NULL);
    if(attr >= 0)
        nad_set_attr(sess->result, 0, -1, "id", NAD_AVAL(nad, attr), NAD_AVAL_L(nad, attr));

    /* if they're active, then this was just a password change, and we're done */
    if(sess->active) {
        log_write(c2s->log, LOG_NOTICE, "[%d] password changed: jid=%s", sess->s->tag, jid_user(sess->resources->jid));
        sx_nad_write(sess->s, sess->result);
        sess->result = NULL;
        return;
    }

    /* create new bound jid holder */
    if(sess->resources == NULL) {
        sess->resources = (bres_t) calloc(1, sizeof(struct bres_st));
    }

    /* our local id */
    sprintf(sess->resources->c2s_id, "%d", sess->s->tag);

    /* the user jid for this transaction */
    sess->resources->jid = jid_new(sess->s->req_to, -1);
    jid_reset_components(sess->resources->jid, username, sess->resources->jid->domain, sess->resources->jid->resource);

    log_write(c2s->log, LOG_NOTICE, "[%d] registration succeeded, requesting user creation: jid=%s", sess->s->tag, jid_user(sess->resources->jid));

    /* get the sm to create them */
    sm_create(sess, sess->resources);

    nad_free(nad);

    return;
}