virnetsocket.h 5.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * virnetsocket.h: generic network socket handling
 *
 * Copyright (C) 2006-2011 Red Hat, Inc.
 * Copyright (C) 2006 Daniel P. Berrange
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
20 21 22 23 24 25 26
 *
 * Author: Daniel P. Berrange <berrange@redhat.com>
 */

#ifndef __VIR_NET_SOCKET_H__
# define __VIR_NET_SOCKET_H__

27
# include "virsocketaddr.h"
28
# include "vircommand.h"
29
# ifdef WITH_GNUTLS
30 31
#  include "virnettlscontext.h"
# endif
32
# include "virobject.h"
33
# ifdef WITH_SASL
34 35
#  include "virnetsaslcontext.h"
# endif
36
# include "virjson.h"
37
# include "viruri.h"
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

typedef struct _virNetSocket virNetSocket;
typedef virNetSocket *virNetSocketPtr;


typedef void (*virNetSocketIOFunc)(virNetSocketPtr sock,
                                   int events,
                                   void *opaque);


int virNetSocketNewListenTCP(const char *nodename,
                             const char *service,
                             virNetSocketPtr **addrs,
                             size_t *naddrs);

int virNetSocketNewListenUNIX(const char *path,
                              mode_t mask,
55
                              uid_t user,
56 57
                              gid_t grp,
                              virNetSocketPtr *addr);
58 59 60

int virNetSocketNewListenFD(int fd,
                            virNetSocketPtr *addr);
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

int virNetSocketNewConnectTCP(const char *nodename,
                              const char *service,
                              virNetSocketPtr *addr);

int virNetSocketNewConnectUNIX(const char *path,
                               bool spawnDaemon,
                               const char *binary,
                               virNetSocketPtr *addr);

int virNetSocketNewConnectCommand(virCommandPtr cmd,
                                  virNetSocketPtr *retsock);

int virNetSocketNewConnectSSH(const char *nodename,
                              const char *service,
                              const char *binary,
                              const char *username,
                              bool noTTY,
79
                              bool noVerify,
80
                              const char *netcat,
81
                              const char *keyfile,
82 83 84
                              const char *path,
                              virNetSocketPtr *addr);

85 86 87 88 89 90 91 92 93
int virNetSocketNewConnectLibSSH2(const char *host,
                                  const char *port,
                                  const char *username,
                                  const char *privkey,
                                  const char *knownHosts,
                                  const char *knownHostsVerify,
                                  const char *authMethods,
                                  const char *command,
                                  virConnectAuthPtr auth,
94
                                  virURIPtr uri,
95 96
                                  virNetSocketPtr *retsock);

97 98 99
int virNetSocketNewConnectExternal(const char **cmdargv,
                                   virNetSocketPtr *addr);

100 101
int virNetSocketNewConnectSockFD(int sockfd,
                                 virNetSocketPtr *retsock);
102 103 104 105 106

virNetSocketPtr virNetSocketNewPostExecRestart(virJSONValuePtr object);

virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock);

107
int virNetSocketGetFD(virNetSocketPtr sock);
108 109
int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec);

110 111
bool virNetSocketIsLocal(virNetSocketPtr sock);

112 113
bool virNetSocketHasPassFD(virNetSocketPtr sock);

114 115
int virNetSocketGetPort(virNetSocketPtr sock);

116 117 118
int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
                                uid_t *uid,
                                gid_t *gid,
119 120
                                pid_t *pid,
                                unsigned long long *timestamp);
121 122
int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
                                  char **context);
123 124 125 126 127 128 129

int virNetSocketSetBlocking(virNetSocketPtr sock,
                            bool blocking);

ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len);
ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len);

130
int virNetSocketSendFD(virNetSocketPtr sock, int fd);
131
int virNetSocketRecvFD(virNetSocketPtr sock, int *fd);
132

133
# ifdef WITH_GNUTLS
134 135
void virNetSocketSetTLSSession(virNetSocketPtr sock,
                               virNetTLSSessionPtr sess);
136
# endif
137

138
# ifdef WITH_SASL
139 140 141 142
void virNetSocketSetSASLSession(virNetSocketPtr sock,
                                virNetSASLSessionPtr sess);
# endif
bool virNetSocketHasCachedData(virNetSocketPtr sock);
143
bool virNetSocketHasPendingData(virNetSocketPtr sock);
144 145 146 147

const char *virNetSocketLocalAddrString(virNetSocketPtr sock);
const char *virNetSocketRemoteAddrString(virNetSocketPtr sock);

148
int virNetSocketListen(virNetSocketPtr sock, int backlog);
149 150 151 152 153 154
int virNetSocketAccept(virNetSocketPtr sock,
                       virNetSocketPtr *clientsock);

int virNetSocketAddIOCallback(virNetSocketPtr sock,
                              int events,
                              virNetSocketIOFunc func,
155 156
                              void *opaque,
                              virFreeCallback ff);
157 158 159 160 161 162

void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
                                  int events);

void virNetSocketRemoveIOCallback(virNetSocketPtr sock);

163
void virNetSocketClose(virNetSocketPtr sock);
164 165 166


#endif /* __VIR_NET_SOCKET_H__ */