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