示例#1
0
文件: var.c 项目: Joywar/openldap
/*
 * Sets/inserts a var
 */
struct rewrite_var *
rewrite_var_set_f(
		Avlnode **tree,
		const char *name,
		const char *value,
		int flags
)
{
	struct rewrite_var *var;

	assert( tree != NULL );
	assert( name != NULL );
	assert( value != NULL );
	
	var = rewrite_var_find( *tree, name );
	if ( var == NULL ) {
		if ( flags & REWRITE_VAR_INSERT ) {
			return rewrite_var_insert_f( tree, name, value, flags );

		} else {
			return NULL;
		}

	} else {
		assert( var->lv_value.bv_val != NULL );

		(void)rewrite_var_replace( var, value, flags );
	}

	return var;
}
示例#2
0
/*
 * Defines and inits a var with session scope
 */
int
rewrite_session_var_set_f(
		struct rewrite_info *info,
		const void *cookie,
		const char *name,
		const char *value,
		int flags
)
{
	struct rewrite_session *session;
	struct rewrite_var *var;

	assert( info != NULL );
	assert( cookie != NULL );
	assert( name != NULL );
	assert( value != NULL );

	session = rewrite_session_find( info, cookie );
	if ( session == NULL ) {
		session = rewrite_session_init( info, cookie );
		if ( session == NULL ) {
			return REWRITE_ERR;
		}

#ifdef USE_REWRITE_LDAP_PVT_THREADS
		ldap_pvt_thread_mutex_lock( &session->ls_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
	}

#ifdef USE_REWRITE_LDAP_PVT_THREADS
	ldap_pvt_thread_rdwr_wlock( &session->ls_vars_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

	var = rewrite_var_find( session->ls_vars, name );
	if ( var != NULL ) {
		assert( var->lv_value.bv_val != NULL );

		(void)rewrite_var_replace( var, value, flags );

	} else {
		var = rewrite_var_insert_f( &session->ls_vars, name, value, flags );
		if ( var == NULL ) {
#ifdef USE_REWRITE_LDAP_PVT_THREADS
			ldap_pvt_thread_rdwr_wunlock( &session->ls_vars_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
			rewrite_session_return( info, session );
			return REWRITE_ERR;
		}
	}	
	
#ifdef USE_REWRITE_LDAP_PVT_THREADS
	ldap_pvt_thread_rdwr_wunlock( &session->ls_vars_mutex );
#endif /* USE_REWRITE_LDAP_PVT_THREADS */

	rewrite_session_return( info, session );

	return REWRITE_SUCCESS;
}