midgard/midgard_legacy.h

00001 /* $Id: midgard_legacy.h,v 1.6 2006/07/31 10:34:55 piotras Exp $
00002  *
00003  * midgard-lib: database access for Midgard clients
00004  *
00005  * Copyright (C) 1999 Jukka Zitting <jukka.zitting@iki.fi>
00006  * Copyright (C) 2000 The Midgard Project ry
00007  * Copyright (C) 2003 David Schmitter, Dataflow Solutions GmbH <schmitt@dataflow.ch>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this library; see the file COPYING.  If not, write to
00021  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00022  * Boston, MA 02111-1307, USA.
00023  */
00024 
00025 #ifndef MIDGARD_LEGACY_H
00026 #define MIDGARD_LEGACY_H
00027 
00028 #include <stdarg.h>
00029 #include <assert.h>
00030 #include <stdlib.h>
00031 #include <ctype.h>
00032 #include <time.h>
00033 #ifdef WIN32
00034 #include <windows.h>
00035 #endif
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <glib.h>
00039 #include "midgard/midgard_config_auto.h"
00040 #include "midgard/midgard_defs.h"
00041 #include "midgard/parser.h"
00042 #include "midgard/tablenames.h"
00043 #include "midgard/pool.h"
00044 #include "midgard/midgard_connection.h"
00045 #include "midgard/midgard_schema.h"
00046 
00047 typedef enum {
00048         MGD_AUTHTYPE_NORMAL = 0,
00049         MGD_AUTHTYPE_PAM
00050 } midgard_auth_type;
00051 
00052 struct _mgd_userinfo {
00053         int id, is_admin, *member_of;
00054         int is_root, sitegroup;
00055 };
00056 
00057 struct _midgard {
00058         midgard_mysql *msql;
00059         midgard_res *res;
00060         midgard_pool *pool, *tmp;
00061         mgd_parser* parser;
00062         mgd_userinfo user_at_pagestart, setuid_user;
00063         mgd_userinfo *current_user;
00064         int lang;
00065         int default_lang;
00066         int p_lang;
00067         int a_lang;
00068         char *username;
00069         char *blobdir;
00070 #if HAVE_MIDGARD_VC
00071         char *cvs_script;
00072 #endif /* HAVE_MIDGARD_VC */
00073         char *ah_prefix;
00074 #if HAVE_MIDGARD_QUOTA
00075         int quota;
00076         int quota_err;
00077         GHashTable *qlimits;
00078 #endif /* HAVE_MIDGARD_QUOTA */
00079         midgard_auth_type auth_type;
00080         MidgardSchema *schema;
00081         gchar *schemafile;
00082         gint errn;
00083         guint loglevel;
00084         const gchar *logfile;
00085         gpointer person;
00086         GHashTable *style_elements;
00087         GError *err;
00088         guint loghandler;
00089         MidgardConnection *_mgd;
00090         const gchar *pamfile;
00091 };
00092 
00093 #if HAVE_MIDGARD_QUOTA
00094 struct _qlimit {
00095         int number;
00096         int space;
00097         char* fields;
00098 };
00099 #endif /* HAVE_MIDGARD_QUOTA */
00100 
00101 struct _midgard_res {
00102         midgard *mgd;
00103         midgard_res *next, *prev;
00104         midgard_pool *pool;
00105         midgard_mysql *msql;
00106         int rown, rows, cols;
00107 };
00108 
00109 /* PATH_MAX is not available on Win32, we use our own define here */
00110 #ifndef MAXPATHLEN
00111 # ifdef PATH_MAX
00112 #  define MAXPATHLEN PATH_MAX
00113 # else
00114 #  define MAXPATHLEN 256    /* Should be safe for any weird systems that do not define it */
00115 # endif
00116 #endif
00117 
00119 #define MGD_API extern
00120 
00121 #define MIDGARD_REPLIGARD_TAG_LENGTH 64
00122 #define MIDGARD_LOGIN_SG_SEPARATOR "+*!$;"
00123 #define MIDGARD_LOGIN_RESERVED_CHARS MIDGARD_LOGIN_SG_SEPARATOR "="
00124 
00125 #include "midgard/guid.h"
00126 
00127 #define MGD_STRUCT_STD_FIELDS \
00128   midgard_res *res; int restype; \
00129   int id, creator, revisor, revision; \
00130   time_t created, revised;
00131 
00132 /*[eeh] Custom log levels */
00133 typedef enum {
00134    G_LOG_LEVEL_DEBUG_PARSE_URI_VERBOSE   =  1 << G_LOG_LEVEL_USER_SHIFT
00135 } MgdGLogLevelFlags;
00136 
00137 MGD_API const char *mgd_version();
00138 MGD_API void mgd_init();
00139 MGD_API guint mgd_parse_log_levels(const char *levels);
00140 MGD_API void mgd_init_ex(guint log_levels, char *logfile);
00141 MGD_API void mgd_done();
00142 MGD_API void mgd_log_debug_default(const gchar *domain, GLogLevelFlags level,
00143           const gchar *msg, gpointer userdata);
00144 /* MGD_API const char *mgd_lib_prefix(); */
00145 
00146 /* Database connection */
00147 MGD_API midgard *mgd_setup();
00148 //MGD_API midgard *mgd_connect(const char *database,
00149 //                          const char *username, const char *password);
00150 MGD_API midgard *mgd_connect(const char *hostname, const char *database,
00151                             const char *username, const char *password);
00152 MGD_API void mgd_close(midgard * mgd);
00153 
00154 #define MGD_CLEAR_BASE        0
00155 #define MGD_CLEAR_SITEGROUP   1
00156 #define MGD_CLEAR_PARSER      2
00157 #define MGD_CLEAR_ALL         (MGD_CLEAR_BASE + MGD_CLEAR_SITEGROUP + MGD_CLEAR_PARSER)
00158 MGD_API void mgd_clear(midgard * mgd, int clearflags);
00159 MGD_API int mgd_errno(midgard * mgd);
00160 MGD_API const char *mgd_error(midgard * mgd);
00161 MGD_API int mgd_select_db(midgard *mgd, const char *database);
00162 MGD_API int mgd_assert_db_connection(midgard *mgd, const char *hostname, const char *database,
00163       const char* username, const char *pass);
00164 
00165 MGD_API int mgd_auth(midgard * mgd,
00166       const char *username, const char *password,
00167       int setuid);
00168 
00179 MGD_API int mgd_auth_trusted(midgard *mgd, const char *username);
00180 
00181 MGD_API int mgd_auth_is_setuid(midgard * mgd);
00182 MGD_API int mgd_auth_unsetuid(midgard * mgd, long int rsg);
00183 
00184 /* Language parser utilites */
00185 MGD_API int mgd_select_parser(midgard * mgd, const char *parser);
00186 MGD_API const char *mgd_get_parser_name(midgard * mgd);
00187 /* Encoding of mail messages */
00188 MGD_API const char *mgd_get_encoding(midgard * mgd);
00189 /* Is mail should be sent as quoted printable text? */
00190 MGD_API int mgd_mail_need_qp(midgard * mgd);
00191 
00192 /* User information */
00193 MGD_API int mgd_user(midgard * mgd);
00194 MGD_API int mgd_isauser(midgard * mgd);
00195 MGD_API int mgd_isadmin(midgard * mgd);
00196 MGD_API int mgd_isroot(midgard * mgd);
00197 MGD_API void mgd_force_root(midgard * mgd); /* use with extreme care */
00198 MGD_API int mgd_isuser(midgard * mgd, int user);
00199 MGD_API int mgd_ismember(midgard * mgd, int group);
00200 MGD_API int *mgd_groups(midgard * mgd);
00201 MGD_API void mgd_force_admin(midgard * mgd); /* use with extreme care */
00202 
00203 /* Sitegroup information */
00204 MGD_API void mgd_set_sitegroup(midgard * mgd, int sitegroup);
00205 MGD_API int mgd_sitegroup(midgard * mgd);
00206 
00207 #if HAVE_MIDGARD_MULTILANG
00208 /* I18N stuff */
00209 MGD_API int mgd_internal_set_parameters_defaultlang(midgard *mgd, int lang);
00210 MGD_API int mgd_parameters_defaultlang(midgard * mgd);
00211 MGD_API int mgd_internal_set_attachments_defaultlang(midgard *mgd, int lang);
00212 MGD_API int mgd_attachments_defaultlang(midgard * mgd);
00213 MGD_API int mgd_internal_set_lang(midgard *mgd, int lang);
00214 MGD_API void mgd_set_default_lang(midgard *mgd, int lang);
00215 MGD_API int mgd_get_default_lang(midgard *mgd);
00216 MGD_API int mgd_lang(midgard * mgd);
00217 
00218 
00219 #endif /* HAVE_MIDGARD_MULTILANG */
00220 /* Data retrieval */
00221 MGD_API midgard_res *mgd_query(midgard * mgd, const char *query, ...);
00222 MGD_API midgard_res *mgd_vquery(midgard * mgd, const char *query, va_list args);
00223 MGD_API midgard_res *mgd_ungrouped_select(midgard * mgd,
00224                                          const char *fields, const char *from,
00225                                          const char *where, const char *sort,
00226                                          ...);
00227 MGD_API midgard_res *mgd_ungrouped_vselect(midgard * mgd, const char *fields,
00228                                           const char *from, const char *where,
00229                                           const char *sort, va_list args);
00230 MGD_API midgard_res *mgd_sitegroup_select(midgard * mgd,
00231                                          const char *fields, const char *from,
00232                                          const char *where, const char *sort,
00233                                          ...);
00234 MGD_API midgard_res *mgd_sitegroup_vselect(midgard * mgd, const char *fields,
00235                                           const char *from, const char *where,
00236                                           const char *sort, va_list args);
00237 MGD_API midgard_res *mgd_sitegroup_record(midgard * mgd, const char *fields,
00238                                          const char *table, int id);
00239 #if HAVE_MIDGARD_MULTILANG
00240 MGD_API midgard_res *mgd_sitegroup_record_lang(midgard * mgd,
00241                                   const char *fields, const char *table, int id);
00242 
00243 #endif /* HAVE_MIDGARD_MULTILANG */
00244 MGD_API midgard_res *mgd_ungrouped_record(midgard * mgd,
00245                                          const char *fields, const char *table,
00246                                          int id);
00247 MGD_API int mgd_idfield(midgard * mgd, const char *field, const char *table,
00248                        int id);
00249 /* Only use mgd_exists_id on single-table queries that are not the
00250    sitegroup table */
00251 MGD_API int mgd_exists_id(midgard * mgd, const char *from, const char *where, ...);
00252 /* make sure you do your own sitegroup verifications, mgd_exists_bool
00253    doesn't */
00254 MGD_API int mgd_exists_bool(midgard * mgd, const char *from, const char *where, ...);
00255 MGD_API int mgd_global_exists(midgard * mgd, const char *where, ...);
00256 
00257 MGD_API int mgd_fetch(midgard_res * res);
00258 MGD_API void mgd_release(midgard_res * res);
00259 
00260 MGD_API int mgd_rows(midgard_res * res);
00261 MGD_API int mgd_cols(midgard_res * res);
00262 
00263 MGD_API const char *mgd_colname(midgard_res * res, int col);
00264 MGD_API const char *mgd_colvalue(midgard_res * res, int col);
00265 MGD_API int mgd_colisnum(midgard_res * res, int col);
00266 MGD_API const char *mgd_column(midgard_res * res, const char *name);
00267 
00268 MGD_API int mgd_sql2id(midgard_res * res, int col);
00269 MGD_API int mgd_sql2int(midgard_res * res, int col);
00270 MGD_API const char *mgd_sql2str(midgard_res * res, int col);
00271 MGD_API time_t mgd_sql2date(midgard_res * res, int col);
00272 MGD_API time_t mgd_sql2time(midgard_res * res, int col);
00273 MGD_API time_t mgd_sql2datetime(midgard_res * res, int col);
00274 
00275 /* Data modification */
00276 MGD_API int mgd_exec(midgard * mgd, const char *command, ...);
00277 MGD_API int mgd_vexec(midgard * mgd, const char *command, va_list args);
00278 MGD_API int mgd_create(midgard * mgd, const char *table,
00279                       const char *fields, const char *values, ...);
00280 MGD_API int mgd_vcreate(midgard * mgd, const char *table,
00281                        const char *fields, const char *values, va_list args);
00282 MGD_API int mgd_update(midgard * mgd, const char *table, int id,
00283                       const char *fields, ...);
00284 MGD_API int mgd_vupdate(midgard * mgd, const char *table, int id,
00285                        const char *fields, va_list args);
00286 MGD_API int mgd_delete(midgard * mgd, const char *table, int id);
00287 
00288 /* repligard functions */
00289 MGD_API int mgd_create_repligard(midgard * mgd, const char *table,
00290                                 const char *fields, const char *values, ...);
00291 MGD_API int mgd_vcreate_repligard(midgard * mgd, const char *table,
00292                                  const char *fields, const char *values,
00293                                  va_list args);
00294 MGD_API int mgd_update_repligard(midgard * mgd, const char *table, int id,
00295                                 const char *fields, ...);
00296 MGD_API int mgd_vupdate_repligard(midgard * mgd, const char *table, int id,
00297                                  const char *fields, va_list args);
00298 MGD_API int mgd_delete_repligard(midgard * mgd, const char *table, int id);
00299 
00300 /* utility functions */
00301 MGD_API midgard_pool *mgd_pool(midgard * mgd);
00302 MGD_API midgard_pool *mgd_res_pool(midgard_res * res);
00303 MGD_API void mgd_set_blobdir(midgard *mgd, char *blobdir);
00304 MGD_API const char* mgd_get_blobdir(midgard *mgd);
00305 #if HAVE_MIDGARD_VC
00306 MGD_API void mgd_set_cvs_script(midgard *mgd, char *cvs_script);
00307 MGD_API const char* mgd_get_cvs_script(midgard *mgd);
00308 #endif /* HAVE_MIDGARD_VC */
00309 #if HAVE_MIDGARD_QUOTA
00310 MGD_API void mgd_set_quota(midgard *mgd, int quota);
00311 MGD_API int mgd_get_quota(midgard *mgd);
00312 MGD_API int mgd_get_quota_count(midgard *mgd, const char* table, int sitegroup);
00313 MGD_API int mgd_get_quota_space(midgard *mgd, const char* table, const char* fields, int sitegroup);
00314 MGD_API int mgd_touch_recorded_quota(midgard *mgd, const char* table, int sitegroup);
00315 MGD_API void mgd_touch_quotacache(midgard *mgd);
00316 MGD_API void mgd_set_quota_error(midgard *mgd, int nr);
00317 MGD_API int mgd_get_quota_error(midgard *mgd);
00318 #endif /* HAVE_MIDGARD_QUOTA */
00319 MGD_API void mgd_set_ah_prefix(midgard *mgd, char* prefix);
00320 MGD_API char *mgd_get_ah_prefix(midgard *mgd);
00321 MGD_API char *mgd_format(midgard * mgd, midgard_pool * pool, const char *fmt,
00322                         ...);
00323 MGD_API char *mgd_vformat(midgard * mgd, midgard_pool * pool, const char *fmt,
00324                          va_list args);
00325 
00326 #if HAVE_MIDGARD_VC
00327 MGD_API void mgd_cvs_dump_nowait(midgard * mgd, const char* table, int id);
00328 MGD_API void mgd_cvs_dump_nowait_guid(midgard * mgd, const char* guid);
00329 MGD_API int mgd_vc_create_repligard(midgard *mgd, const char *table, int id);
00330 #endif /* HAVE_MIDGARD_VC */
00331 
00332 /* Repligard utilities */
00333 MGD_API char* mgd_repligard_guid(midgard* mgd, midgard_pool* pool, const char* table, int id);
00334 MGD_API int mgd_repligard_id(midgard* mgd, const char* guid);
00335 MGD_API int mgd_delete_repligard_guid(midgard* mgd, const char* guid);
00336 MGD_API int mgd_delete_repligard(midgard* mgd, const char* table, int id);
00337 MGD_API char* mgd_repligard_changed(midgard* mgd, midgard_pool* pool, const char* table, int id);
00338 MGD_API char* mgd_repligard_changed_guid(midgard* mgd, midgard_pool* pool, const char* guid);
00339 MGD_API char* mgd_repligard_updated(midgard* mgd, midgard_pool* pool, const char* table, int id);
00340 MGD_API char* mgd_repligard_updated_guid(midgard* mgd, midgard_pool* pool, const char* guid);
00341 MGD_API char* mgd_repligard_table(midgard* mgd, midgard_pool* pool, const char* guid);
00342 MGD_API char* mgd_repligard_action(midgard* mgd, midgard_pool* pool, const char* guid);
00343 
00344 /* Updates Repligard's records for given table: creates if they aren't exist */
00345 MGD_API void mgd_repligard_touch(midgard * mgd, const char *table);
00346 
00347 /* Creates a record in the Repligard table. Generates guid based on object ID, 
00348    class (table name) and current time. GUID is a md5 sum of  'magic string'
00349 */
00350 # define CREATE_REPLIGARD(mgd, table,id)
00351 
00352 /* Updates a record in the Repligard table. Sets changed time to the current time */
00353 #define UPDATE_REPLIGARD(mgd, table,id)\
00354         mgd_update_repligard(mgd, table, id, "changed=NULL,action='update'");
00355 /* Updates a record in the Repligard table. Sets changed time to the specified one */
00356 #define UPDATE_REPLIGARD_TIME(mgd, table,id, changed)\
00357         mgd_update_repligard(mgd, table, id, "changed=$q,action='update'", changed);
00358 
00359 /* Marks a record in the Repligard table for deletion */
00360 #define DELETE_REPLIGARD(mgd, table,id)\
00361         mgd_update_repligard(mgd, table, id, "updated=0,action='delete'");
00362 
00363 /* Tree management */
00365 struct _tree_node {
00366         int id;                                         
00367         int up;                                         
00368         int level;                                      
00369         int size;                                       
00370         struct _tree_node * child;      
00371         struct _tree_node * next;       
00372 };
00373 
00374 typedef struct _tree_node tree_node;
00375 
00376 struct _grp_tree_node {
00377    int id;                          /* !< id of the node */
00378    struct _grp_tree_node * child;   /* !< first child (none when = NULL) */
00379 };
00380 
00381 typedef struct _grp_tree_node grp_tree_node;
00382 
00383 
00384 /* Returns raw tree information about given table.
00385    Maximum possible level of branches is returned in maxlevel. 
00386    Sort specifies sorting and defaults to 'id' if omitted.
00387    Actual value of sort should be name of one of the fields in record.
00388 */
00389 tree_node * mgd_tree_build(midgard * mgd, midgard_pool * pool,
00390                         const char * table, const char * upfield, int root,
00391                         int maxlevel, const char * sort);
00392 /* Returns array of ids of branches under selected tree with given id 
00393    but no deeper than maxlevel. If maxlevel == 0 then whole tree will 
00394    be returned. If id == 0 then all distinct branches will be returned.
00395 */
00396 MGD_API int *mgd_tree(midgard * mgd, const char * table, const char * upfield,
00397                         int id, int maxlevel, const char *sort);
00398 MGD_API int mgd_is_in_tree(midgard * mgd, const char *table, const char *upfield,
00399                                 int root, int id);
00401 typedef int (*midgard_userfunc) (midgard * mgd, int id, int level,
00402                                   void *xparam);
00403 
00404 /* Traverses table tree starting from root and calls user-defined function */
00405 MGD_API int mgd_walk_table_tree(midgard * mgd, const char *table,
00406                                 const char * upfield, int root,
00407                                 int maxlevel, int order, void *xparam,
00408                                 midgard_userfunc func, const char * sort);
00409 
00410 MGD_API int mgd_copy_object(midgard * mgd, midgard_res * object,
00411                            const char *table, const char *upfield, int new_up);
00412 MGD_API int mgd_move_object(midgard * mgd, const char *table,
00413                            const char *upfield, int id, int newup);
00414 
00415 /* Copies topic sub-tree with included articles and return ID of copy 
00416    of root topic
00417 */
00418 MGD_API int mgd_copy_topic(midgard * mgd, int root);
00419 
00420 /* Deletes topic sub-tree with included articles */
00421 MGD_API int mgd_delete_topic(midgard * mgd, int root);
00422 
00423 /* Copies page sub-tree with included pageelements and return ID of copy 
00424    of page
00425 */
00426 MGD_API int mgd_copy_page(midgard * mgd, int root);
00427 
00428 /* Copy article/pageelement/element to specified topic/page/style
00429    If newtopic/newpage/newstyle is equal to 0, a copy will be created
00430    in old container.
00431 */
00432 MGD_API int mgd_copy_article(midgard * mgd, int id, int newtopic);
00433 MGD_API int mgd_copy_page_element(midgard * mgd, int id, int newpage);
00434 MGD_API int mgd_copy_element(midgard * mgd, int id, int newstyle);
00435 MGD_API int mgd_copy_snippet(midgard * mgd, int id, int newsnippetdir);
00436 
00437 /* Deletes page sub-tree with included page elements */
00438 MGD_API int mgd_delete_page(midgard * mgd, int root);
00439 
00440 /* Copies style sub-tree with included elements and return ID of copy 
00441    of style
00442 */
00443 MGD_API int mgd_copy_style(midgard * mgd, int root);
00444 
00445 /* Deletes style sub-tree with included elements */
00446 MGD_API int mgd_delete_style(midgard * mgd, int root);
00447 
00448 /* Copies snippetdir sub-tree with included snippets and return ID of copy 
00449    of snippetdir
00450 */
00451 MGD_API int mgd_copy_snippetdir(midgard * mgd, int root);
00452 
00453 /* Deletes snippetdir sub-tree with included snippets */
00454 MGD_API int mgd_delete_snippetdir(midgard * mgd, int root);
00455 
00456 #define MIDGARD_PATH_ELEMENT_NOTEXISTS          0
00457 #define MIDGARD_PATH_ELEMENT_EXISTS             1
00458 #define MIDGARD_PATH_OBJECT_NOTEXISTS           2
00459 #define MIDGARD_PATH_OBJECT_EXISTS              3
00460 typedef int (*midgard_pathfunc) (midgard * mgd, const char *table,
00461                                  const char *name, int up, int id, int flag);
00462 
00463 /* Parses a path and returns IDs of requested object and its uplink in 'id' and 'up'. Returns 0 on success */
00464 MGD_API int mgd_parse_path(midgard * mgd, const char *path, const char *uptable,
00465                           const char *table, const char *upfield,
00466                           const char *namefield, int *id, int *up);
00467 /* The same but hook is called whenever path element is queried. 'flag' will be set to one of predefined state */
00468 /* (id is undefined in such case) but parsing will continue if hook returns !0 */
00469 MGD_API int mgd_parse_path_with_hook(midgard * mgd, const char *path,
00470                                     const char *uptable, const char *table,
00471                                     const char *upfield, const char *namefield,
00472                                     int *id, int *up, midgard_pathfunc hook);
00473 /* Several predefined macroses to parse common cases: */
00474 /* 1. Parse standard 'id'-'up'-'name' tables */
00475 #define MGD_PARSE_COMMON_PATH(mgd, path, uptable, table, id, up)\
00476     mgd_parse_path(mgd, path, uptable, table, "up", "name", id, up)
00477 /* 2. Parse articles by 'name' field */
00478 #define MGD_PARSE_ARTICLE_PATH(mgd, path, id, up)\
00479     mgd_parse_path(mgd, path, "topic", "article", "topic", "name", id, up)
00480 /* 3. Parse articles by 'title' field */
00481 #define MGD_PARSE_ARTICLE_PATH_BY_TITLE(mgd, path, id, up)\
00482     mgd_parse_path(mgd, path, "topic", "article", "topic", "title", id, up)
00483 /* 4. Parse topics only */
00484 #define MGD_PARSE_TOPIC_PATH(mgd, path, up)\
00485     mgd_parse_path(mgd, path, "topic", NULL, NULL, NULL, NULL, up)
00486 
00487 /* functions exported from tree.c */
00488 
00489 int mgd_delete_all_attachments(midgard * mgd, int id, const char * table);
00490 int mgd_delete_article(midgard * mgd, int root);
00491 int mgd_delete_topic(midgard * mgd, int root);
00492 int mgd_delete_page(midgard * mgd, int root);
00493 int mgd_delete_snippetdir(midgard * mgd, int root);
00494 int mgd_delete_event(midgard * mgd, int root);
00495 int mgd_delete_page_element(midgard * mgd, int id);
00496 int mgd_delete_element(midgard * mgd, int id);
00497 int mgd_delete_style(midgard * mgd, int root);
00498 int mgd_has_dependants(midgard * mgd, int id, char * table);
00499 int mgd_copy_article(midgard * mgd, int root, int newtopic);
00500 int mgd_copy_page_element(midgard * mgd, int id, int newpage);
00501 int mgd_copy_element(midgard * mgd, int id, int newstyle);
00502 int mgd_copy_snippet(midgard * mgd, int id, int newsnippetdir);
00503 int mgd_copy_topic(midgard * mgd, int root);
00504 int mgd_copy_event(midgard * mgd, int root);
00505 int mgd_copy_page(midgard * mgd, int root);
00506 int mgd_copy_style(midgard * mgd, int root);
00507 int mgd_copy_snippetdir(midgard * mgd, int root);
00508 int mgd_copy_object(midgard * mgd, midgard_res * object, const char *table,
00509                     const char *upfield, int new_up);
00510 int mgd_copy_object_article(midgard * mgd, midgard_res * object,
00511                     int new_topic, int new_up);
00512 
00513 /* access.c */
00514 MGD_API int mgd_istopicreader(midgard *mgd, int topic);
00515 MGD_API int mgd_isarticlereader(midgard *mgd, int article);
00516 MGD_API int mgd_istopicowner(midgard *mgd, int topic);
00517 MGD_API int mgd_issnippetdirowner(midgard *mgd, int snippetdir);
00518 MGD_API int mgd_isgroupowner(midgard *mgd, int gid);
00519 MGD_API int mgd_isgroupreader(midgard *mgd, int gid);
00520 MGD_API int mgd_isuserowner(midgard *mgd, int uid);
00521 #if HAVE_MIDGARD_PAGELINKS
00522 MGD_API int mgd_ispagelinkowner(midgard *mgd, int pagelink);
00523 #endif
00524 MGD_API int mgd_isarticleowner(midgard *mgd, int article);
00525 MGD_API int mgd_isarticlelocker(midgard *mgd, int article);
00526 MGD_API int mgd_iseventowner(midgard *mgd, int event);
00527 MGD_API int mgd_ishostowner(midgard *mgd, int host);
00528 MGD_API int mgd_ispageowner(midgard *mgd, int page);
00529 #if HAVE_MIDGARD_MULTILANG
00530 /* i18n */
00531 MGD_API int mgd_ispagecontentowner(midgard *mgd, int page, int lang);
00532 #endif /* HAVE_MIDGARD_MULTILANG */
00533 MGD_API int mgd_isstyleowner(midgard *mgd, int style);
00534 
00535 #if HAVE_MIDGARD_MULTILANG
00536 
00537 MGD_API int mgd_global_is_owner_ex_lang(midgard *mgd, int table, int id, int dbg, int content, int lang);
00538 MGD_API int mgd_global_is_owner_lang(midgard *mgd, int table, int id, int content, int lang);
00539 #endif /* HAVE_MIDGARD_MULTILANG */
00540 MGD_API int mgd_global_is_owner_ex(midgard *mgd, int table, int id, int dbg);
00541 #if ! HAVE_MIDGARD_MULTILANG
00542 #define mgd_global_is_owner(mgd, table, id) mgd_global_is_owner_ex(mgd, table, id, 0) 
00543 #else /* HAVE_MIDGARD_MULTILANG */
00544 MGD_API int mgd_global_is_owner(midgard *mgd, int table, int id);
00545 #endif /* HAVE_MIDGARD_MULTILANG */
00546 
00547 MGD_API int mgd_lookup_table_id(const char *table);
00548 
00549 MGD_API int midgard_lib_compiled_with_sitegroups();
00550 
00551 #if MIDGARD_PHP_REQUEST_CONFIG_BUG_WORKAROUND
00552 void mgd_php_bug_workaround_set_rcfg_dcfg(void *rcfg, void *dcfg);
00553 void* mgd_php_bug_workaround_get_rcfg();
00554 void* mgd_php_bug_workaround_get_dcfg();
00555 #endif
00556 
00557 /* NTLMSSP support. It actually works with hooks provided by upper layers in calls to
00558  * midgard_ntlm_process_auth() and contains no code that requires external dependencies
00559  * other than libc.
00560  */
00561 #define NTLM_MAX_BUF_SIZE 2048
00562 
00563 typedef enum {
00564         MGD_NTLM_INITIATE = 0,
00565         MGD_NTLM_WAIT_NEGOTIATE,
00566         MGD_NTLM_AUTHORIZED,
00567         MGD_NTLM_UNAUTHORIZED,
00568         MGD_NTLM_START,
00569         MGD_NTLM_REFRESH_AUTH
00570 } midgard_ntlm_auth_state;
00571 
00572 void midgard_ntlm_set_pipes(FILE *pipe_in, FILE *pipe_out);
00573 
00574 midgard_ntlm_auth_state midgard_ntlm_process_auth(midgard *mgd, midgard_ntlm_auth_state auth_state, 
00575                   /* Hook for helper to get client reponses */
00576                   const char * (*get_info)(void *data),
00577                   /* Hook for helper to set our responses */
00578                   void(*set_info)(const char *info, void *data),
00579                   /* Hook for identifying policy and returning logon string for mgd_auth */
00580                   /* Returned values: authline -- logon string, (result) - [0 - forbid], [1 - normal], [2 - setuid] */
00581                   /* Will be called just before finishing authentication process */
00582                   int(*define_policy)(midgard *mgd, void *data, const char *username, const char *domain, const char **authline),
00583                   void *data);
00584 
00585 void mgd_set_authtype(midgard *mgd, midgard_auth_type authtype);
00586 
00587 MGD_API void mgdlib_init();
00588 MGD_API midgard *midgard_config_init(gchar *fname);
00589 
00590 /* Start MQL functions */
00591 
00592 /* Select data from data storage which allow create single type */
00593 MGD_API midgard_res *mgdlib_mql_select_type(midgard * mgd, const gchar *table,
00594         const char *select, const char *from, const char *where);
00595 
00596 MGD_API gpointer midgard_query_field_get(midgard *mgd, const gchar *field,
00597         const gchar *from, const gchar *where);
00598 
00599 /* End MQL */
00600 
00601 /* Temporary, delete after 1.8 */
00602 char * mgd_check_quota(midgard * mgd, const char *table);
00603 
00604 #define midgard_lang_get(m) \
00605     m->lang
00606 
00607 #define midgard_lang_set(m,i) \
00608     m->lang = i
00609 
00610 /* Get sitegroup's id 
00611  *
00612  * @param mgd Midgard structure
00613  *
00614  * @return integer which identifies sitegroup
00615  */ 
00616 MGD_API guint midgard_sitegroup_get_id(midgard * mgd);
00617 
00618 /* Free midgard structure 
00619  *
00620  * This function should be called only when application is closed.
00621  * All midgard structure members are freed.
00622  *
00623  * @param mgd midgard structure
00624  */
00625 MGD_API void midgard_shutdown(midgard *mgd);
00626 
00627 #endif /* MIDGARD_LEGACY_H */
00628 

Generated on Thu Feb 22 06:15:14 2007 for midgard-core by  doxygen 1.4.6