root/include/crm/common/ipcs.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * Copyright (C) 2013 Andrew Beekhof <andrew@beekhof.net>
   3  *
   4  * This program is free software; you can redistribute it and/or
   5  * modify it under the terms of the GNU Lesser General Public
   6  * License as published by the Free Software Foundation; either
   7  * version 2 of the License, or (at your option) any later version.
   8  *
   9  * This software is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12  * General Public License for more details.
  13  *
  14  * You should have received a copy of the GNU Lesser General Public
  15  * License along with this library; if not, write to the Free Software
  16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  17  */
  18 
  19 #ifndef CRM_COMMON_IPCS__H
  20 #  define CRM_COMMON_IPCS__H
  21 
  22 #  include <stdbool.h>
  23 #  include <qb/qbipcs.h>
  24 #  ifdef HAVE_GNUTLS_GNUTLS_H
  25 #    undef KEYFILE
  26 #    include <gnutls/gnutls.h>
  27 #  endif
  28 
  29 #  include <crm/common/ipc.h>
  30 #  include <crm/common/mainloop.h>
  31 
  32 typedef struct crm_client_s crm_client_t;
  33 
  34 enum client_type {
  35     CRM_CLIENT_IPC = 1,
  36     CRM_CLIENT_TCP = 2,
  37 #  ifdef HAVE_GNUTLS_GNUTLS_H
  38     CRM_CLIENT_TLS = 3,
  39 #  endif
  40 };
  41 
  42 struct crm_remote_s {
  43     /* Shared */
  44     char *buffer;
  45     size_t buffer_size;
  46     size_t buffer_offset;
  47     int auth_timeout;
  48     int tcp_socket;
  49     mainloop_io_t *source;
  50 
  51     /* CIB-only */
  52     bool authenticated;
  53     char *token;
  54 
  55     /* TLS only */
  56 #  ifdef HAVE_GNUTLS_GNUTLS_H
  57     gnutls_session_t *tls_session;
  58     bool tls_handshake_complete;
  59 #  endif
  60 };
  61 
  62 enum crm_client_flags
  63 {
  64     crm_client_flag_ipc_proxied    = 0x00001, /* ipc_proxy code only */
  65     crm_client_flag_ipc_privileged = 0x00002, /* root or cluster user */
  66 };
  67 
  68 struct crm_client_s {
  69     uint pid;
  70 
  71     uid_t uid;
  72     gid_t gid;
  73 
  74     char *id;
  75     char *name;
  76     char *user;
  77 
  78     /* Provided for server use (not used by library) */
  79     /* @TODO merge options, flags, and kind (reserving lower bits for server) */
  80     long long options;
  81 
  82     int request_id;
  83     uint32_t flags;
  84     void *userdata;
  85 
  86     int event_timer;
  87     GList *event_queue; /* @TODO use GQueue instead */
  88 
  89     /* Depending on the value of kind, only some of the following
  90      * will be populated/valid
  91      */
  92     enum client_type kind;
  93 
  94     qb_ipcs_connection_t *ipcs; /* IPC */
  95 
  96     struct crm_remote_s *remote;        /* TCP/TLS */
  97 
  98     unsigned int queue_backlog; /* IPC queue length after last flush */
  99     unsigned int queue_max;     /* Evict client whose queue grows this big */
 100 };
 101 
 102 extern GHashTable *client_connections;
 103 
 104 void crm_client_init(void);
 105 void crm_client_cleanup(void);
 106 
 107 crm_client_t *crm_client_get(qb_ipcs_connection_t * c);
 108 crm_client_t *crm_client_get_by_id(const char *id);
 109 const char *crm_client_name(crm_client_t * c);
 110 
 111 crm_client_t *crm_client_alloc(void *key);
 112 crm_client_t *crm_client_new(qb_ipcs_connection_t * c, uid_t uid, gid_t gid);
 113 void crm_client_destroy(crm_client_t * c);
 114 void crm_client_disconnect_all(qb_ipcs_service_t *s);
 115 bool crm_set_client_queue_max(crm_client_t *client, const char *qmax);
 116 
 117 void crm_ipcs_send_ack(crm_client_t * c, uint32_t request, uint32_t flags,
 118                        const char *tag, const char *function, int line);
 119 
 120 /* when max_send_size is 0, default ipc buffer size is used */
 121 ssize_t crm_ipc_prepare(uint32_t request, xmlNode * message, struct iovec ** result, uint32_t max_send_size);
 122 ssize_t crm_ipcs_send(crm_client_t * c, uint32_t request, xmlNode * message, enum crm_ipc_flags flags);
 123 ssize_t crm_ipcs_sendv(crm_client_t * c, struct iovec *iov, enum crm_ipc_flags flags);
 124 xmlNode *crm_ipcs_recv(crm_client_t * c, void *data, size_t size, uint32_t * id, uint32_t * flags);
 125 
 126 int crm_ipcs_client_pid(qb_ipcs_connection_t * c);
 127 
 128 #endif

/* [previous][next][first][last][top][bottom][index][help] */