Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.91
diff -u -r1.91 pbx.c
--- pbx.c	1 Dec 2003 02:47:19 -0000	1.91
+++ pbx.c	22 Apr 2004 14:41:34 -0000
@@ -4710,3 +4710,61 @@
 		}
 	return res;
 }
+
+/*
+ * ast-ax-snmpd
+ */
+
+int pbx_apps_num()
+{
+	struct ast_app *a;
+	int ret = 0;
+
+	/* try to lock applications list ... */
+	if (ast_mutex_lock(&applock)) {
+		ast_log(LOG_ERROR, "Unable to lock application list\n");
+		return 0;
+	}
+
+	/* ... go to first application ... */
+	a = apps; 
+
+	/* ... have we got at least one application (first)? no? */
+	if (!a) {
+		ast_mutex_unlock(&applock);
+		return 0;
+	}
+
+	/* ... go through all applications ... */
+	while (a) {
+		a = a->next; 
+		ret++;
+	}
+
+	/* ... unlock and return */
+	ast_mutex_unlock(&applock);
+
+	return ret;
+
+}
+
+struct ast_app *pbx_ax_get_app(int idx) 
+{
+	struct ast_app *tmp;
+	int i;
+
+	/* try to lock applications list ... */
+	if (ast_mutex_lock(&applock)) {
+		ast_log(LOG_ERROR, "Unable to lock application list\n");
+		return NULL;
+	}
+
+	tmp = apps;
+	i = 0;
+	while(tmp && (i<idx)) {
+		tmp = tmp->next;
+		i++;
+	}
+	ast_mutex_unlock(&applock);
+	return tmp;
+}
Index: channels/chan_zap.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v
retrieving revision 1.154
diff -u -r1.154 chan_zap.c
--- channels/chan_zap.c	11 Dec 2003 20:55:26 -0000	1.154
+++ channels/chan_zap.c	22 Apr 2004 14:41:37 -0000
@@ -57,6 +57,8 @@
 
 #include "../asterisk.h"
 
