📄 cuser.c
字号:
/*************************************************************************** CUser.c (c) 2000-2004 Beno� Minisini <gambas@users.sourceforge.net> 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 1, 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.***************************************************************************/#define __CUSER_C#include "main.h"#include "CUser.h"static int valid_user(CUSER *_object){ return (THIS->conn->handle == NULL);}static bool check_user(CCONNECTION *conn, const char *name, bool must_exist){ bool exist = conn->driver->User.Exist(conn->handle, (char *)name); if (must_exist) { if (!exist) { GB.Error("Unknown user: &1", name); return TRUE; } } else { if (exist) { GB.Error("User already exists: &1", name); return TRUE; } } return FALSE;}void *CUSER_get(CCONNECTION *conn, const char *name){ CUSER *_object; if (check_user(conn, name, TRUE)) return NULL; GB.New((void **)&_object, GB.FindClass("User"), NULL, NULL); THIS->conn = conn; GB.Ref(conn); THIS->driver = conn->driver; GB.NewString(&THIS->name, name, 0); conn->driver->User.Info(conn->handle, THIS->name, &THIS->info); return THIS;}int CUSER_exist(CCONNECTION *conn, const char *name){ return conn->driver->User.Exist(conn->handle, (char *)name);}void CUSER_list(CCONNECTION *conn, char ***list){ conn->driver->User.List(conn->handle, list);}/*************************************************************************** User***************************************************************************/BEGIN_METHOD_VOID(CUSER_free) if (!valid_user(THIS)) GB.SubCollection.Remove(THIS->conn->users, THIS->name, 0); GB.Unref((void **)&THIS->conn); GB.FreeString(&THIS->name); GB.FreeString(&THIS->info.password);END_METHODBEGIN_PROPERTY(CUSER_name) GB.ReturnString(THIS->name);END_PROPERTYBEGIN_METHOD_VOID(CUSER_delete) THIS->conn->driver->User.Delete(THIS->conn->handle, THIS->name);END_METHODBEGIN_PROPERTY(CUSER_password) if (READ_PROPERTY) GB.ReturnString(THIS->info.password); else if (THIS->name) { GB.StoreString(PROP(GB_STRING), &THIS->info.password); THIS->driver->User.SetPassword(THIS->conn->handle, THIS->name, THIS->info.password); }END_PROPERTYBEGIN_PROPERTY(CUSER_administrator) GB.ReturnBoolean(THIS->info.admin);END_PROPERTYBEGIN_PROPERTY(CUSER_connection) GB.ReturnObject(THIS->conn);END_PROPERTYGB_DESC CUserDesc[] ={ GB_DECLARE("User", sizeof(CUSER)), GB_NOT_CREATABLE(), GB_HOOK_CHECK(valid_user), GB_METHOD("_free", NULL, CUSER_free, NULL), GB_METHOD("Delete", NULL, CUSER_delete, NULL), GB_PROPERTY_READ("Name", "s", CUSER_name), GB_PROPERTY_READ("Administrator", "b", CUSER_administrator), GB_PROPERTY("Password", "s", CUSER_password), GB_PROPERTY_READ("Connection", "Connection", CUSER_connection), GB_END_DECLARE};/*************************************************************************** .ConnectionUsers***************************************************************************/#undef THIS#define THIS ((GB_SUBCOLLECTION)_object)BEGIN_METHOD(CUSER_add, GB_STRING name; GB_STRING password; GB_BOOLEAN admin) CCONNECTION *conn = GB.SubCollection.Container(THIS); char *name = GB.ToZeroString(ARG(name)); DB_USER info; CLEAR(&info); if (DB_CheckNameWith(name, "user", "@%")) return; if (check_user(conn, name, FALSE)) return; info.admin = VARGOPT(admin, FALSE); if (!MISSING(password)) info.password = GB.ToZeroString(ARG(password)); conn->driver->User.Create(conn->handle, name, &info);END_METHODBEGIN_METHOD(CUSER_remove, GB_STRING name) CCONNECTION *conn = GB.SubCollection.Container(THIS); char *name = GB.ToZeroString(ARG(name)); if (check_user(conn, name, TRUE)) return; GB.SubCollection.Remove(THIS, STRING(name), LENGTH(name)); conn->driver->User.Delete(conn->handle, name);END_METHODGB_DESC CConnectionUsersDesc[] ={ GB_DECLARE(".ConnectionUsers", 0), GB_INHERITS(".SubCollection"), GB_METHOD("Add", NULL, CUSER_add, "(Name)s[(Password)s(Admin)b]"), GB_METHOD("Remove", NULL, CUSER_remove, "(Name)s"), GB_END_DECLARE};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -