Exemplo n.º 1
0
static void overlay_same(abts_case *tc, void *data)
{
    apr_hash_t *base = NULL;
    apr_hash_t *result = NULL;
    int count;
    char str[8196];

    base = apr_hash_make(p);
    ABTS_PTR_NOTNULL(tc, base);

    apr_hash_set(base, "base1", APR_HASH_KEY_STRING, "value1");
    apr_hash_set(base, "base2", APR_HASH_KEY_STRING, "value2");
    apr_hash_set(base, "base3", APR_HASH_KEY_STRING, "value3");
    apr_hash_set(base, "base4", APR_HASH_KEY_STRING, "value4");
    apr_hash_set(base, "base5", APR_HASH_KEY_STRING, "value5");

    result = apr_hash_overlay(p, base, base);

    count = apr_hash_count(result);
    ABTS_INT_EQUAL(tc, 5, count);

    dump_hash(p, result, str);
    /* I don't know why these are out of order, but they are.  I would probably
     * consider this a bug, but others should comment.
     */
    ABTS_STR_EQUAL(tc, "Key base5 (5) Value value5\n"
                          "Key base1 (5) Value value1\n"
                          "Key base2 (5) Value value2\n"
                          "Key base3 (5) Value value3\n"
                          "Key base4 (5) Value value4\n"
                          "#entries 5\n", str);
}
Exemplo n.º 2
0
unsigned int kahanaStockNumberOfItems( kStock_t *s, const char *key )
{
	unsigned int nitem = 0;
	
	if( s )
	{
		if( key && key[0] != '\0' )
		{
			apr_pool_t *p = NULL;
			apr_status_t rc = apr_pool_create( &p, NULL );
			
			if( rc == APR_SUCCESS )
			{
				apr_hash_index_t *idx = NULL;
				const char *ikey;
				
				for( idx = apr_hash_first( p, s->items ); idx; idx = apr_hash_next( idx ) )
				{
					apr_hash_this( idx, (const void**)&ikey, NULL, NULL );
					if( kahanaStrCmpHead( ikey, key ) ){
						nitem++;
					}
				}
				apr_pool_destroy( p );
			}
		}
		else {
			nitem = apr_hash_count( s->items );
		}
	}
	
	return nitem;
}
Exemplo n.º 3
0
static apr_status_t
lcn_multi_reader_document( lcn_index_reader_t *index_reader,
                           lcn_document_t **document,
                           unsigned int n,
                           apr_pool_t *pool )
{
    apr_status_t s;

    do
    {
        lcn_document_t *doc;
        unsigned int i = lcn_multi_reader_index( index_reader, n );
        lcn_multi_reader_t *multi_reader = (lcn_multi_reader_t*) index_reader;

        LCNCE( lcn_index_reader_document( multi_reader->sub_readers[i],
                                          &doc,
                                          n - multi_reader->starts[i],
                                          pool ) );

        if ( index_reader->fs_fields && (0 != apr_hash_count( index_reader->fs_fields )))
        {
            LCNCE( lcn_index_reader_add_fs_fields( index_reader, doc, n, pool ));
        }

        doc->index_pos = n;
        *document = doc;
    }
    while(0);

    return s;
}
Exemplo n.º 4
0
/* Finally terminate RTSP session */
static apt_bool_t rtsp_server_session_do_terminate(rtsp_server_t *server, rtsp_server_session_t *session)
{		
	rtsp_server_connection_t *rtsp_connection = session->connection;

	if(session->active_request) {
		rtsp_message_t *response = rtsp_response_create(session->active_request,
			RTSP_STATUS_CODE_OK,RTSP_REASON_PHRASE_OK,session->active_request->pool);
		if(response) {
			if(session->id.buf) {
				response->header.session_id = session->id;
				rtsp_header_property_add(&response->header,RTSP_HEADER_FIELD_SESSION_ID,response->pool);
			}

			if(rtsp_connection) {
				rtsp_server_message_send(server,rtsp_connection,response);
			}
		}
	}

	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Remove RTSP Session "APT_SID_FMT,session->id.buf);
	apr_hash_set(rtsp_connection->session_table,session->id.buf,session->id.length,NULL);
	rtsp_server_session_destroy(session);

	if(rtsp_connection && !rtsp_connection->it) {
		if(apr_hash_count(rtsp_connection->session_table) == 0) {
			rtsp_server_connection_destroy(rtsp_connection);
		}
	}
	return TRUE;
}
Exemplo n.º 5
0
static apt_bool_t mrcp_client_message_handler(mrcp_connection_t *connection, mrcp_message_t *message, apt_message_status_e status)
{
	if(status == APT_MESSAGE_STATUS_COMPLETE) {
		/* message is completely parsed */
		mrcp_control_channel_t *channel;
		apt_str_t identifier;
		apt_id_resource_generate(&message->channel_id.session_id,&message->channel_id.resource_name,'@',&identifier,message->pool);
		channel = mrcp_connection_channel_find(connection,&identifier);
		if(channel) {
			mrcp_connection_agent_t *agent = connection->agent;
			if(message->start_line.message_type == MRCP_MESSAGE_TYPE_RESPONSE) {
				if(!channel->active_request || 
					channel->active_request->start_line.request_id != message->start_line.request_id) {
					apt_obj_log(APT_LOG_MARK,APT_PRIO_WARNING,channel->log_obj,"Unexpected MRCP Response " APT_SIDRES_FMT" [%d]",
						MRCP_MESSAGE_SIDRES(message),
						message->start_line.request_id);
					return FALSE;
				}
				if(channel->request_timer) {
					apt_timer_kill(channel->request_timer);
				}
				channel->active_request = NULL;
			}

			mrcp_connection_message_receive(agent->vtable,channel,message);
		}
		else {
			apt_log(APT_LOG_MARK,APT_PRIO_WARNING,"Failed to Find Channel " APT_SIDRES_FMT" in Connection %s [%d]",
				MRCP_MESSAGE_SIDRES(message),
				connection->id,
				apr_hash_count(connection->channel_table));
		}
	}
	return TRUE;
}
Exemplo n.º 6
0
git_wc_status2_t * GitStatus::GetNextFileStatus(CTGitPath& /*retPath*/)
{
	static git_wc_status2 st;

	st.text_status = git_wc_status_none;

	/*if (m_fileCache.m_pFileIter)
	{
		switch(m_fileCache.m_pFileIter->nStatus)
		{
		case WGFS_Normal: st.text_status = git_wc_status_normal; break;
		case WGFS_Modified: st.text_status = git_wc_status_modified; break;
		case WGFS_Deleted: st.text_status = git_wc_status_deleted; break;
		}

		m_fileCache.m_pFileIter = m_fileCache.m_pFileIter->pNext;
	}*/

	return &st;

#if 0
	const sort_item*			item;

	if ((m_statushashindex+1) >= apr_hash_count(m_statushash))
		return NULL;
	m_statushashindex++;

	item = &APR_ARRAY_IDX (m_statusarray, m_statushashindex, const sort_item);
	retPath.SetFromGit((const char*)item->key);
	return (git_wc_status2_t *) item->value;
#endif
	return 0;
}
static apt_bool_t mrcp_server_agent_channel_remove(mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel)
{
	mrcp_connection_t *connection = channel->connection;
	mrcp_connection_channel_remove(connection,channel);
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Remove Control Channel <%s> [%d]",
			channel->identifier.buf,
			apr_hash_count(connection->channel_table));
	if(!connection->access_count) {
		if(connection == agent->null_connection) {
			if(apt_list_is_empty(agent->connection_list) == TRUE) {
				apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Destroy Pending Connection");
				mrcp_connection_destroy(agent->null_connection);
				agent->null_connection = NULL;
				agent->connection_list = NULL;
			}
		}
		else if(!connection->sock) {
			mrcp_connection_remove(agent,connection);
			/* set connection to be destroyed on channel destroy */
			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Mark Connection for Late Destroy");
			channel->connection = connection;
			channel->removed = TRUE;
		}
	}
	/* send response */
	return mrcp_control_channel_remove_respond(agent->vtable,channel,TRUE);
}
static apt_bool_t mrcp_server_agent_channel_add(mrcp_connection_agent_t *agent, mrcp_control_channel_t *channel, mrcp_control_descriptor_t *offer)
{
	mrcp_control_descriptor_t *answer = mrcp_control_answer_create(offer,channel->pool);
	apt_id_resource_generate(&offer->session_id,&offer->resource_name,'@',&channel->identifier,channel->pool);
	if(offer->port) {
		answer->port = agent->sockaddr->port;
	}
	if(offer->connection_type == MRCP_CONNECTION_TYPE_EXISTING) {
		if(agent->force_new_connection == TRUE) {
			/* force client to establish new connection */
			answer->connection_type = MRCP_CONNECTION_TYPE_NEW;
		}
		else {
			mrcp_connection_t *connection = NULL;
			/* try to find any existing connection */
			connection = mrcp_connection_find(agent,&offer->ip);
			if(!connection) {
				/* no existing conection found, force the new one */
				answer->connection_type = MRCP_CONNECTION_TYPE_NEW;
			}
		}
	}

	if(!agent->null_connection) {
		apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Create Pending Connection");
		agent->null_connection = mrcp_connection_create();
		agent->connection_list = apt_list_create(agent->null_connection->pool);
	}
	mrcp_connection_channel_add(agent->null_connection,channel);	
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Add Control Channel <%s> to Pending Connection [%d]",
			channel->identifier.buf,
			apr_hash_count(agent->null_connection->channel_table));
	/* send response */
	return mrcp_control_channel_add_respond(agent->vtable,channel,answer,TRUE);
}
Exemplo n.º 9
0
static void overlay_empty(abts_case *tc, void *data)
{
    apr_hash_t *base = NULL;
    apr_hash_t *overlay = NULL;
    apr_hash_t *result = NULL;
    int count;
    char str[8196];

    base = apr_hash_make(p);
    overlay = apr_hash_make(p);
    ABTS_PTR_NOTNULL(tc, base);
    ABTS_PTR_NOTNULL(tc, overlay);

    apr_hash_set(base, "key1", APR_HASH_KEY_STRING, "value1");
    apr_hash_set(base, "key2", APR_HASH_KEY_STRING, "value2");
    apr_hash_set(base, "key3", APR_HASH_KEY_STRING, "value3");
    apr_hash_set(base, "key4", APR_HASH_KEY_STRING, "value4");
    apr_hash_set(base, "key5", APR_HASH_KEY_STRING, "value5");

    result = apr_hash_overlay(p, overlay, base);

    count = apr_hash_count(result);
    ABTS_INT_EQUAL(tc, 5, count);

    dump_hash(p, result, str);
    ABTS_STR_EQUAL(tc, "Key key1 (4) Value value1\n"
                          "Key key2 (4) Value value2\n"
                          "Key key3 (4) Value value3\n"
                          "Key key4 (4) Value value4\n"
                          "Key key5 (4) Value value5\n"
                          "#entries 5\n", str);
}
Exemplo n.º 10
0
/** Return TRUE to proceed with the next message in the stream (if any) */
static apt_bool_t rtsp_client_message_handler(rtsp_client_connection_t *rtsp_connection, rtsp_message_t *message, apt_message_status_e status)
{
	if(status != APT_MESSAGE_STATUS_COMPLETE) {
		/* message is not completely parsed, nothing to do */
		return TRUE;
	}
	/* process parsed message */
	if(message->start_line.message_type == RTSP_MESSAGE_TYPE_RESPONSE) {
		rtsp_message_t *request;
		rtsp_client_session_t *session;
		/* at first, pop in-progress request/session */
		if(rtsp_client_request_pop(rtsp_connection,message,&request,&session) == FALSE) {
			apt_log(RTSP_LOG_MARK,APT_PRIO_WARNING,"Unexpected RTSP Response Received CSeq:%"APR_SIZE_T_FMT,
				message->header.cseq);
			return TRUE;
		}

		/* next, process session response */
		rtsp_client_session_response_process(rtsp_connection->client,session,request,message);

		/* process session pending requests */
		if(rtsp_client_session_pending_requests_process(rtsp_connection->client,session) == FALSE) {
			/* no in-progress request, check the termination state now */
			if(session->term_state != TERMINATION_STATE_NONE) {
				if(session->term_state == TERMINATION_STATE_REQUESTED) {
					rtsp_client_session_resources_teardown(rtsp_connection->client,session);
				}
				
				/* respond if no resources left */
				if(apr_hash_count(session->resource_table) == 0) {
					rtsp_client_session_terminate_respond(rtsp_connection->client,session);

					if(apr_hash_count(rtsp_connection->handle_table) == 0) {
						rtsp_client_connection_destroy(rtsp_connection);
						/* return FALSE to indicate connection has been destroyed */
						return FALSE;
					}
				}
			}
		}
	}
	else if(message->start_line.message_type == RTSP_MESSAGE_TYPE_REQUEST) {
		rtsp_client_session_event_process(rtsp_connection->client,rtsp_connection,message);
	}
	return TRUE;
}
Exemplo n.º 11
0
svn_error_t *
svn_wc__expand_keywords(apr_hash_t **keywords,
                        svn_wc__db_t *db,
                        const char *local_abspath,
                        const char *wri_abspath,
                        const char *keyword_list,
                        svn_boolean_t for_normalization,
                        apr_pool_t *result_pool,
                        apr_pool_t *scratch_pool)
{
  svn_revnum_t changed_rev;
  apr_time_t changed_date;
  const char *changed_author;
  const char *url;
  const char *repos_root_url;

  if (! for_normalization)
    {
      const char *repos_relpath;

      SVN_ERR(svn_wc__db_read_info(NULL, NULL, NULL, &repos_relpath,
                                   &repos_root_url, NULL, &changed_rev,
                                   &changed_date, &changed_author, NULL,
                                   NULL, NULL, NULL, NULL, NULL, NULL,
                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                                   NULL, NULL, NULL, NULL,
                                   db, local_abspath,
                                   scratch_pool, scratch_pool));

      if (repos_relpath)
        url = svn_path_url_add_component2(repos_root_url, repos_relpath,
                                          scratch_pool);
      else
         SVN_ERR(svn_wc__db_read_url(&url, db, local_abspath, scratch_pool,
                                     scratch_pool));
    }
  else
    {
      url = "";
      changed_rev = SVN_INVALID_REVNUM;
      changed_date = 0;
      changed_author = "";
      repos_root_url = "";
    }

  SVN_ERR(svn_subst_build_keywords3(keywords, keyword_list,
                                    apr_psprintf(scratch_pool, "%ld",
                                                 changed_rev),
                                    url, repos_root_url,
                                    changed_date, changed_author,
                                    result_pool));

  if (apr_hash_count(*keywords) == 0)
    *keywords = NULL;

  return SVN_NO_ERROR;
}
Exemplo n.º 12
0
static void hash_count_0(abts_case *tc, void *data)
{
    apr_hash_t *h = NULL;
    int count;

    h = apr_hash_make(p);
    ABTS_PTR_NOTNULL(tc, h);

    count = apr_hash_count(h);
    ABTS_INT_EQUAL(tc, 0, count);
}
Exemplo n.º 13
0
/* Process incoming RTSP response */
static apt_bool_t rtsp_client_session_response_process(rtsp_client_t *client, rtsp_client_session_t *session, rtsp_message_t *request, rtsp_message_t *response)
{
	const char *resource_name;
	if(request->start_line.common.request_line.method_id == RTSP_METHOD_SETUP &&
		response->start_line.common.status_line.status_code == RTSP_STATUS_CODE_OK) {

		if(apr_hash_count(session->resource_table) == 0) {
			if(rtsp_header_property_check(&response->header,RTSP_HEADER_FIELD_SESSION_ID) == TRUE) {
				session->id = response->header.session_id;
				apt_log(RTSP_LOG_MARK,APT_PRIO_INFO,"Add RTSP Session " APT_PTRSID_FMT,
					session,
					session->id.buf);
				apr_hash_set(session->connection->session_table,session->id.buf,session->id.length,session);
			}
		}

		/* add resource */
		resource_name = request->start_line.common.request_line.resource_name;
		apr_hash_set(session->resource_table,resource_name,APR_HASH_KEY_STRING,request);
	}
	else if(request->start_line.common.request_line.method_id == RTSP_METHOD_TEARDOWN) {
		/* remove resource */
		resource_name = request->start_line.common.request_line.resource_name;
		apr_hash_set(session->resource_table,resource_name,APR_HASH_KEY_STRING,NULL);

		if(apr_hash_count(session->resource_table) == 0) {
			if(session->connection) {
				apt_log(RTSP_LOG_MARK,APT_PRIO_INFO,"Remove RTSP Session " APT_PTRSID_FMT,
					session,
					session->id.buf);
				apr_hash_set(session->connection->session_table,session->id.buf,session->id.length,NULL);
			}
		}
	}

	if(session->term_state != TERMINATION_STATE_INPROGRESS) {
		client->vtable->on_session_response(client,session,request,response);
	}

	return TRUE;
}
Exemplo n.º 14
0
/*
 * verify the signature on a JWT
 */
