login_tentacle.cpp

Go to the documentation of this file.
00001 #ifndef LOGIN_TENTACLE_IMPLEMENTATION_FILE
00002 #define LOGIN_TENTACLE_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : login_tentacle                                                    *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "entity_registry.h"
00019 #include "login_tentacle.h"
00020 #include "security_infoton.h"
00021 
00022 #include <basis/log_base.h>
00023 #include <data_struct/string_hash.h>
00024 #include <mechanisms/time_stamp.h>
00025 #include <octopus/entity_defs.h>
00026 
00027 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00028 
00030 
00031 login_tentacle::login_tentacle(entity_registry &security,
00032     int dormancy_period)
00033 : tentacle_helper<security_infoton>(security_infoton::security_classifier(),
00034       false),
00035   _security(security),
00036   _dormancy_period(dormancy_period)
00037 {}
00038 
00039 login_tentacle::~login_tentacle() {}
00040 
00041 outcome login_tentacle::reconstitute(const string_array &classifier,
00042     byte_array &packed_form, infoton * &reformed)
00043 {
00044   if (classifier != security_infoton::security_classifier()) 
00045     return NO_HANDLER;
00046 
00047   return reconstituter(classifier, packed_form, reformed,
00048       (security_infoton *)NIL);
00049 }
00050 
00051 void login_tentacle::expunge(const octopus_entity &to_remove)
00052 {
00053   _security.zap_entity(to_remove);  // trash it and we're done.
00054 }
00055 
00056 outcome login_tentacle::consume(infoton &to_chow,
00057     const octopus_request_id &item_id, byte_array &transformed)
00058 {
00059   FUNCDEF("consume");
00060   transformed.reset();
00061   security_infoton *inf = dynamic_cast<security_infoton *>(&to_chow);
00062   if (!inf) {
00063     // if the infoton doesn't cast, then it is not for us.  we need to vet
00064     // that the entity it came from is known and approved.
00065     if (_security.authorized(item_id._entity)) {
00066       // this infoton's entity was allowed, so we call it partially processed.
00067       return PARTIAL;
00068     }
00069     // the infoton's entity is not authorized; it needs to be dropped.
00070     return DISALLOWED;
00071   }
00072 
00073   switch (inf->_mode) {
00074     case security_infoton::LI_REFRESH:  // intentional fall through.
00075     case security_infoton::LI_LOGIN: {
00076       bool success = _security.add_entity(item_id._entity,
00077           inf->verification());
00078       inf->_success = success? OKAY : DISALLOWED;
00079       break;
00080     }
00081     case security_infoton::LI_LOGOUT: {
00082       bool success = _security.zap_entity(item_id._entity);
00083       inf->_success = success? OKAY : DISALLOWED;
00084       break;
00085     }
00086     default: {
00087       inf->_success = BAD_INPUT;
00088       break;
00089     }
00090   }
00091   inf->verification().reset();  // we don't need to send that back.
00092   if (!store_product((infoton *)inf->clone(), item_id))
00093     return NO_SPACE;
00094   return OKAY;
00095 }
00096 
00097 
00098 #endif //LOGIN_TENTACLE_IMPLEMENTATION_FILE
00099 

Generated on Fri Nov 28 04:29:32 2008 for HOOPLE Libraries by  doxygen 1.5.1