Revision: 1882
          
http://undernet-ircu.svn.sourceforge.net/undernet-ircu/?rev=1882&view=rev
Author:   klmitch
Date:     2008-09-27 04:01:12 +0000 (Sat, 27 Sep 2008)

Log Message:
-----------
Author: Kev <[EMAIL PROTECTED]>
Description:

1) Do a little minor revamping on register subsystem to enable us to
specify the table to search.  This will allow the mode subsystem to
store modelist_t's in a mode table, then store modedesc_t's in the
modelist_t table.

2) Add a flag to mark one-shot modes like +k, so we don't have to
add special processing code to handle them.

3) Add a mask and a field for run-time computation of the ISUPPORT
PREFIX token.  The mask specifies a priority, since PREFIX is
ordering dependent, while the field specifies the indicator
character to use.

Modified Paths:
--------------
    ircu2/branches/mode/ChangeLog
    ircu2/branches/mode/include/mode.h
    ircu2/branches/mode/include/register.h
    ircu2/branches/mode/ircd/register.c

Modified: ircu2/branches/mode/ChangeLog
===================================================================
--- ircu2/branches/mode/ChangeLog       2008-09-26 04:15:18 UTC (rev 1881)
+++ ircu2/branches/mode/ChangeLog       2008-09-27 04:01:12 UTC (rev 1882)
@@ -1,5 +1,17 @@
 2008-09-26  Kevin L. Mitchell  <[EMAIL PROTECTED]>
 
+       * include/mode.h: add a flag to mark one-shot modes like +k; add
+       mask for storing priorities for prefix string calculations; add
+       prefix indicator to struct ModeDesc
+
+       * include/register.h: add {un,}regtab* functions that take
+       pointers to regtab_t instead of table names (for use by new mode
+       infrastructure)
+
+       * ircd/register.c: stylistic clean-ups; add {un,}regtab* functions
+       that take pointers to regtab_t instead of table names (for use by
+       new mode infrastructure)
+
        * include/ancillary.h: correct a minor typo in ancdata_init();
        this eventually needs to be updated to utilize the new keyspace
        routines

