Add ChatPolicyRule
diff --git a/src/chat-policy-rule.cpp b/src/chat-policy-rule.cpp
new file mode 100644
index 0000000..1aa8b24
--- /dev/null
+++ b/src/chat-policy-rule.cpp
@@ -0,0 +1,62 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#include "chat-policy-rule.cpp"
+
+using namespace ndn;
+using namespace std;
+using namespace ndn::security;
+
+
+ChatPolicyRule::ChatPolicyRule(Ptr<Regex> dataRegex, const Name& dataRef,
+ Ptr<Regex> signerRegex, const Name& signerRef,
+ bool isPositive)
+ : PolicyRule(PolicyRule::IDENTITY_POLICY, isPositive)
+ , m_dataRegex(dataRegex)
+ , m_signerRegex(signerRegex)
+ , m_dataRef(dataRef)
+ , m_signerRef(signerRef)
+{}
+
+bool
+ChatPolicyRule::matchDataName(const Data & data)
+{ return (m_dataRegex.match(data.getName()) && m_dataRegex.expand() == m_dataRef) ? true : false; }
+
+bool
+ChatPolicyRule::matchSignerName(const Data & data)
+{
+ Ptr<const signature::Sha256WithRsa> sigPtr = DynamicCast<const signature::Sha256WithRsa> (data.getSignature());
+ Name signerName = sigPtr->getKeyLocator ().getKeyName ();
+ return (m_signerRegex.match(signerName) && m_signerRegex.expand() == m_signerRef) ? true : false;
+}
+
+bool
+ChatPolicyRule::satisfy(const Data & data)
+{ return (matchDataName(data) && matchSignerName(data)) ? true : false ; }
+
+bool
+ChatPolicyRule::satisfy(const Name & dataName, const Name & signerName)
+{
+ if (m_dataRegex.match(data.getName())
+ && m_dataRegex.expand() == m_dataRef
+ && m_signerRegex.match(signerName)
+ && m_signerRegex.expand() == m_signerRef)
+ return true;
+ else
+ return false;
+}
+
+TiXmlElement *
+ChatPolicyRule::toXmlElement()
+{
+ //TODO:
+ return NULL;
+}
+};
diff --git a/src/chat-policy-rule.h b/src/chat-policy-rule.h
new file mode 100644
index 0000000..dfb434d
--- /dev/null
+++ b/src/chat-policy-rule.h
@@ -0,0 +1,47 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#ifndef CHAT_POLICY_RULE_H
+#define CHAT_POLICY_RULE_H
+
+#include <ndn.cxx/security/policy/policy-rule.h>
+
+class ChatPolicyRule : public ndn::security::PolicyRule
+{
+
+public:
+ ChatPolicyRule();
+
+ virtual
+ ~ChatPolicyRyle() {};
+
+ bool
+ matchDataName(const Data & data);
+
+ bool
+ matchSignerName(const Data & data);
+
+ bool
+ satisfy(const Data & data);
+
+ bool
+ satisfy(const Name & dataName, const Name & signerName);
+
+ TiXmlElement *
+ toXmlElement();
+
+private:
+ ndn::Ptr<ndn::Regex> m_dataRegex;
+ ndn::Ptr<ndn::Regex> m_signerRegex;
+ ndn::Name m_dataRef;
+ ndn::Name m_signerRef;
+};
+
+#endif //CHAT_POLICY_RULE_H