f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose/*
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose SSSD
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Data Provider Process - Callback
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Authors:
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Stephen Gallagher <sgallagh@redhat.com>
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Sumit Bose <sbose@redhat.com>
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose Copyright (C) 2010 Red Hat
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose This program is free software; you can redistribute it and/or modify
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose it under the terms of the GNU General Public License as published by
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose the Free Software Foundation; either version 3 of the License, or
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose (at your option) any later version.
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose This program is distributed in the hope that it will be useful,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose GNU General Public License for more details.
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose You should have received a copy of the GNU General Public License
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose*/
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose#include "util/util.h"
cc2d77d5218c188119fa954c856e858cbde76947Pavel Březina#include "providers/backend.h"
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosestruct be_cb {
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb *prev;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb *next;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose be_callback_t cb;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose void *pvt;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina struct be_cb **list;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_ctx *be;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose};
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosestruct be_cb_ctx {
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_ctx *be;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb *callback;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose};
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosestatic int cb_destructor(TALLOC_CTX *ptr)
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose{
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb *cb = talloc_get_type(ptr, struct be_cb);
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina DLIST_REMOVE(*(cb->list), cb);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return 0;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose}
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosestatic int be_add_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose be_callback_t cb, void *pvt, struct be_cb **cb_list,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb **return_cb)
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose{
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb *new_cb;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose if (!ctx || !cb) {
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return EINVAL;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose new_cb = talloc(mem_ctx, struct be_cb);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose if (!new_cb) {
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return ENOMEM;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose new_cb->cb = cb;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose new_cb->pvt = pvt;
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina new_cb->list = cb_list;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose new_cb->be = ctx;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose DLIST_ADD(*cb_list, new_cb);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose talloc_set_destructor((TALLOC_CTX *) new_cb, cb_destructor);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose if (return_cb) {
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose *return_cb = new_cb;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return EOK;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose}
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosestatic void be_run_cb_step(struct tevent_context *ev, struct tevent_timer *te,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct timeval current_time, void *pvt)
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose{
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb_ctx *cb_ctx = talloc_get_type(pvt, struct be_cb_ctx);
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina struct be_cb *next_cb;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct tevent_timer *tev;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct timeval soon;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina /* Store next callback in case this callback frees itself */
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina next_cb = cb_ctx->callback->next;
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Call the callback */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose cb_ctx->callback->cb(cb_ctx->callback->pvt);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina if (next_cb) {
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina cb_ctx->callback = next_cb;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Delay 30ms so we don't block any other events */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose soon = tevent_timeval_current_ofs(0, 30000);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose tev = tevent_add_timer(cb_ctx->be->ev, cb_ctx, soon,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose be_run_cb_step,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose cb_ctx);
bb1487fef5d19a7b1536fc42e25a08f7d4c43e1bStephen Gallagher if (!tev) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Out of memory. Could not invoke callbacks\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose goto final;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosefinal:
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Steal the timer event onto the be_ctx so it doesn't
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose * get freed with the cb_ctx
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose talloc_steal(cb_ctx->be, te);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose talloc_free(cb_ctx);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose}
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
d2e2e5240c0da20d4091e7543ad8e7560be5f820Jakub Hrozekstatic errno_t be_run_cb(struct be_ctx *be, struct be_cb *cb_list)
d2e2e5240c0da20d4091e7543ad8e7560be5f820Jakub Hrozek{
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct timeval soon;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct tevent_timer *te;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose struct be_cb_ctx *cb_ctx;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina if (cb_list == NULL) {
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina return EOK;
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina }
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose cb_ctx = talloc(be, struct be_cb_ctx);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose if (!cb_ctx) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Out of memory. Could not invoke callbacks\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return ENOMEM;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose cb_ctx->be = be;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose cb_ctx->callback = cb_list;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Delay 30ms so we don't block any other events */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose soon = tevent_timeval_current_ofs(0, 30000);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose te = tevent_add_timer(be->ev, cb_ctx, soon,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose be_run_cb_step,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose cb_ctx);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose if (!te) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Out of memory. Could not invoke callbacks\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose talloc_free(cb_ctx);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return ENOMEM;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return EOK;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose}
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zelenyint be_add_reconnect_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny void *pvt, struct be_cb **reconnect_cb)
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny{
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny int ret;
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny ret = be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->reconnect_cb_list, reconnect_cb);
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_add_cb failed.\n");
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny return ret;
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny }
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny return EOK;
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny}
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zelenyvoid be_run_reconnect_cb(struct be_ctx *be)
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny{
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny struct be_cb *callback = be->reconnect_cb_list;
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina struct be_cb *next_cb;
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny if (callback) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Reconnecting. Running callbacks.\n");
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny /**
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny * Call the callback: we have to call this right away
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny * so the provider doesn't go into offline even for
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny * a little while
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny */
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny do {
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina /* Store next callback in case this callback frees itself */
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina next_cb = callback->next;
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny callback->cb(callback->pvt);
16c245e50e7aa763cff5fa93cc45febf8241319dPavel Březina callback = next_cb;
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny } while(callback != NULL);
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Reconnect call back list is empty, nothing to do.\n");
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny }
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny}
75ee7925a9e289bc24f0ce8a7988cca926b71513Jan Zeleny
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Boseint be_add_online_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose void *pvt, struct be_cb **online_cb)
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose{
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose int ret;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose ret = be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->online_cb_list, online_cb);
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_add_cb failed.\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return ret;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Make sure we run the callback for the first
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose * connection after startup.
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose ctx->run_online_cb = true;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose return EOK;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose}
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bosevoid be_run_online_cb(struct be_ctx *be) {
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose int ret;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
beb8badafcd17a279e910b1133e777c129166ce1Sumit Bose if (be->run_online_cb) {
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose /* Reset the flag. We only want to run these
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose * callbacks when transitioning to online
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose */
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose be->run_online_cb = false;
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
beb8badafcd17a279e910b1133e777c129166ce1Sumit Bose if (be->online_cb_list) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Going online. Running callbacks.\n");
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
beb8badafcd17a279e910b1133e777c129166ce1Sumit Bose ret = be_run_cb(be, be->online_cb_list);
beb8badafcd17a279e910b1133e777c129166ce1Sumit Bose if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_run_cb failed.\n");
beb8badafcd17a279e910b1133e777c129166ce1Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose
beb8badafcd17a279e910b1133e777c129166ce1Sumit Bose } else {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Online call back list is empty, nothing to do.\n");
beb8badafcd17a279e910b1133e777c129166ce1Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose }
f6085645026b9ee26e970d8f9a4e7b8cba077361Sumit Bose}
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Boseint be_add_unconditional_online_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx,
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose be_callback_t cb, void *pvt,
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose struct be_cb **unconditional_online_cb)
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose{
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose return be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->unconditional_online_cb_list,
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose unconditional_online_cb);
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose}
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bosevoid be_run_unconditional_online_cb(struct be_ctx *be)
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose{
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose int ret;
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose if (be->unconditional_online_cb_list) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Running unconditional online callbacks.\n");
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose ret = be_run_cb(be, be->unconditional_online_cb_list);
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "be_run_cb failed.\n");
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose }
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose } else {
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose DEBUG(SSSDBG_TRACE_ALL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "List of unconditional online callbacks is empty, " \
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "nothing to do.\n");
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose }
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose}
0a320004a9937295ba66a348d1e60682cfdceb26Sumit Bose
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Boseint be_add_offline_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose void *pvt, struct be_cb **offline_cb)
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose{
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose return be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->offline_cb_list, offline_cb);
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose}
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bosevoid be_run_offline_cb(struct be_ctx *be) {
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose int ret;
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose if (be->offline_cb_list) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Going offline. Running callbacks.\n");
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose ret = be_run_cb(be, be->offline_cb_list);
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "be_run_cb failed.\n");
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose }
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose } else {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_TRACE_ALL,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Offline call back list is empty, nothing to do.\n");
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose }
8eb2a35e3b180e76da4be5beab11cdb4038860b2Sumit Bose}