feisty meow concerns codebase  2.140
login_tentacle.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : login_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 "entity_registry.h"
16 #include "login_tentacle.h"
17 #include "security_infoton.h"
18 
19 #include <octopus/entity_defs.h>
20 #include <structures/string_hash.h>
21 #include <timely/time_stamp.h>
22 
23 using namespace basis;
24 using namespace octopi;
25 using namespace structures;
26 using namespace timely;
27 
28 namespace octopi {
29 
30 #undef LOG
31 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
32 
34 
35 login_tentacle::login_tentacle(entity_registry &security, int dormancy_period)
36 : tentacle_helper<security_infoton>(security_infoton::security_classifier(),
37  false),
38  _security(security),
39  _dormancy_period(dormancy_period)
40 {}
41 
43 
45  byte_array &packed_form, infoton * &reformed)
46 {
47  if (classifier != security_infoton::security_classifier())
48  return NO_HANDLER;
49 
50  return reconstituter(classifier, packed_form, reformed,
52 }
53 
55 {
56  _security.zap_entity(to_remove); // trash it and we're done.
57 }
58 
60  const octopus_request_id &item_id, byte_array &transformed)
61 {
62  FUNCDEF("consume");
63  transformed.reset();
64  security_infoton *inf = dynamic_cast<security_infoton *>(&to_chow);
65  if (!inf) {
66  // if the infoton doesn't cast, then it is not for us. we need to vet
67  // that the entity it came from is known and approved.
68  if (_security.authorized(item_id._entity)) {
69  // this infoton's entity was allowed, so we call it partially processed.
70  return PARTIAL;
71  }
72  // the infoton's entity is not authorized; it needs to be dropped.
73  return DISALLOWED;
74  }
75 
76  switch (inf->_mode) {
77  case security_infoton::LI_REFRESH: // intentional fall through.
79  bool success = _security.add_entity(item_id._entity,
80  inf->verification());
81  inf->_success = success? OKAY : DISALLOWED;
82  break;
83  }
85  bool success = _security.zap_entity(item_id._entity);
86  inf->_success = success? OKAY : DISALLOWED;
87  break;
88  }
89  default: {
90  inf->_success = BAD_INPUT;
91  break;
92  }
93  }
94  inf->verification().reset(); // we don't need to send that back.
95  if (!store_product(dynamic_cast<infoton *>(inf->clone()), item_id))
96  return NO_SPACE;
97  return OKAY;
98 }
99 
100 } //namespace.
101 
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
Definition: array.h:349
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
Provides a security model for the octopus.
virtual bool authorized(const octopus_entity &entity)=0
returns true if the "entity" is a registered entity.
virtual bool add_entity(const octopus_entity &entity, const basis::byte_array &verification)=0
adds the "entity" to the list of authorized users if allowed.
virtual bool zap_entity(const octopus_entity &entity)=0
removes a "entity" if the entity can be found.
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
virtual basis::outcome consume(infoton &to_chow, const octopus_request_id &item_id, basis::byte_array &transformed)
the base login_tentacle allows anyone to log in.
virtual void expunge(const octopus_entity &to_remove)
trashes the records we were keeping for the entity.
virtual basis::outcome reconstitute(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed)
recreates a "reformed" infoton from the packed data.
Provides a way of identifying users of an octopus object.
Definition: entity_defs.h:35
Identifies requests made on an octopus by users.
Definition: entity_defs.h:114
octopus_entity _entity
the entity.
Definition: entity_defs.h:116
Encapsulates security activities (login, logout, refresh).
@ LI_REFRESH
the requester is still alive and wants to keep its login.
@ LI_LOGIN
the requester wants to log in as a new entity.
@ LI_LOGOUT
the requester surrenders its login.
basis::outcome _success
did the request succeed?
const basis::byte_array & verification() const
virtual clonable * clone() const
must be provided to allow creation of a copy of this object.
login_modes _mode
what kind of request is being made here?
static const structures::string_array & security_classifier()
returns the classifier for this type of infoton.
provides prefab implementations for parts of the tentacle object.
bool store_product(infoton *product, const octopus_request_id &original_id)
used by tentacles to store the objects they produce from infotons.
Definition: tentacle.cpp:118
@ PARTIAL
processing of request is partially done.
Definition: tentacle.h:74
@ NO_HANDLER
no handler for that type of infoton.
Definition: tentacle.h:73
An array of strings with some additional helpful methods.
Definition: string_array.h:32
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
basis::outcome reconstituter(const structures::string_array &classifier, basis::byte_array &packed_form, infoton *&reformed, contents *formal(junk))
< reconstituter should work for most infotons to restore flattened infotons.
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
#include <time.h>
Definition: earth_time.cpp:37