apr_byte_t apr_jws_verify(apr_pool_t *pool, apr_jwt_t *jwt, apr_hash_t *keys,
                          apr_jwt_error_t *err) {
    apr_byte_t rc = FALSE;

    apr_jwk_t *jwk = NULL;
    apr_hash_index_t *hi;

    if (jwt->header.kid != NULL) {

        jwk = apr_hash_get(keys, jwt->header.kid,
                           APR_HASH_KEY_STRING);
        if (jwk != NULL) {
            rc = apr_jws_verify_with_jwk(pool, jwt, jwk, err);
        } else {
            apr_jwt_error(err, "could not find key with kid: %s",
                          jwt->header.kid);
            rc = FALSE;
        }

    } else {

        for (hi = apr_hash_first(pool, keys); hi; hi = apr_hash_next(hi)) {
            apr_hash_this(hi, NULL, NULL, (void **) &jwk);
            rc = apr_jws_verify_with_jwk(pool, jwt, jwk, err);
            if (rc == TRUE)
                break;
        }

        if (rc == FALSE)
            apr_jwt_error(err,
                          "could not verify signature against any of the (%d) provided keys%s",
                          apr_hash_count(keys),
                          apr_hash_count(keys) > 0 ?
                          "" :
                          apr_psprintf(pool,
                                       "; you have probably provided no or incorrect keys/key-types for algorithm: %s",
                                       jwt->header.alg));
    }

    return rc;
}
Exemplo n.º 15
0
/* Call RECEIVER for the given PATH and PROP_HASH.
 *
 * If PROP_HASH is null or has zero count, do nothing.
 */
