LCOV - code coverage report
Current view: top level - lib/util - tevent_werror.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 16 38 42.1 %
Date: 2021-09-23 10:06:22 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Wrap win32 errors around tevent_req
       4             :    Copyright (C) Kai Blin 2010
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "../replace/replace.h"
      21             : #include "tevent_werror.h"
      22             : #include "libcli/util/error.h"
      23             : 
      24      423985 : bool _tevent_req_werror(struct tevent_req *req,
      25             :                         WERROR werror,
      26             :                         const char *location)
      27             : {
      28      423985 :         return _tevent_req_error(req, W_ERROR_V(werror),
      29             :                                  location);
      30             : }
      31             : 
      32      313564 : bool tevent_req_is_werror(struct tevent_req *req, WERROR *error)
      33             : {
      34             :         enum tevent_req_state state;
      35             :         uint64_t err;
      36             : 
      37      313564 :         if (!tevent_req_is_error(req, &state, &err)) {
      38      163903 :                 return false;
      39             :         }
      40      149353 :         switch (state) {
      41           0 :         case TEVENT_REQ_TIMED_OUT:
      42           0 :                 *error = WERR_TIMEOUT;
      43           0 :                 break;
      44           0 :         case TEVENT_REQ_NO_MEMORY:
      45           0 :                 *error = WERR_NOT_ENOUGH_MEMORY;
      46           0 :                 break;
      47      149353 :         case TEVENT_REQ_USER_ERROR:
      48      149353 :                 *error = W_ERROR(err);
      49      149353 :                 break;
      50           0 :         default:
      51           0 :                 *error = WERR_INTERNAL_ERROR;
      52           0 :                 break;
      53             :         }
      54      149353 :         return true;
      55             : }
      56             : 
      57       36608 : WERROR tevent_req_simple_recv_werror(struct tevent_req *req)
      58             : {
      59             :         WERROR werror;
      60             : 
      61       36608 :         if (tevent_req_is_werror(req, &werror)) {
      62           6 :                 tevent_req_received(req);
      63           6 :                 return werror;
      64             :         }
      65       36602 :         tevent_req_received(req);
      66       36602 :         return WERR_OK;
      67             : }
      68             : 
      69           0 : void tevent_req_simple_finish_werror(struct tevent_req *subreq,
      70             :                                      WERROR subreq_error)
      71             : {
      72           0 :         struct tevent_req *req = tevent_req_callback_data(
      73             :                 subreq, struct tevent_req);
      74             : 
      75           0 :         TALLOC_FREE(subreq);
      76             : 
      77           0 :         if (!W_ERROR_IS_OK(subreq_error)) {
      78           0 :                 tevent_req_werror(req, subreq_error);
      79           0 :                 return;
      80             :         }
      81           0 :         tevent_req_done(req);
      82             : }
      83             : 
      84           0 : bool tevent_req_poll_werror(struct tevent_req *req,
      85             :                             struct tevent_context *ev,
      86             :                             WERROR *err)
      87             : {
      88           0 :         bool ret = tevent_req_poll(req, ev);
      89           0 :         if (!ret) {
      90           0 :                 NTSTATUS status = map_nt_error_from_unix_common(errno);
      91           0 :                 *err = ntstatus_to_werror(status);
      92             :         }
      93           0 :         return ret;
      94             : }

Generated by: LCOV version 1.13