Modified: ircu2/branches/mode/include/mode.h
===================================================================
--- ircu2/branches/mode/include/mode.h  2008-09-26 04:15:18 UTC (rev 1881)
+++ ircu2/branches/mode/include/mode.h  2008-09-27 04:01:12 UTC (rev 1882)
@@ -58,6 +58,7 @@
 struct ModeDesc {
   regent_t             md_regent;      /**< Registration entry. */
   int                  md_switch;      /**< Mode switch (character). */
+  int                  md_prefix;      /**< Indicator prefix for mode. */
   mode_t               md_mode;        /**< Numerical value of mode. */
   const char*          md_desc;        /**< Textual description of mode. */
   flagpage_t           md_flags;       /**< Flags affecting mode. */
@@ -69,7 +70,12 @@
 #define MDFLAG_LOCAL           0x40000000
 /** Accept octal or hexadecimal integers, not just decimal. */
 #define MDFLAG_HEXINT          0x20000000
+/** Mode can only be set or reset once per message. */
+#define MDFLAG_ONESHOT         0x10000000
 
+/** Mask for prefix ordering priority. */
+#define MDFLAG_PRIO            0x000f0000
+
 /** Mode is visible to anyone. */
 #define MDFLAG_VIS_OPEN                0x00000000
 /** Mode is visible only to channel operators. */

Modified: ircu2/branches/mode/include/register.h
===================================================================
--- ircu2/branches/mode/include/register.h      2008-09-26 04:15:18 UTC (rev 
1881)
+++ ircu2/branches/mode/include/register.h      2008-09-27 04:01:12 UTC (rev 
1882)
@@ -126,4 +126,17 @@
 /* iterate over entries in the table */
 extern int reg_iter(const char* table, regiter_t func, void* extra);
 
+/* register an entry in a specified table */
+extern int regtab(regtab_t *tab, void* entry);
+/* register an array of entries in a specified table */
+extern int regtab_n(regtab_t *tab, void* ent_array, int n, size_t size);
+/* unregister an entry from a specified table */
+extern int unregtab(regtab_t *tab, void* entry);
+/* unregister an array of entries from a specified table */
+extern int unregtab_n(regtab_t *tab, void* ent_array, int n, size_t size);
+/* look up an entry in the specified table */
+extern void* regtab_find(regtab_t *tab, const char* id);
+/* iterate over entries in the specified table */
+extern int regtab_iter(regtab_t *tab, regiter_t func, void* extra);
+
 #endif /* INCLUDED_register_h */

Modified: ircu2/branches/mode/ircd/register.c
===================================================================
--- ircu2/branches/mode/ircd/register.c 2008-09-26 04:15:18 UTC (rev 1881)
+++ ircu2/branches/mode/ircd/register.c 2008-09-27 04:01:12 UTC (rev 1882)
@@ -169,9 +169,11 @@
 /** Search a table for a named entry.
  * @param[in] table Table to search.
  * @param[in] id Identifier of the entry to look up.
- * @return Pointer to the identified entry, or NULL if there isn't one.
+ * @return Pointer to the identified entry, or NULL if there isn't
+ * one.
  */
-static regent_t* _reg_find(regtab_t* table, const char* id)
+static regent_t*
+_reg_find(regtab_t* table, const char* id)
 {
   regent_t *cursor, *tmp;
 
@@ -211,7 +213,8 @@
  * @param[in] table Table to add the entry to.
  * @param[in] entry Entry to add.
  */
-static void reg_add(regtab_t* table, regent_t* entry)
+static void
+reg_add(regtab_t* table, regent_t* entry)
 {
   assert(0 != table);
   assert(0 != entry);
@@ -232,7 +235,8 @@
  * @param[in] table Table to remove entry from.
  * @param[in] entry Entry to remove.
  */
-static void reg_rem(regtab_t* table, regent_t* entry)
+static void
+reg_rem(regtab_t* table, regent_t* entry)
 {
   assert(0 != table);
   assert(0 != entry);
@@ -256,7 +260,8 @@
  * @param[in] entry Table being unregistered.
  * @return 0 to accept the unregistration.
  */
-static int reg_flush(regtab_t* table, regtab_t* entry)
+static int
+reg_flush(regtab_t* table, regtab_t* entry)
 {
   /* Unregister each entry in turn */
   while (entry->reg_list) {
@@ -271,23 +276,22 @@
   return 0;
 }
 
-/** Register a new entry in a table.
- * @param[in] table Name of table entry should belong to.
+/** Register a new entry in a specified table.
+ * @param[in] tab Pointer to the regtab_t entry should belong to.
  * @param[in] entry Entry to add; must begin with a regent_t.
- * @return 0 if entry was added, non-zero otherwise; -1 means no table by
- * that name; -2 means the magic numbers don't match; -3 means it already
+ * @return 0 if entry was added, non-zero otherwise; -1 means invalid
+ * table; -2 means the magic numbers don't match; -3 means it already
  * exists in the table; other values returned by table reg function.
  */
-int reg(const char* table, void* entry)
+int
+regtab(regtab_t* tab, void* entry)
 {
   int retval;
-  regtab_t *tab;
 
   reg_init(); /* initialize subsystem */
 
-  /* look up the requested table */
-  if (!(tab = (regtab_t*) _reg_find(&reg_table, table)))
-    return -1; /* no such table */
+  if (!REGTAB_CHECK(tab)) /* valid table? */
+    return -1;
 
   /* double-check the magic numbers */
   if (((regent_t*) entry)->rl_magic != tab->reg_magic)
@@ -307,18 +311,17 @@
   return 0; /* all set */
 }
 
-/** Register an array of entries in a table.
- * @param[in] table Name of table entries should belong to.
- * @param[in] ent_array Array of entries to add; each must be same size and
- * begin with a regent_t.
- * @param[in] n Number of entries in array.
- * @param[in] size Size of each entry in array.
- * @return n if all entries were added; -1 means no table by that name;
- * otherwise, the index of the first entry not added to the table.
+/** Register a new entry in a table.
+ * @param[in] table Name of table entry should belong to.
+ * @param[in] entry Entry to add; must begin with a regent_t.
+ * @return 0 if entry was added, non-zero otherwise; -1 means no table
+ * by that name; -2 means the magic numbers don't match; -3 means it
+ * already exists in the table; other values returned by table reg
+ * function.
  */
-int reg_n(const char* table, void* ent_array, int n, size_t size)
+int
+reg(const char* table, void* entry)
 {
-  int i;
   regtab_t *tab;
 
   reg_init(); /* initialize subsystem */
@@ -327,6 +330,29 @@
   if (!(tab = (regtab_t*) _reg_find(&reg_table, table)))
     return -1; /* no such table */
 
+  /* use regtab function */
+  return regtab(tab, entry);
+}
+
+/** Register an array of entries in a specified table.
+ * @param[in] tab Pointer to the regtab_t entries should belong to.
+ * @param[in] ent_array Array of entries to add; each must be same
+ * size and begin with a regent_t.
+ * @param[in] n Number of entries in array.
+ * @param[in] size Size of each entry in array.
+ * @return n if all entries were added; -1 means invalid table;
+ * otherwise, the index of the first entry not added to the table.
+ */
+int
+regtab_n(regtab_t* tab, void* ent_array, int n, size_t size)
+{
+  int i;
+
+  reg_init(); /* initialize subsystem */
+
+  if (!REGTAB_CHECK(tab)) /* valid table? */
+    return -1;
+
   /* walk through each array entry and add it */
   for (i = 0; i < n; i++) {
     /* obtain the indexed entry */
@@ -351,25 +377,49 @@
   return i; /* should be n, indicating all entries processed */
 }
 
-/** Unregister an entry from a table.
- * @param[in] table Name of table entry should be removed from.
- * @param[in] entry Entry to remove; must begin with a regent_t.
- * @return 0 if entry was removed, non-zero otherwise; -1 means no table by
- * that name; other values returned by table unreg function.
+/** Register an array of entries in a table.
+ * @param[in] table Name of table entries should belong to.
+ * @param[in] ent_array Array of entries to add; each must be same
+ * size and begin with a regent_t.
+ * @param[in] n Number of entries in array.
+ * @param[in] size Size of each entry in array.
+ * @return n if all entries were added; -1 means no table by that
+ * name; otherwise, the index of the first entry not added to the
+ * table.
  */
-int unreg(const char* table, void* entry)
+int
+reg_n(const char* table, void* ent_array, int n, size_t size)
 {
-  int retval;
   regtab_t *tab;
 
   reg_init(); /* initialize subsystem */
 
   /* look up the requested table */
   if (!(tab = (regtab_t*) _reg_find(&reg_table, table)))
-    return -1;
+    return -1; /* no such table */
 
-  assert(tab == ((regent_t*) entry)->rl_desc);
+  /* use regtab_n function */
+  return regtab_n(tab, ent_array, n, size);
+}
 
+/** Unregister an entry from a specified table.
+ * @param[in] tab Pointer to the regtab_t entry should be removed
+ * from.
+ * @param[in] entry Entry to remove; must begin with a regent_t.
+ * @return 0 if entry was removed, non-zero otherwise; -1 means
+ * invalid or wrong table; other values returned by table unreg
+ * function.
+ */
+int
+unregtab(regtab_t* tab, void* entry)
+{
+  int retval;
+
+  reg_init(); /* initialize subsystem */
+
+  if (!REGTAB_CHECK(tab) || tab != ((regent_t*) entry)->rl_desc)
+    return -1; /* invalid or incorrect table */
+
   /* perform any table-specific unregistration */
   if (tab->reg_unreg && (retval = (tab->reg_unreg)(tab, entry)))
     return retval;
@@ -380,27 +430,51 @@
   return 0; /* all set */
 }
 
-/** Unregister an array of entries from a table.
- * @param[in] table Name of table entries should be removed from.
- * @param[in] ent_array Array of entries to remove; each must be same size and
- * begin with a regent_t.
- * @param[in] n Number of entries in array.
- * @param[in] size Size of each entry in array.
- * @return n if all entries were removed; -1 means no table by that name;
- * otherwise, the index of the first entry not removed from the table.  Note
- * only table unreg function returning non-zero can halt processing.
+/** Unregister an entry from a table.
+ * @param[in] table Name of table entry should be removed from.
+ * @param[in] entry Entry to remove; must begin with a regent_t.
+ * @return 0 if entry was removed, non-zero otherwise; -1 means no
+ * table by that name; other values returned by table unreg function.
  */
-int unreg_n(const char* table, void* ent_array, int n, size_t size)
+int
+unreg(const char* table, void* entry)
 {
-  int i;
   regtab_t *tab;
 
   reg_init(); /* initialize subsystem */
 
   /* look up the requested table */
   if (!(tab = (regtab_t*) _reg_find(&reg_table, table)))
-    return -1; /* no such table */
+    return -1;
 
+  assert(tab == ((regent_t*) entry)->rl_desc);
+
+  /* use unregtab function */
+  return unregtab(tab, entry);
+}
+
+/** Unregister an array of entries from a specified table.
+ * @param[in] tab Pointer to the regtab_t entries should be removed
+ * from.
+ * @param[in] ent_array Array of entries to remove; each must be same
+ * size and begin with a regent_t.
+ * @param[in] n Number of entries in array.
+ * @param[in] size Size of each entry in array.
+ * @return n if all entries were removed; -1 means invalid or
+ * incorrect table; otherwise, the index of the first entry not
+ * removed from the table.  Note only table unreg function returning
+ * non-zero can halt processing.
+ */
+int
+unregtab_n(regtab_t* tab, void* ent_array, int n, size_t size)
+{
+  int i;
+
+  reg_init(); /* initialize subsystem */
+
+  if (!REGTAB_CHECK(tab) || tab != ((regent_t*) ent_array)->rl_desc)
+    return -1; /* invalid or incorrect table */
+
   /* walk through each array entry and add it */
   for (i = 0; i < n; i++) {
     /* obtain the indexed entry */
@@ -419,13 +493,59 @@
   return i; /* should be n, indicating all entries processed */
 }
 
+/** Unregister an array of entries from a table.
+ * @param[in] table Name of table entries should be removed from.
+ * @param[in] ent_array Array of entries to remove; each must be same
+ * size and begin with a regent_t.
+ * @param[in] n Number of entries in array.
+ * @param[in] size Size of each entry in array.
+ * @return n if all entries were removed; -1 means no table by that
+ * name; otherwise, the index of the first entry not removed from the
+ * table.  Note only table unreg function returning non-zero can halt
+ * processing.
+ */
+int
+unreg_n(const char* table, void* ent_array, int n, size_t size)
+{
+  regtab_t *tab;
 
+  reg_init(); /* initialize subsystem */
+
+  /* look up the requested table */
+  if (!(tab = (regtab_t*) _reg_find(&reg_table, table)))
+    return -1; /* no such table */
+
+  assert(tab == ((regent_t*) ent_array)->rl_desc); /* first entry */
+
+  /* use unregtab_n function */
+  return unregtab_n(tab, ent_array, n, size);
+}
+
+
+/** Find an entry in a specified table.
+ * @param[in] tab Pointer to regtab_t to search.
+ * @param[in] id Name of entry to look up.
+ * @return Pointer to entry, or NULL if not found.
+ */
+void*
+regtab_find(regtab_t* tab, const char* id)
+{
+  reg_init(); /* initialize subsystem */
+
+  if (!REGTAB_CHECK(tab)) /* valid table? */
+    return 0;
+
+  /* return the result of looking up the entry */
+  return (void*) _reg_find(tab, id);
+}
+
 /** Find an entry in a table.
  * @param[in] table Name of table to search.
  * @param[in] id Name of entry to look up.
  * @return Pointer to entry, or NULL if not found.
  */
-void* reg_find(const char* table, const char* id)
+void*
+reg_find(const char* table, const char* id)
 {
   regtab_t *tab;
 
@@ -439,25 +559,24 @@
   return (void*) _reg_find(tab, id);
 }
 
-/** Iterate over all entries in a table.
- * @param[in] table Name of table to walk.
+/** Iterate over all entries in a specified table.
+ * @param[in] tab Pointer to regtab_t to walk.
  * @param[in] func Iteration function to execute.
  * @param[in] extra Extra data to pass to iteration function.
- * @return -1 if table doesn't exist; otherwise, 0 or whatever
- * non-zero value \a func returns.
+ * @return -1 if table is invalid; otherwise, 0 or whatever non-zero
+ * value \a func returns.
  */
-int reg_iter(const char* table, regiter_t func, void* extra)
+int
+regtab_iter(regtab_t* tab, regiter_t func, void* extra)
 {
   int retval;
-  regtab_t *tab;
   regent_t *cursor;
 
   assert(0 != func);
 
   reg_init(); /* initialize subsystem */
 
-  /* look up the requested table */
-  if (!(tab = (regtab_t*) _reg_find(&reg_table, table)))
+  if (!REGTAB_CHECK(tab)) /* valid table? */
     return -1;
 
   /* walk the linked list */
@@ -467,3 +586,27 @@
 
   return 0; /* all done */
 }
+
+/** Iterate over all entries in a table.
+ * @param[in] table Name of table to walk.
+ * @param[in] func Iteration function to execute.
+ * @param[in] extra Extra data to pass to iteration function.
+ * @return -1 if table doesn't exist; otherwise, 0 or whatever
+ * non-zero value \a func returns.
+ */
+int
+reg_iter(const char* table, regiter_t func, void* extra)
+{
+  regtab_t *tab;
+
+  assert(0 != func);
+
+  reg_init(); /* initialize subsystem */
+
+  /* look up the requested table */
+  if (!(tab = (regtab_t*) _reg_find(&reg_table, table)))
+    return -1;
+
+  /* use regtab_iter function */
+  return regtab_iter(tab, func, extra);
+}


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to