[Freeciv-Dev] (PR#6133) remove struct user and user.h
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
this patch removes all traces of "struct user" from the codebase.
struct connection is used instead to relay information to the userdatabase
code. Raimar, you told me so.
This also easily allows other nice things like IP logging and such. Stats
and such will be stored in opaque structures in the connection.server struct.
-mike
diff -Nur -Xsnap/diff_ignore snap/server/connecthand.c
snap-conn/server/connecthand.c
--- snap/server/connecthand.c 2003-08-11 19:35:19.000000000 -0500
+++ snap-conn/server/connecthand.c 2003-09-10 19:20:35.000000000 -0500
@@ -28,7 +28,6 @@
#include "support.h"
#include "version.h"
-#include "user.h"
#include "user_db.h"
#include "diplhand.h"
#include "gamehand.h"
@@ -210,9 +209,7 @@
struct packet_login_request *req)
{
char msg[MAX_LEN_MSG];
- char orig_name[MAX_LEN_NAME];
- sz_strlcpy(orig_name, req->username);
remove_leading_trailing_spaces(req->username);
/* Name-sanity check: could add more checks? */
@@ -308,14 +305,12 @@
if (has_capability("auth", req->capability)
&& !is_guest_name(req->username)) {
- struct user user;
struct packet_authentication_request packet;
char tmpname[MAX_LEN_NAME] = "\0";
- sz_strlcpy(user.name, req->username);
sz_strlcpy(pconn->username, req->username);
- switch(user_db_load(&user)) {
+ switch(user_db_load(pconn)) {
case USER_DB_ERROR:
#ifdef GUESTS_ALLOWED
sz_strlcpy(tmpname, pconn->username);
@@ -334,7 +329,6 @@
break;
case USER_DB_SUCCESS:
/* we found a user */
- sz_strlcpy(pconn->password, user.password);
packet.type = AUTH_LOGIN_FIRST;
my_snprintf(packet.message, sizeof(packet.message),
_("Enter password for %s:"), pconn->username);
@@ -414,7 +408,6 @@
char msg[MAX_LEN_MSG];
if (pconn->server.status == AS_REQUESTING_NEW_PASS) {
- struct user user;
/* check if the new password is acceptable */
if (!is_good_password(packet->password, msg)) {
@@ -432,10 +425,9 @@
/* the new password is good, create a database entry for
* this user; we establish the connection in handle_db_lookup */
- sz_strlcpy(user.name, pconn->username);
- sz_strlcpy(user.password, packet->password);
+ sz_strlcpy(pconn->password, packet->password);
- switch(user_db_save(&user)) {
+ switch(user_db_save(pconn)) {
case USER_DB_SUCCESS:
break;
case USER_DB_ERROR:
diff -Nur -Xsnap/diff_ignore snap/server/userdb/Makefile.am
snap-conn/server/userdb/Makefile.am
--- snap/server/userdb/Makefile.am 2003-07-09 22:24:39.000000000 -0500
+++ snap-conn/server/userdb/Makefile.am 2003-09-10 18:57:07.000000000 -0500
@@ -8,5 +8,4 @@
lockfile.c \
lockfile.h \
user_db.c \
- user_db.h \
- user.h
+ user_db.h
diff -Nur -Xsnap/diff_ignore snap/server/userdb/user.h
snap-conn/server/userdb/user.h
--- snap/server/userdb/user.h 2003-07-09 22:24:39.000000000 -0500
+++ snap-conn/server/userdb/user.h 1969-12-31 18:00:00.000000000 -0600
@@ -1,25 +0,0 @@
-/**********************************************************************
- Freeciv - Copyright (C) 2003 - M.C. Kaufman
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-***********************************************************************/
-#ifndef FC__USER_H
-#define FC__USER_H
-
-#include "shared.h"
-
-struct user {
- char name[MAX_LEN_NAME];
- char password[MAX_LEN_NAME];
-
- /* add more fields here as warranted */
-};
-
-#endif /* FC__USER_H */
diff -Nur -Xsnap/diff_ignore snap/server/userdb/user_db.c
snap-conn/server/userdb/user_db.c
--- snap/server/userdb/user_db.c 2003-07-09 22:24:39.000000000 -0500
+++ snap-conn/server/userdb/user_db.c 2003-09-10 19:14:09.000000000 -0500
@@ -19,46 +19,52 @@
#include <stdlib.h>
#include <string.h>
+#include "connection.h"
#include "registry.h"
#include "shared.h"
#include "support.h"
#include "lockfile.h"
-#include "user.h"
#include "user_db.h"
#ifndef USER_DATABASE
#define FC_USER_DATABASE "freeciv_user_database"
#endif
-static void fill_entry(struct section_file *sf, struct user *puser, int no);
-static void fill_user(struct section_file *sf, struct user *puser, int no);
+static void fill_entry(struct section_file *sf,
+ struct connection *pconn, int no);
+
+static void fill_conn(struct section_file *sf,
+ struct connection *pconn, int no);
/**************************************************************************
- helper function to retrieve a user struct from the database
+ helper function to fill the user and password in the connection struct
+ from the database
**************************************************************************/
-static void fill_user(struct section_file *sf, struct user *puser, int no)
+static void fill_conn(struct section_file *sf,
+ struct connection *pconn, int no)
{
- sz_strlcpy(puser->name, secfile_lookup_str(sf, "db.users%d.name", no));
- sz_strlcpy(puser->password, secfile_lookup_str(sf, "db.users%d.pass", no));
+ sz_strlcpy(pconn->username, secfile_lookup_str(sf, "db.users%d.name", no));
+ sz_strlcpy(pconn->password, secfile_lookup_str(sf, "db.users%d.pass", no));
}
/**************************************************************************
- helper function to insert a user struct to the database
+ helper function to insert some fields of the connection struct to the database
**************************************************************************/
-static void fill_entry(struct section_file *sf, struct user *puser, int no)
+static void fill_entry(struct section_file *sf,
+ struct connection *pconn, int no)
{
- secfile_insert_str(sf, puser->name, "db.users%d.name", no);
- secfile_insert_str(sf, puser->password, "db.users%d.pass", no);
+ secfile_insert_str(sf, pconn->username, "db.users%d.name", no);
+ secfile_insert_str(sf, pconn->password, "db.users%d.pass", no);
}
/**************************************************************************
Loads a user from the database.
**************************************************************************/
-enum userdb_status user_db_load(struct user *puser)
+enum userdb_status user_db_load(struct connection *pconn)
{
struct section_file sf;
- int i, num_users = 0;
+ int i, num_entries = 0;
enum userdb_status result;
if (!create_lock()) {
@@ -71,22 +77,23 @@
result = USER_DB_NOT_FOUND;
goto unlock_end;
} else {
- num_users = secfile_lookup_int(&sf, "db.user_num");
+ num_entries = secfile_lookup_int(&sf, "db.num_entries");
}
- /* find the user in the database */
- for (i = 0; i < num_users; i++) {
- char *name = secfile_lookup_str(&sf, "db.users%d.name", i);
- if (strncmp(name, puser->name, MAX_LEN_NAME) == 0) {
+ /* find the connection in the database */
+ for (i = 0; i < num_entries; i++) {
+ char *username = secfile_lookup_str(&sf, "db.users%d.name", i);
+ if (strncmp(username, pconn->username, MAX_LEN_NAME) == 0) {
break;
}
}
- /* if we couldn't find the user, return, else, fill the user struct */
- if (i == num_users) {
+ /* if we couldn't find the connection, return, else,
+ * fill the connection struct */
+ if (i == num_entries) {
result = USER_DB_NOT_FOUND;
} else {
- fill_user(&sf, puser, i);
+ fill_conn(&sf, pconn, i);
result = USER_DB_SUCCESS;
}
section_file_free(&sf);
@@ -98,13 +105,14 @@
}
/**************************************************************************
- Saves a user to the database. If the user already exists, replace the data.
+ Saves pconn fields to the database. If the username already exists,
+ replace the data.
**************************************************************************/
-enum userdb_status user_db_save(struct user *puser)
+enum userdb_status user_db_save(struct connection *pconn)
{
struct section_file old, new;
- struct user entry;
- int i, num_users = 0, new_num = 1;
+ struct connection conn;
+ int i, num_entries = 0, new_num = 1;
enum userdb_status result;
if (!create_lock()) {
@@ -114,28 +122,28 @@
section_file_init(&new);
- /* add the pusers info to the database */
- fill_entry(&new, puser, 0);
+ /* add the pconns info to the database */
+ fill_entry(&new, pconn, 0);
/* load the file, and if it exists, save it to the new file */
if (section_file_load(&old, FC_USER_DATABASE)) {
- num_users = secfile_lookup_int(&old, "db.user_num");
+ num_entries = secfile_lookup_int(&old, "db.num_entries");
- /* fill the new database with the old one. skip puser if he
+ /* fill the new database with the old one. skip pconn if he
* exists, since we already inserted his new information */
- for (i = 0; i < num_users; i++) {
- fill_user(&old, &entry, i);
- if (strncmp(entry.name, puser->name, MAX_LEN_NAME) != 0) {
- fill_entry(&new, &entry, new_num++);
+ for (i = 0; i < num_entries; i++) {
+ fill_conn(&old, &conn, i);
+ if (strncmp(conn.username, pconn->username, MAX_LEN_NAME) != 0) {
+ fill_entry(&new, &conn, new_num++);
}
}
section_file_free(&old);
}
- /* insert the number of users */
- secfile_insert_int(&new, new_num, "db.user_num");
+ /* insert the number of connections */
+ secfile_insert_int(&new, new_num, "db.num_entries");
/* save to file */
if (!section_file_save(&new, FC_USER_DATABASE, 0)) {
diff -Nur -Xsnap/diff_ignore snap/server/userdb/user_db.h
snap-conn/server/userdb/user_db.h
--- snap/server/userdb/user_db.h 2003-07-09 22:24:39.000000000 -0500
+++ snap-conn/server/userdb/user_db.h 2003-09-10 18:56:55.000000000 -0500
@@ -13,7 +13,7 @@
#ifndef FC__USER_DB_H
#define FC__USER_DB_H
-struct user;
+struct connection;
/**************************************************
The user db statuses are:
@@ -29,7 +29,7 @@
USER_DB_NOT_FOUND
};
-enum userdb_status user_db_load(struct user *puser);
-enum userdb_status user_db_save(struct user *puser);
+enum userdb_status user_db_load(struct connection *pconn);
+enum userdb_status user_db_save(struct connection *pconn);
#endif /* FC__USER_DB_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#6133) remove struct user and user.h,
Mike Kaufman <=
|
|