+void init_astChZap(void);
+
 /* 
    XXX 
    XXX   We definitely need to lock the private structure in zt_read and such 
@@ -7388,6 +7390,7 @@
 	ast_manager_register( "ZapHangup", 0, action_transferhangup, "Hangup Zap Channel" );
 	ast_manager_register( "ZapDialOffhook", 0, action_zapdialoffhook, "Dial over Zap channel while offhook" );
 
+  init_astChZap();
 	return res;
 }
 
@@ -7812,3 +7815,385 @@
 {
 	return ASTERISK_GPL_KEY;
 }
+
+
+/* This file was generated by mib2c and is intended for use as a mib module
+   for the ucd-snmp snmpd agent. */
+
+
+#include <ucd-snmp/ucd-snmp-config.h>
+#include <ucd-snmp/ucd-snmp-includes.h>
+#include <ucd-snmp/ucd-snmp-agent-includes.h>
+#include <ucd-snmp/util_funcs.h>
+
+
+#include "../../ast-ax-snmpd.0.3/astChZap.h"
+
+
+#define TABLE_SIZE 2
+/* 
+ * astChZap_variables_oid:
+ *   this is the top level oid that we want to register under.  This
+ *   is essentially a prefix, with the suffix appearing in the
+ *   variable below.
+ */
+
+
+oid astChZap_variables_oid[] = { 1,3,6,1,4,1,18816,1,5 };
+
+
+/* 
+ * variable4 astChZap_variables:
+ *   this variable defines function callbacks and type return information 
+ *   for the astChZap mib section 
+ */
+
+
+struct variable4 astChZap_variables[] = {
+/*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */
+#define   ASTCHZAPNUMBER        1
+  { ASTCHZAPNUMBER      , ASN_COUNTER   , RONLY , var_astChZap, 1, { 1 } },
+#define   ASTCHZAPINDEX         4
+  { ASTCHZAPINDEX       , ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,1 } },
+#define   ASTCHZAPFD            5
+  { ASTCHZAPFD          , ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,2 } },
+#define   ASTCHZAPSPAN          6
+  { ASTCHZAPSPAN        , ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,3 } },
+#define   ASTCHZAPEXTENSION     7
+  { ASTCHZAPEXTENSION   , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,4 } },
+#define   ASTCHZAPCONTEXT       8
+  { ASTCHZAPCONTEXT     , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,5 } },
+#define   ASTCHZAPCID           9
+  { ASTCHZAPCID         , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,6 } },
+#define   ASTCHZAPDESTROY       10
+  { ASTCHZAPDESTROY     , ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,7 } },
+#define   ASTCHZAPSIGNALLINGTYPE  11
+  { ASTCHZAPSIGNALLINGTYPE, ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,8 } },
+#define   ASTCHZAPOWNER         12
+  { ASTCHZAPOWNER       , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,9 } },
+#define   ASTCHZAPREAL          13
+  { ASTCHZAPREAL        , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,10 } },
+#define   ASTCHZAPCALLWAIT      14
+  { ASTCHZAPCALLWAIT    , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,11 } },
+#define   ASTCHZAPTHREEWAY      15
+  { ASTCHZAPTHREEWAY    , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,12 } },
+#define   ASTCHZAPCONFNO        16
+  { ASTCHZAPCONFNO      , ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,13 } },
+#define   ASTCHZAPPROPAGATEDCONFERENCE  17
+  { ASTCHZAPPROPAGATEDCONFERENCE, ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,14 } },
+#define   ASTCHZAPREALINCONFERENCE  18
+  { ASTCHZAPREALINCONFERENCE, ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,15 } },
+#define   ASTCHZAPDSP           19
+  { ASTCHZAPDSP         , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,16 } },
+#define   ASTCHZAPRELAXDTMF     20
+  { ASTCHZAPRELAXDTMF   , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,17 } },
+#define   ASTCHZAPDIALING       21
+  { ASTCHZAPDIALING     , ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,18 } },
+#define   ASTCHZAPCALLWAITCAS   22
+  { ASTCHZAPCALLWAITCAS , ASN_INTEGER   , RONLY , var_astchzapTable, 3, { 2,1,19 } },
+#define   ASTCHZAPDEFAULTLAW    23
+  { ASTCHZAPDEFAULTLAW  , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,20 } },
+#define   ASTCHZAPFAXHANDLED    24
+  { ASTCHZAPFAXHANDLED  , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,21 } },
+#define   ASTCHZAPPULSEPHONE    25
+  { ASTCHZAPPULSEPHONE  , ASN_OCTET_STR , RONLY , var_astchzapTable, 3, { 2,1,22 } },
+};
+/*    (L = length of the oidsuffix) */
+
+
+/*
+ * init_astChZap():
+ *   Initialization routine.  This is called when the agent starts up.
+ *   At a minimum, registration of your variables should take place here.
+ */
+void init_astChZap(void) {
+
+
+  /* register ourselves with the agent to handle our mib tree */
+  register_mib("astChZap", (struct variable *)astChZap_variables,
+		(size_t)sizeof(struct variable4),
+		(size_t)sizeof(astChZap_variables) / sizeof(struct variable4),
+               astChZap_variables_oid,
+							 sizeof(astChZap_variables_oid)/sizeof(oid));
+
+
+  /* place any other initialization junk you need here */
+}
+
+
+static int ast_ax_zap_chan_num(void)
+{
+	struct zt_pvt *tmp = NULL;
+	int i;
+
+	ast_mutex_lock(&iflock);
+	
+	i = 0;
+	tmp = iflist;
+	while (tmp) {
+		tmp = tmp->next;
+		i++;
+	}
+	ast_mutex_unlock(&iflock);
+	return (i);
+}
+
+/*
+ * var_astChZap():
+ *   This function is called every time the agent gets a request for
+ *   a scalar variable that might be found within your mib section
+ *   registered above.  It is up to you to do the right thing and
+ *   return the correct value.
+ *     You should also correct the value of "var_len" if necessary.
+ *
+ *   Please see the documentation for more information about writing
+ *   module extensions, and check out the examples in the examples
+ *   and mibII directories.
+ */
+unsigned char *
+var_astChZap(struct variable *vp, 
+                oid     *name, 
+                size_t  *length, 
+                int     exact, 
+                size_t  *var_len, 
+                WriteMethod **write_method)
+{
+
+
+  /* variables we may use later */
+  static long long_ret;
+
+
+  if (header_generic(vp,name,length,exact,var_len,write_method)
+                                  == MATCH_FAILED )
+    return NULL;
+
+
+  /* 
+   * this is where we do the value assignments for the mib results.
+   */
+  switch(vp->magic) {
+
+
+    case ASTCHZAPNUMBER:
+        
+        long_ret = ast_ax_zap_chan_num();
+        return (unsigned char *) &long_ret;
+
+
+    default:
+      ERROR_MSG("");
+  }
+  return NULL;
+}
+
+static struct zt_pvt *ast_ax_get_zap_chan(int i)
+{
+	struct zt_pvt *tmp = NULL;
+	static struct zt_pvt buf;
+	int flag = 0;
+
+	ast_mutex_lock(&iflock);
+	tmp = iflist;
+	while (tmp) {
+		if (tmp->channel == i) {
+		flag = 1;
+		memcpy((void *)&buf, (const void *)tmp, sizeof(struct zt_pvt));
+		}
+	tmp = tmp->next;
+	}
+	
+	ast_mutex_unlock(&iflock);
+
+	if (flag)
+		return(&buf);
+  else
+		return NULL;
+}
+
+/*
+ * var_astchzapTable():
+ *   Handle this table separately from the scalar value case.
+ *   The workings of this are basically the same as for var_astChZap above.
+ */
+unsigned char *
+var_astchzapTable(struct variable *vp,
+    	    oid     *name,
+    	    size_t  *length,
+    	    int     exact,
+    	    size_t  *var_len,
+    	    WriteMethod **write_method)
+{
+
+
+  /* variables we may use later */
+  static long long_ret;
+  static unsigned char string[SPRINT_MAX_LEN];
+	struct zt_pvt *tmp = NULL;
+
+  /* 
+   * This assumes that the table is a 'simple' table.
+   *	See the implementation documentation for the meaning of this.
+   *	You will need to provide the correct value for the TABLE_SIZE parameter
+   *
+   * If this table does not meet the requirements for a simple table,
+   *	you will need to provide the replacement code yourself.
+   *	Mib2c is not smart enough to write this for you.
+   *    Again, see the implementation documentation for what is required.
+   */
+  if (header_simple_table(vp,name,length,exact,var_len,write_method, ast_ax_zap_chan_num())
+                                                == MATCH_FAILED )
+    return NULL;
+
+  tmp = ast_ax_get_zap_chan(name[*length-1]);
+
+	if (!tmp) return NULL;
+
+  /* 
+   * this is where we do the value assignments for the mib results.
+   */
+  switch(vp->magic) {
+
+
+    case ASTCHZAPINDEX:
+        
+        long_ret = name[*length-1];
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPFD:
+        
+        long_ret = tmp->subs[SUB_REAL].zfd;
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPSPAN:
+        
+        long_ret = tmp->span;
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPEXTENSION:
+        
+				strcpy(string, tmp->exten);
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPCONTEXT:
+        
+				strcpy(string, tmp->context);
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPCID:
+        
+				strcpy(string, tmp->callerid);
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPDESTROY:
+        
+        long_ret = tmp->destroy;
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPSIGNALLINGTYPE:
+        
+				strcpy(string, sig2str(tmp->sig));
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPOWNER:
+        
+				strcpy(string, tmp->owner ? tmp->owner->name : "<None>");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPREAL:
+        
+				sprintf(string, "%s%s%s", tmp->subs[SUB_REAL].owner ? tmp->subs[SUB_REAL].owner->name : "<None>",
+				tmp->subs[SUB_REAL].inthreeway ? " (Confed)" : "",
+				tmp->subs[SUB_REAL].linear ? " (Linear)" : "");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPCALLWAIT:
+        
+				sprintf(string, "%s%s%s",
+				tmp->subs[SUB_CALLWAIT].owner ? tmp->subs[SUB_CALLWAIT].owner->name : "<None>",
+				tmp->subs[SUB_CALLWAIT].inthreeway ? " (Confed)" : "",
+				tmp->subs[SUB_CALLWAIT].linear ? " (Linear)" : "");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPTHREEWAY:
+        
+        sprintf(string, "%s%s%s", 
+				tmp->subs[SUB_THREEWAY].owner ? tmp->subs[SUB_THREEWAY].owner->name : "<None>",
+				tmp->subs[SUB_THREEWAY].inthreeway ? " (Confed)" : "",
+				tmp->subs[SUB_THREEWAY].linear ? " (Linear)" : "");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPCONFNO:
+        
+        long_ret = tmp->confno;
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPPROPAGATEDCONFERENCE:
+        
+        long_ret = tmp->propconfno;
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPREALINCONFERENCE:
+        
+        long_ret = tmp->inconference;
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPDSP:
+        
+        strcpy(string, tmp->dsp ? "yes" : "no");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPRELAXDTMF:
+        
+        strcpy(string, tmp->dtmfrelax ? "yes" : "no");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPDIALING:
+        
+        long_ret = tmp->dialing;
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPCALLWAITCAS:
+        
+        long_ret = tmp->callwaitcas;
+        return (unsigned char *) &long_ret;
+
+    case ASTCHZAPDEFAULTLAW:
+        
+        strcpy(string, tmp->law == ZT_LAW_MULAW ? "ulaw" : tmp->law == ZT_LAW_ALAW ? "alaw" : "unknown");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPFAXHANDLED:
+        
+        strcpy(string, tmp->faxhandled ? "yes" : "no");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    case ASTCHZAPPULSEPHONE:
+        
+        strcpy(string, tmp->pulsedial ? "yes" : "no");
+        *var_len = strlen(string);
+        return (unsigned char *) string;
+
+    default:
+      ERROR_MSG("");
+  }
+  return NULL;
+}
+
+
+
+
+
+
Index: include/asterisk/pbx.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/pbx.h,v
retrieving revision 1.23
diff -u -r1.23 pbx.h
--- include/asterisk/pbx.h	25 Oct 2003 17:50:06 -0000	1.23
+++ include/asterisk/pbx.h	22 Apr 2004 14:41:37 -0000
@@ -533,6 +533,9 @@
 
 int ast_extension_patmatch(const char *pattern, const char *data);
 
+extern int pbx_apps_num(void);
+extern struct ast_app *pbx_ax_get_app(int idx);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

