libwbclient: Add async wbcPing_send/_recv
authorKai Blin <kai@samba.org>
Tue, 24 Mar 2009 21:51:11 +0000 (22:51 +0100)
committerKai Blin <kai@samba.org>
Thu, 11 Feb 2010 22:56:32 +0000 (23:56 +0100)
nsswitch/libwbclient/wbc_async.h
nsswitch/libwbclient/wbc_util.c

index 76e02cadf227afce1ca506ec70bc8bba3341674e..f3eab91633a7bad8b6fdde39e1920b923a1f2a26 100644 (file)
@@ -92,4 +92,12 @@ struct tevent_req *wb_simple_trans_send(TALLOC_CTX *mem_ctx,
 int wb_simple_trans_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
                         struct winbindd_response **presponse, int *err);
 
+/* Async functions from wbc_util.c */
+
+struct tevent_req *wbcPing_send(TALLOC_CTX *mem_ctx,
+                              struct tevent_context *ev,
+                              struct wb_context *wb_ctx);
+wbcErr wbcPing_recv(struct tevent_req *req);
+
+
 #endif /*_WBC_ASYNC_H_*/
index 24699e91c4f59c60c38bab39746ece0e8bedcd1d..ddef8b644d334f281c4c2d96ebb3c484efacd58b 100644 (file)
 
 
 
+struct wbc_ping_state {
+       struct winbindd_request req;
+};
+
+static void wbcPing_done(struct tevent_req *subreq);
+
+/** @brief Ping winbind to see if the service is up and running
+ *
+ * @param mem_ctx      talloc context to allocate the request from
+ * @param ev           event context to use for async operation
+ * @param wb_ctx       winbind context to use
+ *
+ * @return Async request on successful dispatch of the request, NULL on error
+ */
+
+struct tevent_req *wbcPing_send(TALLOC_CTX *mem_ctx,
+                               struct tevent_context *ev,
+                               struct wb_context *wb_ctx)
+{
+       struct tevent_req *req, *subreq;
+       struct wbc_ping_state *state;
+
+       req = tevent_req_create(mem_ctx, &state, struct wbc_ping_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       ZERO_STRUCT(state->req);
+
+       state->req.cmd = WINBINDD_PING;
+       subreq = wb_trans_send(state, ev, wb_ctx, false, &state->req);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       tevent_req_set_callback(subreq, wbcPing_done, req);
+       return req;
+}
+
+static void wbcPing_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+                       subreq, struct tevent_req);
+       struct wbc_ping_state *state = tevent_req_data(
+                       req, struct wbc_ping_state);
+       struct winbindd_response *resp;
+       wbcErr wbc_status;
+
+       wbc_status = wb_trans_recv(subreq, state, &resp);
+       TALLOC_FREE(subreq);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
+               tevent_req_error(req, wbc_status);
+               return;
+       }
+       TALLOC_FREE(resp);
+
+       tevent_req_done(req);
+}
+
+/** @brief Receive ping response from winbind
+ *
+ * @param req          async request sent in #wbcPing_send
+ *
+ * @return NT_STATUS_OK on success, an error status on error.
+ */
+
+wbcErr wbcPing_recv(struct tevent_req *req)
+{
+       wbcErr wbc_status;
+
+       if (tevent_req_is_wbcerr(req, &wbc_status)) {
+               tevent_req_received(req);
+               return wbc_status;
+       }
+
+       tevent_req_received(req);
+       return WBC_ERR_SUCCESS;
+}
+
 /** @brief Ping winbindd to see if the daemon is running
  *
  * @return #wbcErr
  **/
-
 wbcErr wbcPing(void)
 {
        struct winbindd_request request;