Merge branch 'master' of feistymeow.org:feisty_meow
[feisty_meow.git] / octopi / library / octopus / identity_tentacle.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : identity_tentacle                                                 *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *******************************************************************************
7 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com                               *
13 \*****************************************************************************/
14
15 #include "identity_tentacle.h"
16 #include "identity_infoton.h"
17 #include "octopus.h"
18
19 #include <structures/string_hash.h>
20 #include <timely/time_stamp.h>
21
22 using namespace basis;
23 using namespace structures;
24 using namespace timely;
25
26 namespace octopi {
27
28 #undef LOG
29 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
30
31 //#define DEBUG_IDENTITY_TENTACLE
32   // uncomment for debugging version.
33
34 //////////////
35
36 identity_tentacle::identity_tentacle(octopus &parent)
37 : tentacle_helper<identity_infoton>(identity_infoton::identity_classifier(),
38       false),
39   _parent(parent)
40 {}
41
42 identity_tentacle::~identity_tentacle() {}
43
44 outcome identity_tentacle::reconstitute(const string_array &classifier,
45     byte_array &packed_form, infoton * &reformed)
46 {
47   if (classifier != identity_infoton::identity_classifier()) 
48     return NO_HANDLER;
49
50   return reconstituter(classifier, packed_form, reformed,
51       (identity_infoton *)NULL_POINTER);
52 }
53
54 outcome identity_tentacle::consume(infoton &to_chow,
55     const octopus_request_id &item_id, byte_array &transformed)
56 {
57 #ifdef DEBUG_IDENTITY_TENTACLE
58   FUNCDEF("consume");
59 #endif
60   transformed.reset();
61   identity_infoton *inf = dynamic_cast<identity_infoton *>(&to_chow);
62   if (!inf) {
63     // if the infoton doesn't cast, then it is not for us.  we need to vet
64     // that the identity looks pretty much okay.
65
66 //hmmm: check host?
67 //      that would imply that all users of octopi have correctly identified
68 //      themselves.  this is not currently the case.  we need a way to
69 //      automate that step for a user of an octopus?
70 bool uhhh = true;
71
72     if (uhhh) {
73       // this infoton's entity was allowed, so we call it partially processed.
74       return PARTIAL;
75     }
76 #ifdef DEBUG_IDENTITY_TENTACLE
77     LOG(astring("denying infoton ") + item_id.mangled_form());
78 #endif
79     // the infoton's identity is invalid; it needs to be dropped.
80     return DISALLOWED;
81   }
82
83 #ifdef DEBUG_IDENTITY_TENTACLE
84   LOG(astring("old name, storing under: ") + item_id.mangled_form());
85 #endif
86
87   // this is definitely for an identity request now.
88   inf->_new_name = _parent.issue_identity();
89
90 #ifdef DEBUG_IDENTITY_TENTACLE
91   LOG(astring("new name: ") + inf->_new_name.mangled_form());
92 #endif
93
94   if (!store_product(dynamic_cast<infoton *>(inf->clone()), item_id))
95     return NO_SPACE;
96   return OKAY;
97 }
98
99 } //namespace.
100