quvi_set: Add support for QUVI_OPTION_CALLBACK_STATUS_USERDATA
[libquvi.git] / src / net / resolve.c
blob43e75be7063e254b1f99e25222a7d8d16d230184
1 /* libquvi
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library 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 Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include <glib.h>
25 #include "quvi.h"
26 /* -- */
27 #include "_quvi_s.h"
28 #include "_quvi_macro.h"
29 #include "_quvi_net_resolve_s.h"
30 /* -- */
31 #include "net/resolve.h"
32 #include "net/handle.h"
34 extern QuviError c_resolve(_quvi_t, _quvi_net_resolve_t);
36 QuviError n_resolve(_quvi_t q, _quvi_net_resolve_t r)
38 QuviError rc = QUVI_OK;
40 if (q->cb.status != NULL)
42 const glong p = q_makelong(QUVI_CALLBACK_STATUS_RESOLVE, 0);
44 if (q->cb.status(p, 0) != QUVI_OK)
45 return (QUVI_ERROR_CALLBACK_ABORTED);
48 if (q->cb.resolve != NULL)
49 rc = q->cb.resolve(r);
50 else
51 rc = c_resolve(q, r);
53 if (rc == QUVI_OK)
55 if (q->cb.status != NULL)
57 const glong p = q_makelong(QUVI_CALLBACK_STATUS_RESOLVE,
58 QUVI_CALLBACK_STATUS_DONE);
60 if (q->cb.status(p, 0) != QUVI_OK)
61 rc = QUVI_ERROR_CALLBACK_ABORTED;
64 else
66 if (r->status.errmsg->len >0)
67 g_string_assign(q->status.errmsg, r->status.errmsg->str);
68 else
70 g_string_assign(q->status.errmsg,
71 "unknown error: callback returned empty errmsg");
75 q->status.resp_code = r->status.resp_code;
76 q->status.rc = rc;
78 return (rc);
81 /* vim: set ts=2 sw=2 tw=72 expandtab: */