static svn_error_t*
call_receiver(const char *path,
              apr_hash_t *prop_hash,
              svn_proplist_receiver_t receiver,
              void *receiver_baton,
              apr_pool_t *pool)
{
  if (prop_hash && apr_hash_count(prop_hash))
    SVN_ERR(receiver(receiver_baton, path, prop_hash, pool));

  return SVN_NO_ERROR;
}
Exemplo n.º 16
0
static svn_error_t *
test_parse_property_and_text_diff(apr_pool_t *pool)
{
  svn_patch_file_t *patch_file;
  svn_patch_t *patch;
  svn_prop_patch_t *prop_patch;
  svn_diff_hunk_t *hunk;
  apr_array_header_t *hunks;

  SVN_ERR(create_patch_file(&patch_file, property_and_text_unidiff, pool));

  SVN_ERR(svn_diff_parse_next_patch(&patch, patch_file,
                                    FALSE, /* reverse */
                                    FALSE, /* ignore_whitespace */
                                    pool, pool));
  SVN_TEST_ASSERT(patch);
  SVN_TEST_STRING_ASSERT(patch->old_filename, "iota");
  SVN_TEST_STRING_ASSERT(patch->new_filename, "iota");
  SVN_TEST_ASSERT(patch->hunks->nelts == 1);
  SVN_TEST_ASSERT(apr_hash_count(patch->prop_patches) == 1);

  /* Check contents of text hunk */
  hunk = APR_ARRAY_IDX(patch->hunks, 0, svn_diff_hunk_t *);

  SVN_ERR(check_content(hunk, TRUE,
                        "This is the file 'iota'." NL,
                        pool));

  SVN_ERR(check_content(hunk, FALSE,
                        "This is the file 'iota'." NL
                        "some more bytes to 'iota'" NL,
                        pool));

  /* Check the added property */
  prop_patch = apr_hash_get(patch->prop_patches, "prop_add",
                            APR_HASH_KEY_STRING);
  SVN_TEST_ASSERT(prop_patch->operation == svn_diff_op_added);

  hunks = prop_patch->hunks;
  SVN_TEST_ASSERT(hunks->nelts == 1);
  hunk = APR_ARRAY_IDX(hunks, 0 , svn_diff_hunk_t *);

  SVN_ERR(check_content(hunk, TRUE,
                        "",
                        pool));

  SVN_ERR(check_content(hunk, FALSE,
                        "value" NL,
                        pool));

  SVN_ERR(svn_diff_close_patch_file(patch_file, pool));
  return SVN_NO_ERROR;
}
Exemplo n.º 17
0
static void hash_count_1(abts_case *tc, void *data)
{
    apr_hash_t *h = NULL;
    int count;

    h = apr_hash_make(p);
    ABTS_PTR_NOTNULL(tc, h);

    apr_hash_set(h, "key", APR_HASH_KEY_STRING, "value");

    count = apr_hash_count(h);
    ABTS_INT_EQUAL(tc, 1, count);
}
Exemplo n.º 18
0
/* Respond to session termination request */
static apt_bool_t rtsp_client_session_terminate_respond(rtsp_client_t *client, rtsp_client_session_t *session)
{
	rtsp_client_connection_t *rtsp_connection = session->connection;
	apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Remove RTSP Handle "APT_PTR_FMT,session);
	apr_hash_set(rtsp_connection->handle_table,session,sizeof(session),NULL);

	session->term_state = TERMINATION_STATE_NONE;
	client->vtable->on_session_terminate_response(client,session);
	
	if(apr_hash_count(rtsp_connection->handle_table) == 0) {
		rtsp_client_connection_destroy(client,rtsp_connection);
	}
	return TRUE;
}
Exemplo n.º 19
0
static mrcp_control_channel_t* mrcp_connection_channel_associate(mrcp_connection_agent_t *agent, mrcp_connection_t *connection, const mrcp_message_t *message)
{
	apt_str_t identifier;
	mrcp_control_channel_t *channel;
	if(!connection || !message) {
		return NULL;
	}
	apt_id_resource_generate(&message->channel_id.session_id,&message->channel_id.resource_name,'@',&identifier,connection->pool);
	channel = mrcp_connection_channel_find(connection,&identifier);
	if(!channel) {
		channel = apr_hash_get(agent->pending_channel_table,identifier.buf,identifier.length);
		if(channel) {
			apr_hash_set(agent->pending_channel_table,identifier.buf,identifier.length,NULL);
			mrcp_connection_channel_add(connection,channel);
			apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Assign Control Channel <%s> to Connection %s [%d] -> [%d]",
				channel->identifier.buf,
				connection->id,
				apr_hash_count(agent->pending_channel_table),
				apr_hash_count(connection->channel_table));
		}
	}
	return channel;
}
Exemplo n.º 20
0
svn_boolean_t
svn_fs__prop_lists_equal(apr_hash_t *a,
                         apr_hash_t *b,
                         apr_pool_t *pool)
{
  apr_hash_index_t *hi;

  /* Quick checks and special cases. */
  if (a == b)
    return TRUE;

  if (a == NULL)
    return apr_hash_count(b) == 0;
  if (b == NULL)
    return apr_hash_count(a) == 0;

  if (apr_hash_count(a) != apr_hash_count(b))
    return FALSE;

  /* Compare prop by prop. */
  for (hi = apr_hash_first(pool, a); hi; hi = apr_hash_next(hi))
    {
      const char *key;
      apr_ssize_t klen;
      svn_string_t *val_a, *val_b;

      apr_hash_this(hi, (const void **)&key, &klen, (void **)&val_a);
      val_b = apr_hash_get(b, key, klen);

      if (!val_b || !svn_string_compare(val_a, val_b))
        return FALSE;
    }

  /* No difference found. */
  return TRUE;
}
Exemplo n.º 21
0
/*
 * decrypt a JWT and return the plaintext
 */
