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

/home/pvrabec/project/openscap/openscap-0.6.6/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         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; /* 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         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 */

Generated on Thu Dec 9 2010 for Open SCAP Library by  doxygen 1.7.1