+const char *Yaz_ProxyConfig::check_mime_type(const char *path)
+{
+ struct {
+ const char *mask;
+ const char *type;
+ } types[] = {
+ {".xml", "text/xml"},
+ {".xsl", "text/xml"},
+ {".tkl", "text/xml"},
+ {".xsd", "text/xml"},
+ {".html", "text/html"},
+ {".jpg", "image/jpeg"},
+ {".png", "image/png"},
+ {".gif", "image/gif"},
+ {".css", "text/css"},
+ {".pdf", "application/pdf"},
+ {0, "text/plain"},
+ {0, 0},
+ };
+ int i;
+ size_t plen = strlen (path);
+ for (i = 0; types[i].type; i++)
+ if (types[i].mask == 0)
+ return types[i].type;
+ else
+ {
+ size_t mlen = strlen(types[i].mask);
+ if (plen > mlen && !memcmp(path+plen-mlen, types[i].mask, mlen))
+ return types[i].type;
+ }
+ return "application/octet-stream";
+}
+
+
+void Yaz_ProxyConfig::target_authentication(const char *name,
+ ODR odr, Z_InitRequest *req)
+{
+#if YAZ_HAVE_XSLT
+ xmlNodePtr ptr = m_cp->find_target_node(name);
+ if (!ptr)
+ return ;
+
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ if (ptr->type == XML_ELEMENT_NODE &&
+ !strcmp((const char *) ptr->name, "target-authentication"))
+ {
+ struct _xmlAttr *attr;
+ const char *type = "open";
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "type") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ type = (const char *) attr->children->content;
+ }
+ const char *t = m_cp->get_text(ptr);
+ if (!t || !strcmp(type, "none"))
+ {
+ req->idAuthentication = 0;
+ }
+ else if (!strcmp(type, "anonymous"))
+ {
+ req->idAuthentication =
+ (Z_IdAuthentication *)
+ odr_malloc (odr, sizeof(*req->idAuthentication));
+ req->idAuthentication->which =
+ Z_IdAuthentication_anonymous;
+ req->idAuthentication->u.anonymous = odr_nullval();
+ }
+ else if (!strcmp(type, "open"))
+ {
+ req->idAuthentication =
+ (Z_IdAuthentication *)
+ odr_malloc (odr, sizeof(*req->idAuthentication));
+ req->idAuthentication->which =
+ Z_IdAuthentication_open;
+ req->idAuthentication->u.open = odr_strdup (odr, t);
+ }
+ else if (!strcmp(type, "idPass"))
+ {
+ char user[64], group[64], password[64];
+ *group = '\0';
+ *password = '\0';
+ *user = '\0';
+ sscanf(t, "%63[^:]:%63[^:]:%63s", user, group, password);
+
+ req->idAuthentication =
+ (Z_IdAuthentication *)
+ odr_malloc (odr, sizeof(*req->idAuthentication));
+ req->idAuthentication->which =
+ Z_IdAuthentication_idPass;
+ req->idAuthentication->u.idPass =
+ (Z_IdPass*) odr_malloc(odr, sizeof(Z_IdPass));
+ req->idAuthentication->u.idPass->userId =
+ *user ? odr_strdup(odr, user) : 0;
+ req->idAuthentication->u.idPass->groupId =
+ *group ? odr_strdup(odr, group) : 0;
+ req->idAuthentication->u.idPass->password =
+ *password ? odr_strdup(odr, password) : 0;
+ }
+ }
+#endif
+}
+
+int Yaz_ProxyConfig::client_authentication(const char *name,
+ const char *user,
+ const char *group,
+ const char *password,
+ const char *peer_IP)
+{
+ int ret = YAZPROXY_RET_NOT_ME;
+#if YAZ_HAVE_XSLT
+ xmlNodePtr ptr;
+ ptr = m_cp->find_target_node(name);
+ if (!ptr)
+ return 1;
+ for (ptr = ptr->children; ptr; ptr = ptr->next)
+ if (ptr->type == XML_ELEMENT_NODE &&
+ !strcmp((const char *) ptr->name, "client-authentication"))
+ {
+ struct _xmlAttr *attr;
+ const char *module_name = 0;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "module") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ module_name = (const char *) attr->children->content;
+ }
+ ret = m_cp->m_modules.authenticate(module_name,
+ name, ptr,
+ user, group, password,
+ peer_IP
+ );
+ if (ret != YAZPROXY_RET_NOT_ME)
+ break;
+ }
+#endif
+ if (ret == YAZPROXY_RET_PERM)
+ return 0;
+ return 1;
+}
+
+int Yaz_ProxyConfig::global_client_authentication(const char *user,
+ const char *group,
+ const char *password,
+ const char *peer_IP)
+{
+ int ret = YAZPROXY_RET_NOT_ME;
+#if YAZ_HAVE_XSLT
+ if (!m_cp->m_proxyPtr)
+ return 1;
+ xmlNodePtr ptr;
+ for (ptr = m_cp->m_proxyPtr->children; ptr; ptr = ptr->next)
+ {
+ if (ptr->type == XML_ELEMENT_NODE &&
+ !strcmp((const char *) ptr->name, "client-authentication"))
+ {
+ struct _xmlAttr *attr;
+ const char *module_name = 0;
+ for (attr = ptr->properties; attr; attr = attr->next)
+ {
+ if (!strcmp((const char *) attr->name, "module") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ module_name = (const char *) attr->children->content;
+ }
+ ret = m_cp->m_modules.authenticate(module_name,
+ NULL, ptr,
+ user, group, password,
+ peer_IP
+ );
+ if (ret != YAZPROXY_RET_NOT_ME)
+ break;
+ }
+ }
+#endif
+ if (ret == YAZPROXY_RET_PERM)
+ return 0;
+ return 1;
+}
+