blob: a36634b76cb1f29ae8f218d168c12f4eaf0fc59f [file] [log] [blame]
Yingdi Yu42f66462013-10-31 17:38:22 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * Yingdi Yu
5 *
6 * BSD license, See the LICENSE file for more information
7 *
8 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
9 */
10
11#include "chronos-invitation.h"
Yingdi Yued8cfc42013-11-01 17:37:51 -070012
13#include <ndn.cxx/security/certificate/identity-certificate.h>
Yingdi Yu42f66462013-10-31 17:38:22 -070014#include "exception.h"
15#include "logging.h"
16
17using namespace std;
18using namespace ndn;
19
20INIT_LOGGER("ChronosInvitation");
21
22ChronosInvitation::ChronosInvitation(const ndn::Name& interestName)
23 : m_interestName(interestName)
24{
25 if(interestName.get(0).toUri() != string("ndn")
26 || interestName.get(1).toUri() != string("broadcast")
27 || interestName.get(2).toUri() != string("chronos")
28 || interestName.get(3).toUri() != string("invitation"))
29 throw LnException("Wrong ChronosInvitation Name");
30
31 int i = 4;
32 int size = interestName.size();
33
34 string chatroomStr("chatroom");
35 int inviteeBegin = 4;
36 for(; i < size; i++)
37 if(interestName.get(i).toUri() == chatroomStr)
38 break;
39
40 if(i >= size)
41 throw LnException("Wrong ChronosInvitation Name, No chatroom tag");
42 m_inviteeNameSpace = interestName.getSubName(inviteeBegin, i - inviteeBegin);
43
44 _LOG_DEBUG(m_inviteeNameSpace.toUri());
45
46 string inviterPrefixStr("inviter-prefix");
47 int chatroomBegin = (++i);
48 for(; i < size; i++)
49 if(interestName.get(i).toUri() == inviterPrefixStr)
50 break;
51
52 if(i > size)
53 throw LnException("Wrong ChronosInvitation Name, No inviter-prefix tag");
54 m_chatroom = interestName.getSubName(chatroomBegin, i - chatroomBegin);
55
56 _LOG_DEBUG(m_chatroom.toUri());
57
58 string inviterStr("inviter");
59 int inviterPrefixBegin = (++i);
60 for(; i < size; i++)
61 if(interestName.get(i).toUri() == inviterStr)
62 break;
63
64 if(i > size)
65 throw LnException("Wrong ChronosInvitation Name, No inviter tag");
66 m_inviterPrefix = interestName.getSubName(inviterPrefixBegin, i - inviterPrefixBegin);
67
68 _LOG_DEBUG(m_inviterPrefix.toUri());
69
70 int inviterCertBegin = (++i);
71 m_inviterCertificateName = interestName.getSubName(inviterCertBegin, size - 1 - inviterCertBegin);
72
73 _LOG_DEBUG(m_inviterCertificateName.toUri());
74
75 string signature = interestName.get(-1).toBlob();
76 m_signatureBits.insert(m_signatureBits.end(), signature.begin(), signature.end());
Yingdi Yued8cfc42013-11-01 17:37:51 -070077
78 Name keyName = security::IdentityCertificate::certificateNameToPublicKeyName(m_inviterCertificateName, true);
79 m_inviterNameSpace = keyName.getPrefix(keyName.size()-1);
Yingdi Yu42f66462013-10-31 17:38:22 -070080
81 string signedName = interestName.getSubName(0, size - 1).toUri();
82 m_signedBlob.insert(m_signedBlob.end(), signedName.begin(), signedName.end());
83}
84
85ChronosInvitation::ChronosInvitation(const ChronosInvitation& invitation)
86 : m_interestName(invitation.m_interestName)
87 , m_inviteeNameSpace(invitation.m_inviteeNameSpace)
88 , m_chatroom(invitation.m_chatroom)
89 , m_inviterPrefix(invitation.m_inviterPrefix)
90 , m_inviterCertificateName(invitation.m_inviterCertificateName)
91 , m_signatureBits(invitation.m_signatureBits)
92 , m_inviterNameSpace(invitation.m_inviterNameSpace)
93 , m_signedBlob(invitation.m_signedBlob)
94{}