feisty meow concerns codebase 2.140
security_infoton.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : security_infoton *
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 "security_infoton.h"
16
17#include <basis/byte_array.h>
18#include <basis/functions.h>
19#include <basis/mutex.h>
22#include <octopus/tentacle.h>
23
24using namespace basis;
25using namespace structures;
26//using namespace textual;
27
28namespace octopi {
29
31: infoton(security_classifier()),
32 _mode(LI_LOGIN),
33 _success(tentacle::NOT_FOUND),
34 _verification(new byte_array)
35{}
36
38 const byte_array &verification)
39: infoton(security_classifier()),
40 _mode(mode),
41 _success(success),
42 _verification(new byte_array(verification))
43{}
44
46: root_object(),
47 infoton(to_copy),
48 _mode(to_copy._mode),
49 _success(to_copy._success),
50 _verification(new byte_array(*to_copy._verification))
51{
52}
53
56
58{ return cloner<security_infoton>(*this); }
59
61{
62 if (this == &to_copy) return *this;
63 set_classifier(to_copy.classifier());
64 _mode = to_copy._mode;
65 _success = to_copy._success;
66 *_verification = *to_copy._verification;
67 return *this;
68}
69
71{ return *_verification; }
72
73byte_array &security_infoton::verification() { return *_verification; }
74
75const astring login_classifier[] = { "#octsec" };
76
79
81{
82 return sizeof(_mode)
83 + sizeof(int) // packed outcome.
84 + _verification->length() + sizeof(int);
85}
86
87void security_infoton::pack(byte_array &packed_form) const
88{
89 structures::attach(packed_form, int(_mode));
90 attach(packed_form, _success.value());
91 structures::attach(packed_form, *_verification);
92}
93
94bool security_infoton::unpack(byte_array &packed_form)
95{
96 int int_hold;
97 if (!structures::detach(packed_form, int_hold)) return false;
98 _mode = login_modes(int_hold);
99 int value;
100 if (!detach(packed_form, value)) return false;
101 _success = outcome(value);
102 if (!structures::detach(packed_form, *_verification)) return false;
103 return true;
104}
105
106} //namespace.
107
int length() const
Returns the current reported length of the allocated C array.
Definition array.h:115
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
A clonable object knows how to make copy of itself.
Definition contracts.h:109
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
int value() const
Definition outcome.h:51
An infoton is an individual request parcel with accompanying information.
Definition infoton.h:32
void set_classifier(const structures::string_array &new_classifier)
sets the infoton's classifier to the "new_classifier".
Definition infoton.cpp:104
const structures::string_array & classifier() const
this array of strings is the "name" for this infoton.
Definition infoton.cpp:85
Encapsulates security activities (login, logout, refresh).
basis::outcome _success
did the request succeed?
virtual void pack(basis::byte_array &packed_form) const
stuffs the data in the infoton into the "packed_form".
virtual int packed_size() const
reports how large the infoton will be when packed.
const basis::byte_array & verification() const
static const structures::string_array & security_classifier()
returns the classifier for this type of infoton.
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?
virtual bool unpack(basis::byte_array &packed_form)
restores an infoton from a packed form.
security_infoton & operator=(const security_infoton &to_copy)
Manages a service within an octopus by processing certain infotons.
Definition tentacle.h:36
An array of strings with some additional helpful methods.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
Definition functions.h:121
void attach(byte_array &packed_form, const char *to_attach)
Packs a character string "to_attach" into "packed_form".
Definition astring.cpp:1018
bool detach(byte_array &packed_form, astring &to_detach)
Unpacks a character string "to_attach" from "packed_form".
Definition astring.cpp:1026
const astring login_classifier[]
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55
void attach(byte_array &packed_form, const byte_array &to_attach)
Packs a byte_array "to_attach" into "packed_form".
bool detach(byte_array &packed_form, byte_array &to_detach)
Unpacks a byte_array "to_detach" from "packed_form".
#define SAFE_STATIC_CONST(type, func_name, parms)
this version returns a constant object instead.