library/src/webchat/BP-WebChat.cc
// Attempts to add a chat user from a httpd user (user enters chat)
Attempts to add a chat user from a httpd user (user enters chat)
Attempts to add a chat user from a httpd user ( user enters chat )
P_BP_WEBCHAT_USER BP_WebChatAddUserFromHttpdUser
(
		P_BP_WEBCHAT                  webchat,
		P_BP_HTTPD_USER               httpd_user,
		char                         *chat_user,
		BP_BOOL                       is_admin,
		BP_WEBCHAT_USER_SOCIAL_STATUS overall_social_status_ranking,
		BP_BOOL                       can_create_channel_group,
		BP_BOOL                       can_create_channel,
		BP_BOOL                       can_create_user_group,
		size_t                        total_messages_sent,
		size_t                        total_messages_recieved,
		size_t                        total_user_approved_messages,
		size_t                        total_user_disapproved_messages,
		BP_BOOL                       can_change_username,
		BP_BOOL                       can_change_password
)
{
	if(!webchat)
		return NULL;
	if(!httpd_user)
		return NULL;
	if(!chat_user)
		return NULL;
	if(!webchat->system_hreg)
		return NULL;
	if(!BP_StringIsReasonablePrintableString(chat_user, bpstrlen(chat_user), BP_FALSE, BP_FALSE))
		return NULL;
	if(!BP_StringIsReasonablePrintableString(httpd_user->username, bpstrlen(httpd_user->username), BP_FALSE, BP_FALSE))
		return NULL;
	if(BP_WebChatLookupUserFromHTTPdUser(webchat, httpd_user))
		return NULL;
	if(BP_WebChatLookupUserFromChatUsername(webchat, chat_user))
		return NULL;
	P_BP_WEBCHAT_USER new_webchat_user = (P_BP_WEBCHAT_USER) ht_calloc(webchat->system_hreg, sizeof(BP_WEBCHAT_USER), 1);
	if(!new_webchat_user)
		return NULL;
	new_webchat_user->httpd_user                      = httpd_user;
	new_webchat_user->chat_user                       = ht_strndup(webchat->system_hreg, chat_user, bpstrlen(chat_user));
	new_webchat_user->is_admin                        = is_admin;
	new_webchat_user->overall_social_status_ranking   = overall_social_status_ranking;
	new_webchat_user->can_create_channel_group        = can_create_channel_group;
	new_webchat_user->can_create_channel              = can_create_channel;
	new_webchat_user->can_create_user_group           = can_create_user_group;
	new_webchat_user->total_messages_sent             = total_messages_sent;
	new_webchat_user->total_messages_recieved         = total_messages_recieved;
	new_webchat_user->total_user_approved_messages    = total_user_approved_messages;
	new_webchat_user->total_user_disapproved_messages = total_user_disapproved_messages;
	new_webchat_user->can_change_username             = can_change_username;
	new_webchat_user->can_change_password             = can_change_password;
	char *table_add_path[10];
	BP_ZERO_STACK(table_add_path);
	char *table_search_path[10];
	BP_ZERO_STACK(table_search_path);
	table_add_path[0] = "users";
	table_add_path[1] = "hashed_by_httpd_username";
	BP_HashRegAddDataToTableByPath
	(
			webchat->system_hreg,
			(char **) &table_add_path,
			httpd_user->username,
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			NULL,
			sizeof(new_webchat_user)
	);
	table_search_path[0] = "users";
	table_search_path[1] = "hashed_by_httpd_username";
	table_search_path[2] = httpd_user->username;
	P_BP_HASH_TABLE_KEYED_ENTRY user_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->system_hreg,
		(char **) &table_search_path
	);
	P_BP_WEBCHAT_USER * user_ptr = (P_BP_WEBCHAT_USER *) user_lookup->data;
	*user_ptr = new_webchat_user;
	P_BP_WEBCHAT_USER httpd_user_lookup = BP_WebChatLookupUserFromHTTPdUser(webchat, httpd_user);
	if(!httpd_user_lookup)
		return NULL;
	table_add_path[0] = "users";
	table_add_path[1] = "hashed_by_webchat_username";
	BP_HashRegAddDataToTableByPath
	(
			webchat->system_hreg,
			(char **) &table_add_path,
			chat_user,
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			NULL,
			sizeof(new_webchat_user)
	);
	table_search_path[0] = "users";
	table_search_path[1] = "hashed_by_webchat_username";
	table_search_path[2] = chat_user;
	P_BP_HASH_TABLE_KEYED_ENTRY webchat_lookup = BP_HashRegLookupTableEntryByPath
	(
		webchat->system_hreg,
		(char **) &table_search_path
	);
	P_BP_WEBCHAT_USER * webchat_ptr = (P_BP_WEBCHAT_USER *) webchat_lookup->data;
	*webchat_ptr = new_webchat_user;
	P_BP_WEBCHAT_USER webchat_user_lookup = BP_WebChatLookupUserFromChatUsername(webchat,chat_user);
	if(!webchat_user_lookup)
		return NULL;
	%%%%%%%%%%%%
	%%%%%%%%%%%%
	printf("\n ADDING USERS HERE WOOP: %p - %p", httpd_user_lookup, webchat_user_lookup);
	return new_webchat_user;
}
P_BP_WEBCHAT_USER BP_WebChatAddUserFromHttpdUser ( P_BP_WEBCHAT webchat , P_BP_HTTPD_USER httpd_user , char * chat_user , BP_BOOL is_admin , BP_WEBCHAT_USER_SOCIAL_STATUS overall_social_status_ranking , BP_BOOL can_create_channel_group , BP_BOOL can_create_channel , BP_BOOL can_create_user_group , size_t total_messages_sent , size_t total_messages_recieved , size_t total_user_approved_messages , size_t total_user_disapproved_messages , BP_BOOL can_change_username , BP_BOOL can_change_password ) { if ( ! webchat ) return NULL ; if ( ! httpd_user ) return NULL ; if ( ! chat_user ) return NULL ; if ( ! webchat -> system_hreg ) return NULL ; if ( ! BP_StringIsReasonablePrintableString ( chat_user , bpstrlen ( chat_user ) , BP_FALSE , BP_FALSE ) ) return NULL ; if ( ! BP_StringIsReasonablePrintableString ( httpd_user -> username , bpstrlen ( httpd_user -> username ) , BP_FALSE , BP_FALSE ) ) return NULL ; if ( BP_WebChatLookupUserFromHTTPdUser ( webchat , httpd_user ) ) return NULL ; if ( BP_WebChatLookupUserFromChatUsername ( webchat , chat_user ) ) return NULL ; P_BP_WEBCHAT_USER new_webchat_user = ( P_BP_WEBCHAT_USER ) ht_calloc ( webchat -> system_hreg , sizeof ( BP_WEBCHAT_USER ) , 1 ) ; if ( ! new_webchat_user ) return NULL ; new_webchat_user -> httpd_user = httpd_user ; new_webchat_user -> chat_user = ht_strndup ( webchat -> system_hreg , chat_user , bpstrlen ( chat_user ) ) ; new_webchat_user -> is_admin = is_admin ; new_webchat_user -> overall_social_status_ranking = overall_social_status_ranking ; new_webchat_user -> can_create_channel_group = can_create_channel_group ; new_webchat_user -> can_create_channel = can_create_channel ; new_webchat_user -> can_create_user_group = can_create_user_group ; new_webchat_user -> total_messages_sent = total_messages_sent ; new_webchat_user -> total_messages_recieved = total_messages_recieved ; new_webchat_user -> total_user_approved_messages = total_user_approved_messages ; new_webchat_user -> total_user_disapproved_messages = total_user_disapproved_messages ; new_webchat_user -> can_change_username = can_change_username ; new_webchat_user -> can_change_password = can_change_password ; char * table_add_path [ 10 ] ; BP_ZERO_STACK ( table_add_path ) ; char * table_search_path [ 10 ] ; BP_ZERO_STACK ( table_search_path ) ; table_add_path [ 0 ] = " " ; table_add_path [ 1 ] = " " ; BP_HashRegAddDataToTableByPath ( webchat -> system_hreg , ( char * * ) & table_add_path , httpd_user -> username , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( new_webchat_user ) ) ; table_search_path [ 0 ] = " " ; table_search_path [ 1 ] = " " ; table_search_path [ 2 ] = httpd_user -> username ; P_BP_HASH_TABLE_KEYED_ENTRY user_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> system_hreg , ( char * * ) & table_search_path ) ; P_BP_WEBCHAT_USER * user_ptr = ( P_BP_WEBCHAT_USER * ) user_lookup -> data ; * user_ptr = new_webchat_user ; P_BP_WEBCHAT_USER httpd_user_lookup = BP_WebChatLookupUserFromHTTPdUser ( webchat , httpd_user ) ; if ( ! httpd_user_lookup ) return NULL ; table_add_path [ 0 ] = " " ; table_add_path [ 1 ] = " " ; BP_HashRegAddDataToTableByPath ( webchat -> system_hreg , ( char * * ) & table_add_path , chat_user , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( new_webchat_user ) ) ; table_search_path [ 0 ] = " " ; table_search_path [ 1 ] = " " ; table_search_path [ 2 ] = chat_user ; P_BP_HASH_TABLE_KEYED_ENTRY webchat_lookup = BP_HashRegLookupTableEntryByPath ( webchat -> system_hreg , ( char * * ) & table_search_path ) ; P_BP_WEBCHAT_USER * webchat_ptr = ( P_BP_WEBCHAT_USER * ) webchat_lookup -> data ; * webchat_ptr = new_webchat_user ; P_BP_WEBCHAT_USER webchat_user_lookup = BP_WebChatLookupUserFromChatUsername ( webchat , chat_user ) ; if ( ! webchat_user_lookup ) return NULL ; printf ( " \n " , httpd_user_lookup , webchat_user_lookup ) ; return new_webchat_user ; }
Attempts to add a chat user from a httpd user (user enters chat)
Attempts to add a chat user from a httpd user ( user enters chat )
// basic null checks // basic reasonable checks on new chat username // basic reasonable checks on httpd username // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt Lookup Checks %%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // exit if we already have a user // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add New User and Specify Initial Settings %%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create new webchat user // set settings for new user from webchat // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Table Fast Lookup References %%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create add path // create search path // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Hash By HTTP Username %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set the table add path // add data from username // search to see if httpd user already exists // attempt to lookup entry in the table // set pointer reference // copy pointer into new data // user lookup // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Reference by Username %%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // add data from username // search to see if httpd user already exists // attempt to lookup entry in the table // set pointer reference // copy pointer into new data // lookup user from chat username // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // return the new webchat user