static uint8_t *oidc_jwe_decrypt_impl(apr_pool_t *pool, cjose_jwe_t *jwe,
		apr_hash_t *keys, size_t *content_len, oidc_jose_error_t *err) {

	uint8_t *decrypted = NULL;
	oidc_jwk_t *jwk = NULL;
	apr_hash_index_t *hi;

	cjose_err cjose_err;
	cjose_header_t *hdr = cjose_jwe_get_protected(jwe);
	const char *kid = cjose_header_get(hdr, CJOSE_HDR_KID, &cjose_err);
	const char *alg = cjose_header_get(hdr, CJOSE_HDR_ALG, &cjose_err);

	if (kid != NULL) {

		jwk = apr_hash_get(keys, kid, APR_HASH_KEY_STRING);
		if (jwk != NULL) {
			decrypted = cjose_jwe_decrypt(jwe, jwk->cjose_jwk, content_len,
					&cjose_err);
			if (decrypted == NULL)
				oidc_jose_error(err,
						"encrypted JWT could not be decrypted with kid %s: %s",
						kid, oidc_cjose_e2s(pool, cjose_err));
		} else {
			oidc_jose_error(err, "could not find key with kid: %s", kid);
		}

	} else {

		for (hi = apr_hash_first(pool, keys); hi; hi = apr_hash_next(hi)) {
			apr_hash_this(hi, NULL, NULL, (void **) &jwk);

			if (jwk->kty == oidc_alg2kty(alg)) {
				decrypted = cjose_jwe_decrypt(jwe, jwk->cjose_jwk, content_len,
						&cjose_err);
				if (decrypted != NULL)
					break;
			}
		}

		if (decrypted == NULL)
			oidc_jose_error(err,
					"encrypted JWT could not be decrypted with any of the %d keys: error for last tried key is: %s",
					apr_hash_count(keys), oidc_cjose_e2s(pool, cjose_err));

	}

	return decrypted;
}
Exemplo n.º 22
0
static apt_bool_t mrcp_connection_remove(mrcp_connection_agent_t *agent, mrcp_connection_t *connection)
{
	if(connection->it) {
		apt_list_elem_remove(agent->connection_list,connection->it);
		connection->it = NULL;
	}
	if(agent->null_connection) {
		if(apt_list_is_empty(agent->connection_list) == TRUE && apr_hash_count(agent->null_connection->channel_table) == 0) {
			apt_log(APT_LOG_MARK,APT_PRIO_DEBUG,"Destroy Pending Connection");
			mrcp_connection_destroy(agent->null_connection);
			agent->null_connection = NULL;
			agent->connection_list = NULL;
		}
	}
	return TRUE;
}
Exemplo n.º 23
0
svn_error_t *
svn_hash_keys(apr_array_header_t **array,
              apr_hash_t *hash,
              apr_pool_t *pool)
{
  apr_hash_index_t *hi;

  *array = apr_array_make(pool, apr_hash_count(hash), sizeof(const char *));

  for (hi = apr_hash_first(pool, hash); hi; hi = apr_hash_next(hi))
    {
      APR_ARRAY_PUSH(*array, const char *) = svn__apr_hash_index_key(hi);
    }

  return SVN_NO_ERROR;
}
Exemplo n.º 24
0
void
auth_vas_cache_set_max_size(auth_vas_cache *cache, unsigned int new_size) {
    unsigned int num_items;

    if (new_size < 1) /* Some dolt will try it */
	new_size = 1;

    num_items = apr_hash_count(cache->table);

    while (num_items > new_size) {
	auth_vas_cache_remove_items_from(cache, cache->oldest);
	--num_items;
    }

    cache->max_size = new_size;
}
Exemplo n.º 25
0
void UmcFramework::ProcessShowSessions()
{
	UmcSession* pSession;
	void* pVal;
	printf("%d Session(s)\n", apr_hash_count(m_pSessionTable));
	apr_hash_index_t* it = apr_hash_first(m_pPool,m_pSessionTable);
	for(; it; it = apr_hash_next(it)) 
	{
		apr_hash_this(it,NULL,NULL,&pVal);
		pSession = (UmcSession*) pVal;
		if(pSession)
		{
			printf("[%s] - %s\n", pSession->GetId(), pSession->GetScenario()->GetName());
		}
	}
}
Exemplo n.º 26
0
void UmcFramework::ProcessShowScenarios()
{
	UmcScenario* pScenario;
	void* pVal;
	printf("%d Scenario(s)\n", apr_hash_count(m_pScenarioTable));
	apr_hash_index_t* it = apr_hash_first(m_pPool,m_pScenarioTable);
	for(; it; it = apr_hash_next(it))
	{
		apr_hash_this(it,NULL,NULL,&pVal);
		pScenario = (UmcScenario*) pVal;
		if(pScenario)
		{
			printf("[%s]\n", pScenario->GetName());
		}
	}
}
Exemplo n.º 27
0
void
svn_ra_serf__merge_lock_token_list(apr_hash_t *lock_tokens,
                                   const char *parent,
                                   serf_bucket_t *body,
                                   serf_bucket_alloc_t *alloc,
                                   apr_pool_t *pool)
{
  apr_hash_index_t *hi;

  if (!lock_tokens || apr_hash_count(lock_tokens) == 0)
    return;

  svn_ra_serf__add_open_tag_buckets(body, alloc,
                                    "S:lock-token-list",
                                    "xmlns:S", SVN_XML_NAMESPACE,
                                    SVN_VA_NULL);

  for (hi = apr_hash_first(pool, lock_tokens);
       hi;
       hi = apr_hash_next(hi))
    {
      const void *key;
      apr_ssize_t klen;
      void *val;
      svn_string_t path;

      apr_hash_this(hi, &key, &klen, &val);

      path.data = key;
      path.len = klen;

      if (parent && !svn_relpath_skip_ancestor(parent, key))
        continue;

      svn_ra_serf__add_open_tag_buckets(body, alloc, "S:lock", SVN_VA_NULL);

      svn_ra_serf__add_open_tag_buckets(body, alloc, "lock-path", SVN_VA_NULL);
      svn_ra_serf__add_cdata_len_buckets(body, alloc, path.data, path.len);
      svn_ra_serf__add_close_tag_buckets(body, alloc, "lock-path");

      svn_ra_serf__add_tag_buckets(body, "lock-token", val, alloc);

      svn_ra_serf__add_close_tag_buckets(body, alloc, "S:lock");
    }

  svn_ra_serf__add_close_tag_buckets(body, alloc, "S:lock-token-list");
}
Exemplo n.º 28
0
static void hash_count_5(abts_case *tc, void *data)
{
    apr_hash_t *h = NULL;
    int count;

    h = apr_hash_make(p);
    ABTS_PTR_NOTNULL(tc, h);

    apr_hash_set(h, "key1", APR_HASH_KEY_STRING, "value1");
    apr_hash_set(h, "key2", APR_HASH_KEY_STRING, "value2");
    apr_hash_set(h, "key3", APR_HASH_KEY_STRING, "value3");
    apr_hash_set(h, "key4", APR_HASH_KEY_STRING, "value4");
    apr_hash_set(h, "key5", APR_HASH_KEY_STRING, "value5");

    count = apr_hash_count(h);
    ABTS_INT_EQUAL(tc, 5, count);
}
Exemplo n.º 29
0
static dav_error *dav_acl_patch_validate(const dav_resource * resource,
                                         const apr_xml_elem * elem,
                                         int operation,
                                         void **context,
                                         int *defer_to_dead)
{
    apr_pool_t *pool = resource->pool;
    dav_repos_resource *db_r = resource->info->db_r;
    dav_repos_db *db = resource->info->db;
    request_rec *rec = resource->info->rec;
    dav_elem_private *priv = elem->priv;
    dav_error *err = NULL;

    TRACE();

    if (priv->propid == DAV_PROPID_group_member_set) {
	*defer_to_dead = 0;
        if (db_r->resourcetype!=dav_repos_GROUP || operation!=DAV_PROP_OP_SET)
            return dav_new_error(pool, HTTP_FORBIDDEN, 0,
                                 "Not a set operation on a group");
            
        apr_xml_elem *href_elem = dav_find_child(elem, "href");
        apr_hash_t *new_members = apr_hash_make(pool);
        apr_array_header_t *to_remove = NULL;

        while (href_elem && !err) {
            const char *prin_uri = dav_xml_get_cdata(href_elem, pool, 1);
            const char *prin_name = get_name_from_principal_URL(rec, prin_uri);
            if (prin_name == NULL)
                err = dav_new_error
                  (pool, HTTP_CONFLICT, 0, "Not a DAV:principal-URL");
            else
                apr_hash_set(new_members, prin_name, APR_HASH_KEY_STRING, "");
            href_elem = href_elem->next;
        }
        if (err) return err;
        if (apr_hash_count(new_members))
            err = dbms_calculate_group_changes(db, db_r, new_members,&to_remove);
        else
            err = dbms_get_group_members(db, db_r, &to_remove);
        if (err) return err;
        apr_hash_set(new_members, "-to-remove-", APR_HASH_KEY_STRING, to_remove);
        *context = new_members;
    }
    return err;
}
Exemplo n.º 30
0
static void hash_clear(abts_case *tc, void *data)
{
    apr_hash_t *h;
    int i, *e;

    h = apr_hash_make(p);
    ABTS_PTR_NOTNULL(tc, h);

    for (i = 1; i <= 10; i++) {
        e = apr_palloc(p, sizeof(int));
        *e = i;
        apr_hash_set(h, e, sizeof(*e), e);
    }
    apr_hash_clear(h);
    i = apr_hash_count(h);
    ABTS_INT_EQUAL(tc, 0, i);
}