| id | int |
| username | char(20) |
| password | char(20) |
| last_avatar | int |
| logged_in | int |
| net_id | int |
| last_login | int |
Schema for GROUPS table
| owner_id | char(20) |
| list_id | char(20) |
| member_id | char(20) |
This is the API to connect with the
editor database. For now, I'd recommend
running everything on speedy.cc because
I hardcoded some things temporarily.
However, the client can connect to
other hosts... just not right now. Some
things you should know before
you get started...
1)
Username: vrmidtown
Password: vrmidtown
Database: vrmidtown
tables: userdb, groups
This account has ALL privileges so
please be careful when doing anything from
the mysql prompt.
2)
Start the server by typing:
startdb-X where X is the platform
you're running on.
3)
I have included a test client that
executes all the functions in the library.
It's pretty simple and everything
is explained further in the userdb.h file.
The "make" file is just a script called
"run-X" for now where X is the
platform you're running on.
4)
I have included a script to create
a small test table for the test client.
You will require both create and create.sql
files. Create can be run from any
directory. Please run this before
you run the test client so you can start
with fresh data.
5)
I probably left something out so e-mail
me if you have problems. Also,
there's an extensive manual in html
format included with the mysql server.
6)
Start the server before you do ANYTHING.
Otherwise, it's pretty much
pointless, isn't it. Also, don't
forget to kill the server after you're
done. This can be done my typing:
killdb-X where X is the platform you're
running on.
That's it.
/*
So far, the only information stored
in the database is the user's userid,
(used by the system) name, password,
last avatar used, logged_in (takes values
of 0 or 1 only), and timestamp (used
by the system). More data can be added
later on as deemed necessary.
Changes:
2/24/99 - Added logged_in variable
in the struct to act as a boolean to
see if the user is logged in or not.
Removed the userid field b/c it's only
for internal use. Removed timestap
for the same reason.
2/26/99 - Added four functions: add_ToGroup,
remove_FromGroup, logged_In,
and showNetID. Changed the user_t
struct so that the userid is no longer in
there, but the net_id is. I
changed remove_User so that it doesn't
return ERROR_A.
3/2/99 - Added show_AllConnectedUsers.
3/3/99 - Changed net_id to type int. Added get_UserInfoID.
3/10/99 - Added multi-group functionality.
Had to makes changes to or add
the following functions:
add_List
remove_List
add_ToGroup
remove_FromGroup
show_NetID
*/
/* return values for the following
functions.
SUCCESS and ERROR are obvious.
ERROR_A represents check errors, for eg: the
user you want to delete does not exist,
etc...
*/
#define SUCCESS 1
#define ERROR 0
#define ERROR_A -1
/* error types */
#define ERR_CONNECT
1
#define ERR_QUERY
2
#define ERR_INITIALIZE_MYSQL
3
#define ERR_STORE_RESULT
4
typedef struct {
char
username[21];
char
password[21];
int
avatar; /* accepts any integer up to 9 digits */
int
logged_in; /* 0 - not logged in, 1 - logged in. */
int
net_id; /* accepts any integer up to 9 digits */
} user_t;
/* function prototypes */
int validate_Login (char *username,
char *password);
/*
Input: username, password
Returns: SUCCESS | ERROR
Will take in a username and password
and search through the database.
If the user exists in the database
and the password is correct, it will
return SUCCESS or else return ERROR.
*/
int add_User (user_t user);
/*
Input: user_t struct
Returns: SUCCESS | ERROR | ERROR_A
Will attempt to add an entry into
the user database based on the
username. If there's an error,
ERROR will be returned. If a user by that
name already exists, ERROR_A is returned.
If user was successfully added,
SUCCESS is returned. */
int remove_User (char *username, char
*password);
/*
Input: username, password
Returns: SUCCESS | ERROR
Takes in a username and password.
If the username and password match
up with an entry, it is removed and
SUCCESS is returned. If there was an
error removing the user, ERROR is
returned.
*/
int update_User (user_t user);
/*
Input: user_t
Returns: SUCCESS | ERROR
Takes in a user_t struct and attempts
to update the existing
information. Return SUCCESS
on success, ERROR on error.
*/
int get_UserInfo (user_t *user);
/*
Input: user_t
Returns: SUCCESS | ERROR
Takes in the username and password
and tries to find the user and return
his/her information. If the
user was found and information sent successfully,
SUCCESS is returned. If there
was an error, ERROR is returned.
*/
int get_UserInfoID (user_t *user);
/*
Input: user_t
Returns: SUCCESS | ERROR
Takes in the net_id of a user and
tries to find the user and return
his/her information. If the
user was found and information sent successfully,
SUCCESS is returned. If there
was an error, ERROR is returned.
*/
int add_List (char *username, char
*listname);
/*
Input: username, listname (of mailing
list)
Returns: SUCCESS | ERROR
Takes in the username and mailing
list name and attempts to create a
mailing list under that user's name.
Returns SUCCESS on success, ERROR if that list already exists.
*/
int remove_List (char *username, char
*listname);
/*
Input: username, listname (of mailing
list)
Returns: SUCCESS | ERROR
Takes in the username and mailing
list and attempts to remove that
mailing list whether it's full or
not. Returns SUCCESS on success, ERROR if that list does not exist.
*/
int add_ToGroup (char *username, char
*member, char *listname);
/*
Input: username, member, listname(of
mailing list)
Returns: SUCCESS | ERROR | ERROR_A
Takes in the username and member to
add to the username's "mailing list". If
the member is added correctly, SUCCESS
is returned. If member is already in
the username's list, ERROR_A is returned.
Otherwise, ERROR is returned.
*/
int remove_FromGroup (char *username,
char *member, char *listname);
/*
Input: username, member, listname
Returns: SUCCESS | ERROR
Takes in the username and member to
remove from the username's "mailing
list". If the member is removed
correctly, SUCCESS is returned. Otherwise,
ERROR is returned.
*/
int logged_In (char *username);
/*
Input: username
Returns: SUCCESS | ERROR
This takes in the username and checks
to see if that person is logged in. If
the user is logged in, SUCCESS is
returned. Otherwise, ERROR is returned.
*/
int *
show_NetID (char *username, int *
const NumItems, char *listname);
/*
Input: username, a integer containing
the size of the array that will
returned, and the mailing list.
Returns: This function will take in
a username and an integer. It will then
create an array of net_ids of all
the people in the username's "listname"
who are connected to the server.
It will then return a pointer pointing to
the array of net_id's and NumItems
will contain the number of elements
in the array. If NULL is returned,
there was an error in the transaction.
*/
int
show_AllConnectedUsers ();
/*
Input: none
Returns:
This function will go through and
print out the usernames of all those
who are connected to the database
server. It will return the number of
users who are connected... -1 if there
was an error.
Note: Used for testing.
*/