00001 #ifndef __STUB_PROBE
00002 #pragma once
00003 #ifndef _SEAP_DESCRIPTOR_H
00004 #define _SEAP_DESCRIPTOR_H
00005
00006 #include <errno.h>
00007 #include <pthread.h>
00008 #include <stdint.h>
00009 #include "generic/bitmap.h"
00010 #include "generic/pqueue.h"
00011 #include "_sexp-types.h"
00012 #include "_sexp-parse.h"
00013 #include "_sexp-output.h"
00014 #include "_seap-command.h"
00015 #include "public/seap-scheme.h"
00016 #include "public/seap-message.h"
00017 #include "public/seap-command.h"
00018 #include "public/seap-error.h"
00019 #include "../../../common/util.h"
00020
00021 OSCAP_HIDDEN_START;
00022
00023
00024
00025
00026 typedef struct {
00027 SEAP_msgid_t next_id;
00028 SEXP_t *sexpbuf;
00029 SEXP_ostate_t *ostate;
00030 SEXP_pstate_t *pstate;
00031 SEAP_scheme_t scheme;
00032 void *scheme_data;
00033
00034
00035 SEXP_t *msg_queue;
00036 SEXP_t *err_queue;
00037 SEXP_t *cmd_queue;
00038
00039 pqueue_t *pck_queue;
00040
00041
00042
00043 pthread_mutex_t w_lock;
00044 pthread_mutex_t r_lock;
00045
00046 SEAP_cmdid_t next_cid;
00047 SEAP_cmdtbl_t *cmd_c_table;
00048 SEAP_cmdtbl_t *cmd_w_table;
00049 } SEAP_desc_t;
00050
00051 #define SEAP_DESC_FDIN 0x00000001
00052 #define SEAP_DESC_FDOUT 0x00000002
00053 #define SEAP_DESC_SELF -1
00054
00055 typedef struct {
00056 SEAP_desc_t *sd;
00057 uint16_t sdsize;
00058 bitmap_t bitmap;
00059 } SEAP_desctable_t;
00060
00061 #define SEAP_DESCTBL_INITIALIZER { NULL, 0, BITMAP_INITIALIZER }
00062
00063 #define SEAP_BUFFER_SIZE 2*4096
00064 #define SEAP_MAX_OPENDESC 128
00065 #define SDTABLE_REALLOC_ADD 4
00066
00067 int SEAP_desc_add (SEAP_desctable_t *sd_table, SEXP_pstate_t *pstate, SEAP_scheme_t scheme, void *scheme_data);
00068 int SEAP_desc_del (SEAP_desctable_t *sd_table, int sd);
00069 SEAP_desc_t *SEAP_desc_get (SEAP_desctable_t *sd_table, int sd);
00070
00071 static inline int SEAP_desc_trylock (pthread_mutex_t *m)
00072 {
00073 switch (pthread_mutex_trylock (m)) {
00074 case 0:
00075 return (1);
00076 case EBUSY:
00077 return (0);
00078 case EINVAL:
00079 errno = EINVAL;
00080 default:
00081 return (-1);
00082 }
00083 }
00084
00085 static inline int SEAP_desc_lock (pthread_mutex_t *m)
00086 {
00087 switch (pthread_mutex_lock (m)) {
00088 case 0:
00089 return (1);
00090 default:
00091 return (-1);
00092 }
00093 }
00094
00095 static inline int SEAP_desc_unlock (pthread_mutex_t *m)
00096 {
00097 switch (pthread_mutex_unlock (m)) {
00098 case 0:
00099 return (1);
00100 default:
00101 return (-1);
00102 }
00103 }
00104
00105 #define DESC_TRYRLOCK(d) SEAP_desc_trylock (&((d)->r_lock))
00106 #define DESC_RLOCK(d) SEAP_desc_lock (&((d)->r_lock))
00107 #define DESC_RUNLOCK(d) SEAP_desc_unlock (&((d)->r_lock))
00108
00109 #define DESC_TRYWLOCK(d) SEAP_desc_trylock (&((d)->w_lock))
00110 #define DESC_WLOCK(d) SEAP_desc_lock (&((d)->w_lock))
00111 #define DESC_WUNLOCK(d) SEAP_desc_unlock (&((d)->w_lock))
00112
00113 SEAP_msgid_t SEAP_desc_genmsgid (SEAP_desctable_t *sd_table, int sd);
00114 SEAP_cmdid_t SEAP_desc_gencmdid (SEAP_desctable_t *sd_table, int sd);
00115
00116 OSCAP_HIDDEN_END;
00117
00118 #endif
00119 #endif