Updated footer comment
[yazproxy-moved-to-github.git] / src / mod_sample.cpp
index 05b121b..eebdf32 100644 (file)
@@ -1,7 +1,5 @@
-/* $Id: mod_sample.cpp,v 1.1 2005-02-11 15:19:08 adam Exp $
-   Copyright (c) 1998-2005, Index Data.
-
-This file is part of the yaz-proxy.
+/* This file is part of YAZ proxy
+   Copyright (C) 1998-2009 Index Data
 
 YAZ proxy 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
@@ -14,16 +12,24 @@ 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 YAZ proxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
 
 #include <string.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #include <yazproxy/module.h>
 
+#if YAZ_HAVE_XSLT
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xinclude.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/transform.h>
+#endif
+
 void *my_init(void)
 {
     return 0;  // no private data for handler
@@ -34,17 +40,40 @@ void my_destroy(void *p)
     // private data destroy
 }
 
-int my_authenticate(void *p, const char *user, const char *group,
-                   const char *password)
+int my_authenticate(void *user_handle,
+                    const char *target_name,
+                    void *element_ptr,
+                    const char *user, const char *group, const char *password,
+                    const char *peer_IP)
 {
-    fprintf(stderr, "my_authenticate: user=%s group=%s\n",
-           user ? user : "none", group ? group : "none");
+    // see if we have an "args" attribute
+    const char *args = 0;
+#if YAZ_HAVE_XSLT
+    xmlNodePtr ptr = (xmlNodePtr) element_ptr;
+    struct _xmlAttr *attr;
+    
+    for (attr = ptr->properties; attr; attr = attr->next)
+    {
+        if (!strcmp((const char *) attr->name, "args") &&
+            attr->children && attr->children->type == XML_TEXT_NODE)
+            args = (const char *) attr->children->content;
+    }
+#endif
+    // args holds args (or NULL if  none is provided)
+
+    sleep(2);
+    fprintf(stderr, "my_authenticate: target=%s user=%s group=%s args=%s IP=%s"
+            "\n",
+            target_name ? target_name : "none", 
+            user ? user : "none", group ? group : "none",
+            args ? args : "none",
+            peer_IP);
     // authentication handler
     if (!user && !group && !password)
-       return YAZPROXY_RET_OK;   // OK if anonymous
+        return YAZPROXY_RET_OK;   // OK if anonymous
     if (user && !strcmp(user, "guest")
-       && password && !strcmp(password, "guest"))  // or guest guest
-       return YAZPROXY_RET_OK;
+        && password && !strcmp(password, "guest"))  // or guest guest
+        return YAZPROXY_RET_OK;
     return YAZPROXY_RET_PERM;  // fail otherwise
 }
 
@@ -60,4 +89,12 @@ Yaz_ProxyModule_entry yazproxy_module = {
     "Sample Module for YAZ Proxy",// description
     &interface0
 };
-       
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+