• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

/home/pvrabec/project/openscap/openscap-0.7.1/src/OVAL/probes/SEAP/seap-descriptor.h

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/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  * Descriptor table + related stuff
00047  */
00048 typedef struct {
00049         SEAP_msgid_t   next_id;
00050         SEXP_t        *sexpbuf; /* S-exp buffer */
00051         SEXP_ostate_t *ostate; /* Output state */
00052         SEXP_pstate_t *pstate; /* Parser state */
00053         SEAP_scheme_t  scheme; /* Protocol/Scheme used for this descriptor */
00054         void          *scheme_data; /* Protocol/Scheme related data */
00055 
00056         SEXP_t *msg_queue;
00057         rbt_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; /* Local SEAP commands */
00067         SEAP_cmdtbl_t *cmd_w_table; /* Waiting SEAP commands */
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                 /* FALLTHROUGH */
00103         default:
00104                 return (-1);
00105         }
00106 }
00107 
00108 static inline int SEAP_desc_lock (pthread_mutex_t *m)
00109 {
00110         switch (pthread_mutex_lock (m)) {
00111         case 0:
00112                 return (1);
00113         default:
00114                 return (-1);
00115         }
00116 }
00117 
00118 static inline int SEAP_desc_unlock (pthread_mutex_t *m)
00119 {
00120         switch (pthread_mutex_unlock (m)) {
00121         case 0:
00122                 return (1);
00123         default:
00124                 return (-1);
00125         }
00126 }
00127 
00128 #define DESC_TRYRLOCK(d) SEAP_desc_trylock (&((d)->r_lock))
00129 #define DESC_RLOCK(d)    SEAP_desc_lock (&((d)->r_lock))
00130 #define DESC_RUNLOCK(d)  SEAP_desc_unlock (&((d)->r_lock))
00131 
00132 #define DESC_TRYWLOCK(d) SEAP_desc_trylock (&((d)->w_lock))
00133 #define DESC_WLOCK(d)    SEAP_desc_lock (&((d)->w_lock))
00134 #define DESC_WUNLOCK(d)  SEAP_desc_unlock (&((d)->w_lock))
00135 
00136 SEAP_msgid_t SEAP_desc_genmsgid (SEAP_desctable_t *sd_table, int sd);
00137 SEAP_cmdid_t SEAP_desc_gencmdid (SEAP_desctable_t *sd_table, int sd);
00138 
00139 OSCAP_HIDDEN_END;
00140 
00141 #endif /* _SEAP_DESCRIPTOR_H */

Generated on Fri Mar 11 2011 for Open SCAP Library by  doxygen 1.7.1