Open SCAP Library
|
00001 /* 00002 * Copyright 2009 Red Hat Inc., Durham, North Carolina. 00003 * All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * Authors: 00020 * "Daniel Kopecek" <dkopecek@redhat.com> 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/rbt/rbt.h" 00032 #include "_sexp-types.h" 00033 #include "_seap-packetq.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 * Descriptor table + related stuff 00047 */ 00048 typedef struct { 00049 SEAP_msgid_t next_id; 00050 SEXP_ostate_t *ostate; /* Output state */ 00051 SEXP_pstate_t *pstate; /* Parser state */ 00052 SEAP_scheme_t scheme; /* Protocol/Scheme used for this descriptor */ 00053 void *scheme_data; /* Protocol/Scheme related data */ 00054 00055 SEXP_t *msg_queue; 00056 rbt_t *err_queue; 00057 SEXP_t *cmd_queue; 00058 00059 SEAP_packetq_t pck_queue; 00060 00061 pthread_mutex_t w_lock; 00062 pthread_mutex_t r_lock; 00063 00064 SEAP_cmdid_t next_cid; 00065 SEAP_cmdtbl_t *cmd_c_table; /* Local SEAP commands */ 00066 SEAP_cmdtbl_t *cmd_w_table; /* Waiting SEAP commands */ 00067 } SEAP_desc_t; 00068 00069 #define SEAP_DESC_FDIN 0x00000001 00070 #define SEAP_DESC_FDOUT 0x00000002 00071 #define SEAP_DESC_SELF -1 00072 00073 typedef struct { 00074 rbt_t *tree; 00075 bitmap_t *bmap; 00076 } SEAP_desctable_t; 00077 00078 #define SEAP_DESCTBL_INITIALIZER { NULL, NULL } 00079 00080 #define SEAP_BUFFER_SIZE 2*4096 00081 #define SEAP_MAX_OPENDESC 128 00082 #define SDTABLE_REALLOC_ADD 4 00083 00084 int SEAP_desc_add (SEAP_desctable_t *sd_table, SEXP_pstate_t *pstate, SEAP_scheme_t scheme, void *scheme_data); 00085 int SEAP_desc_del (SEAP_desctable_t *sd_table, int sd); 00086 SEAP_desc_t *SEAP_desc_get (SEAP_desctable_t *sd_table, int sd); 00087 00088 SEAP_desctable_t *SEAP_desctable_new (void); 00089 void SEAP_desctable_free(SEAP_desctable_t *sd_table); 00090 void SEAP_desc_free(SEAP_desc_t *dsc); 00091 00092 static inline int SEAP_desc_trylock (pthread_mutex_t *m) 00093 { 00094 switch (pthread_mutex_trylock (m)) { 00095 case 0: 00096 return (1); 00097 case EBUSY: 00098 return (0); 00099 case EINVAL: 00100 errno = EINVAL; 00101 /* FALLTHROUGH */ 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 /* _SEAP_DESCRIPTOR_H */