static int virNetServerDispatchNewClient(virNetServerServicePtr svc, virNetSocketPtr clientsock, void *opaque) { virNetServerPtr srv = opaque; virNetServerClientPtr client; if (!(client = virNetServerClientNew(clientsock, virNetServerServiceGetAuth(svc), virNetServerServiceIsReadonly(svc), virNetServerServiceGetMaxRequests(svc), #if WITH_GNUTLS virNetServerServiceGetTLSContext(svc), #endif srv->clientPrivNew, srv->clientPrivPreExecRestart, srv->clientPrivFree, srv->clientPrivOpaque))) return -1; if (virNetServerAddClient(srv, client) < 0) { virNetServerClientClose(client); virObjectUnref(client); return -1; } virObjectUnref(client); return 0; }
static void virNetServerServiceAccept(virNetSocketPtr sock, int events ATTRIBUTE_UNUSED, void *opaque) { virNetServerServicePtr svc = opaque; virNetServerClientPtr client = NULL; virNetSocketPtr clientsock = NULL; if (virNetSocketAccept(sock, &clientsock) < 0) goto error; if (!clientsock) /* Connection already went away */ goto cleanup; if (!(client = virNetServerClientNew(clientsock, svc->auth, svc->readonly, svc->nrequests_client_max, svc->tls))) goto error; if (!svc->dispatchFunc) goto error; if (svc->dispatchFunc(svc, client, svc->dispatchOpaque) < 0) virNetServerClientClose(client); virNetServerClientFree(client); cleanup: return; error: if (client) { virNetServerClientClose(client); virNetServerClientFree(client); } else { virNetSocketFree(clientsock); } }
static virNetServerPtr testCreateServer(const char *host, int family) { virNetServerPtr srv = NULL; virNetServerServicePtr svc1 = NULL, svc2 = NULL; virNetServerClientPtr cln1 = NULL, cln2 = NULL; virNetSocketPtr sk1 = NULL, sk2 = NULL; int fdclient[2]; if (socketpair(PF_UNIX, SOCK_STREAM, 0, fdclient) < 0) { virReportSystemError(errno, "%s", "Cannot create socket pair"); goto cleanup; } if (!(srv = virNetServerNew(10, 50, 5, 100, 10, 120, 5, true, # ifdef WITH_AVAHI "libvirtTest", # else NULL, # endif NULL, NULL, NULL, NULL))) goto error; if (!(svc1 = virNetServerServiceNewTCP(host, NULL, family, VIR_NET_SERVER_SERVICE_AUTH_NONE, # ifdef WITH_GNUTLS NULL, # endif true, 5, 2))) goto error; if (!(svc2 = virNetServerServiceNewTCP(host, NULL, family, VIR_NET_SERVER_SERVICE_AUTH_POLKIT, # ifdef WITH_GNUTLS NULL, # endif false, 25, 5))) goto error; if (virNetServerAddService(srv, svc1, "libvirt-ro") < 0) goto error; if (virNetServerAddService(srv, svc2, "libvirt-ro") < 0) goto error; if (virNetSocketNewConnectSockFD(fdclient[0], &sk1) < 0) goto error; if (virNetSocketNewConnectSockFD(fdclient[1], &sk2) < 0) goto error; if (!(cln1 = virNetServerClientNew(sk1, VIR_NET_SERVER_SERVICE_AUTH_SASL, true, 15, # ifdef WITH_GNUTLS NULL, # endif NULL, NULL, NULL, NULL))) goto error; if (!(cln2 = virNetServerClientNew(sk2, VIR_NET_SERVER_SERVICE_AUTH_POLKIT, true, 66, # ifdef WITH_GNUTLS NULL, # endif NULL, NULL, NULL, NULL))) goto error; if (virNetServerAddClient(srv, cln1) < 0) goto error; if (virNetServerAddClient(srv, cln2) < 0) goto error; cleanup: virObjectUnref(cln1); virObjectUnref(cln2); virObjectUnref(svc1); virObjectUnref(svc2); return srv; error: virObjectUnref(srv); srv = NULL; goto cleanup; }