2 * shib-target.h -- top-level header file for the SHIB Common Target Library
4 * Created by: Derek Atkins <derek@ihtfp.com>
13 # include <saml/saml.h>
14 # include <shib/shib.h>
17 #include <shib-target/shibrpc.h>
26 typedef SOCKET ShibSocket;
27 typedef u_short ShibSockName;
28 #define SHIB_SHAR_SOCKET 12345 /* shar portnumber */
32 typedef int ShibSocket;
33 typedef char * ShibSockName;
34 #define SHIB_SHAR_SOCKET "/tmp/shar-socket"
40 /* Create an RPC Client handle for the _connected_ socket sock, attaching
41 * the RPC program and version.
43 * returns a CLIENT on success, or NULL on error. The caller can
44 * call clnt_pcreateerror ("<string>") to output an error message from
47 CLIENT * shibrpc_client_create (ShibSocket sock, u_long program, u_long version);
51 /* Create a new socket and put it into sock.
53 * Returns 0 on success, non-zero on error
55 int shib_sock_create (ShibSocket *sock);
58 * bind the socket s to the "port" name.
60 * Returns 0 on success; non-zero on error.
62 * SIDE EFFECT: On error, the socket is closed!
64 int shib_sock_bind (ShibSocket s, ShibSockName name);
67 * connect the socket s to the "port" name on the local host.
69 * Returns 0 on success; non-zero on error.
71 int shib_sock_connect (ShibSocket s, ShibSockName name);
74 * accept a connection. Returns 0 on success, non-zero on failure.
76 int shib_sock_accept (ShibSocket listener, ShibSocket* s);
81 void shib_sock_close (ShibSocket s, ShibSockName name);
85 /* application names */
86 #define SHIBTARGET_GENERAL "general"
87 #define SHIBTARGET_SHAR "shar"
88 #define SHIBTARGET_SHIRE "shire"
89 #define SHIBTARGET_RM "rm"
90 #define SHIBTARGET_POLICIES "policies"
92 /* configuration tags */
93 #define SHIBTARGET_TAG_LOGGER "logger"
94 #define SHIBTARGET_TAG_SCHEMAS "schemadir"
95 #define SHIBTARGET_TAG_CERTFILE "certfile"
96 #define SHIBTARGET_TAG_KEYFILE "keyfile"
97 #define SHIBTARGET_TAG_KEYPASS "keypass"
98 #define SHIBTARGET_TAG_CALIST "calist"
100 #define SHIBTARGET_TAG_AAP "aap-uri"
101 #define SHIBTARGET_TAG_SITES "sitesFile"
103 #define SHIBTARGET_TAG_DEFAULTLIFE "defaultLife"
105 #define SHIBTARGET_TAG_CACHETYPE "cacheType"
106 #define SHIBTARGET_TAG_CACHECLEAN "cacheClean"
107 #define SHIBTARGET_TAG_CACHETIMEOUT "cacheTimeout"
109 #define SHIBTARGET_TAG_REQATTRS "requestAttributes"
111 /* initialize and finalize the target library (return 0 on success, 1 on failure) */
112 int shib_target_initialize (const char* application, const char* ini_file);
113 void shib_target_finalize (void);
114 ShibSockName shib_target_sockname(void);
120 namespace shibtarget {
125 Resource(const char* resource_url);
126 Resource(std::string resource_url);
129 const char* getResource() const;
130 const char* getURL() const;
131 bool equals(Resource*) const;
132 saml::Iterator<saml::SAMLAttribute*> getDesignators() const;
135 ResourcePriv *m_priv;
138 class RPCHandleInternal;
142 RPCHandle(ShibSockName shar, u_long program, u_long version);
145 CLIENT * connect(void); /* locks the HANDLE and returns the CLIENT */
146 void release(void); /* unlocks the HANDLE */
147 void disconnect(void); /* disconnects */
150 RPCHandleInternal *m_priv;
153 class ShibTargetException : public std::exception
156 explicit ShibTargetException() { m_code = SHIBRPC_OK; m_msg=""; }
157 explicit ShibTargetException(ShibRpcStatus code, const char* msg) { m_code = code; if (msg) m_msg=msg; }
158 explicit ShibTargetException(ShibRpcStatus code, const std::string& msg) : m_msg(msg) { m_code=code; }
159 virtual ~ShibTargetException() throw () {}
160 virtual const char* what() const throw () { return (m_msg.c_str()); }
161 virtual ShibRpcStatus which() const throw () { return (m_code); }
164 ShibRpcStatus m_code;
172 RPCError() { init(0,""); }
173 RPCError(int s, char const* st) { init(s,st); }
174 RPCError(ShibTargetException &exp) { init(exp.which(), exp.what()); }
180 // Return a set of strings that corresponds to the type, text, and desc
181 const char* getType();
182 const char* getText();
183 const char* getDesc();
184 const char* getOriginErrorURL();
185 const char* getOriginContactName();
186 const char* getOriginContactEmail();
190 void init(int code, char const* msg);
191 RPCErrorPriv* m_priv;
206 SHIRE(RPCHandle *rpc, SHIREConfig config, std::string shire_url);
209 RPCError* sessionIsValid(const char* cookie, const char* ip, const char* url);
210 RPCError* sessionCreate(const char* post, const char* ip,
211 std::string &cookie);
226 RM(RPCHandle *rpc, RMConfig config);
229 RPCError* getAssertions(const char* cookie, const char* ip,
231 std::vector<saml::SAMLAssertion*> &assertions,
232 saml::SAMLAuthenticationStatement **statement = NULL);
233 static void serialize(saml::SAMLAssertion &assertion, std::string &result);
234 static saml::Iterator<saml::SAMLAttribute*> getAttributes(saml::SAMLAssertion &assertion);
242 ShibINI (std::string& file, bool case_sensitive = true) { init(file,case_sensitive); }
243 ShibINI (const char *file, bool case_sensitive = true) {
244 std::string f = file;
245 init(f, case_sensitive);
251 const std::string get (const std::string& header, const std::string& tag);
252 const std::string get (const char* header, const char* tag) {
253 std::string h = header, t = tag;
257 const std::string operator() (const std::string& header, const std::string& tag) {
258 return get(header,tag);
260 const std::string operator() (const char* header, const char* tag) {
261 std::string h = header, t = tag;
265 bool exists(const std::string& header);
266 bool exists(const std::string& header, const std::string& tag);
268 bool exists(const char* header) {
269 std::string s = header;
272 bool exists(const char* header, const char* tag) {
273 std::string h = header, t = tag;
277 // Special method to look for a tag in one header and maybe in the
278 // 'SHIBTARGET_GENERAL' header
279 bool get_tag(std::string& header, std::string& tag, bool try_general,
280 std::string* result);
282 bool get_tag(std::string& header, const char* tag, bool try_general,
283 std::string* result) {
285 return get_tag (header,t,try_general,result);
288 bool get_tag(const char* header, const char* tag, bool try_general,
289 std::string* result) {
290 std::string h = header, t = tag;
291 return get_tag (h,t,try_general,result);
294 // Dump out the inifile to the output stream
295 void dump(std::ostream& os);
299 // The begin() functions reset the iterator and return the first element
300 // (or 0 if there are no elements.)
301 // The next() functions return the next element, or 0 if there are no
305 // for (const foo* current = begin(); current; current = next()) {
309 // NOTE: Holding an Iterator will lock the INI file and cause it to
310 // stop updating itself. You should destroy the iterator as soon as
311 // you are done with it.
313 // ALSO NOTE: the string* returned from the Iterator is only valid
314 // while you hold the iterator. You should copy the de-reference
315 // of the pointer to your own copy if you want to keep the string.
319 virtual ~Iterator() = 0;
320 virtual const std::string* begin() = 0;
321 virtual const std::string* next() = 0;
324 Iterator* header_iterator();
325 Iterator* tag_iterator(const std::string& header);
327 static bool boolean(std::string& value);
331 void init(std::string& file, bool case_sensitive);
340 void insert (const std::string& key, const std::string& value) { m_map[key] = value; }
341 void insert (const std::string& key, const char* value) {
342 std::string v = value;
345 void insert (const char* key, const std::string& value) {
349 void insert (const char* key, const char* value) {
350 std::string k = key, v = value;
353 void insert (RPCError& e);
355 void clear () { m_map.clear(); }
357 std::string run (std::istream& s) const;
358 std::string run (const std::string& input) const;
359 std::string run (const char* input) const {
360 std::string i = input;
366 std::map<std::string,std::string> m_map;
369 class ShibTargetConfig
372 static void preinit();
373 static ShibTargetConfig& init(const char* app_name, const char* inifile);
374 static ShibTargetConfig& getConfig();
375 virtual void init() = 0;
376 virtual void shutdown() = 0;
377 virtual ~ShibTargetConfig();
378 virtual ShibINI& getINI() = 0;
379 virtual saml::Iterator<const XMLCh*> getPolicies() = 0;
381 ShibSockName m_SocketName;
387 #endif /* SHIB_TARGET_H */