Rudimentary tool.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Wed, 5 Sep 2007 20:50:04 +0000 (20:50 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Wed, 5 Sep 2007 20:50:04 +0000 (20:50 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2450 cb58f699-b61c-0410-a6fe-9272a202ed29

util/mdquery.cpp

index f0f918c..4440f8f 100644 (file)
 #include <shibsp/ServiceProvider.h>\r
 #include <shibsp/util/SPConstants.h>\r
 #include <saml/saml2/metadata/Metadata.h>\r
+#include <xmltooling/logging.h>\r
 \r
 using namespace shibsp;\r
 using namespace opensaml::saml2md;\r
 using namespace opensaml;\r
+using namespace xmltooling::logging;\r
 using namespace xmltooling;\r
 using namespace std;\r
 \r
 int main(int argc,char* argv[])\r
 {\r
-    /*\r
-    char* n_param=NULL;\r
-    char* q_param=NULL;\r
-    char* f_param=NULL;\r
-    char* a_param=NULL;\r
+    char* entityID = NULL;\r
+    char* appID = "default";\r
+    bool strict = true;\r
 \r
     for (int i=1; i<argc; i++) {\r
-        if (!strcmp(argv[i],"-n") && i+1<argc)\r
-            n_param=argv[++i];\r
-        else if (!strcmp(argv[i],"-q") && i+1<argc)\r
-            q_param=argv[++i];\r
-        else if (!strcmp(argv[i],"-f") && i+1<argc)\r
-            f_param=argv[++i];\r
+        if (!strcmp(argv[i],"-e") && i+1<argc)\r
+            entityID=argv[++i];\r
         else if (!strcmp(argv[i],"-a") && i+1<argc)\r
-            a_param=argv[++i];\r
+            appID=argv[++i];\r
+        else if (!strcmp(argv[i],"--nostrict"))\r
+            strict = false;\r
     }\r
 \r
-    if (!n_param || !q_param) {\r
-        cerr << "usage: samlquery -n <name> -q <IdP> [-f <format URI> -a <application id>]" << endl;\r
+    if (!entityID) {\r
+        cerr << "usage: mdquery -e <entityID> [-a <application id> --nostrict]" << endl;\r
         exit(0);\r
     }\r
-    if (!a_param)\r
-        a_param="default";\r
-    */\r
 \r
     char* path=getenv("SHIBSP_SCHEMAS");\r
     if (!path)\r
@@ -83,7 +78,7 @@ int main(int argc,char* argv[])
     SPConfig& conf=SPConfig::getConfig();\r
     conf.setFeatures(SPConfig::Metadata | SPConfig::OutOfProcess);\r
     if (!conf.init(path))\r
-        return -10;\r
+        return -1;\r
 \r
     try {\r
         static const XMLCh _path[] = UNICODE_LITERAL_4(p,a,t,h);\r
@@ -99,12 +94,33 @@ int main(int argc,char* argv[])
     }\r
     catch (exception&) {\r
         conf.term();\r
-        return -20;\r
+        return -2;\r
     }\r
 \r
     ServiceProvider* sp=conf.getServiceProvider();\r
     sp->lock();\r
 \r
+    Category& log = Category::getInstance(SHIBSP_LOGCAT".Utility.MDQuery");\r
+\r
+    const Application* app = sp->getApplication(appID);\r
+    if (!app) {\r
+        log.error("unknown application ID (%s)", appID);\r
+        sp->unlock();\r
+        conf.term();\r
+        return -3;\r
+    }\r
+\r
+    app->getMetadataProvider()->lock();\r
+    const EntityDescriptor* entity = app->getMetadataProvider()->getEntityDescriptor(entityID, strict);\r
+    if (entity) {\r
+        XMLHelper::serialize(entity->marshall(), cout, true);\r
+    }\r
+    else {\r
+        log.error("no metadata found for (%s)", entityID);\r
+    }\r
+\r
+    app->getMetadataProvider()->unlock();\r
+\r
     sp->unlock();\r
     conf.term();\r
     return 0;\r