/* Copyright 2010 Nathan Phillip Brink, Ethan Zonca, Matt Orlando This file is a part of DistRen. DistRen is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. DistRen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with DistRen. If not, see . */ #ifndef LIBDISTREN_H_ #define LIBDISTREN_H_ 1 /* Private definitions for libdistren. */ #include "distren.h" #include "common/multiio.h" #include "common/options.h" #include "common/remoteio.h" #include enum distren_state { /** * client is waiting for a VERSION packet from the server. */ DISTREN_STATE_VERSION, /** * We are waiting to be authenticated. */ DISTREN_STATE_AUTH, DISTREN_STATE_NORMAL, }; struct distren { struct options_common *options; char *server; enum distren_state state; /* * If rem is NULL, we're not connected to the server. This is the * way to detect a communication error. */ struct remoteio *rem; /* * for libdistren_remoteio_read_handle(): determine whether or not * we've passed through the server's hacky MOTD */ short done_ad; /* * The servertype bitmask of the remote server. */ uint32_t servertype; /* something on which to call multiio_poll() ;-) */ multiio_context_t multiio; /* * The last-used per-connection DISTREN_REQUEST_FILE_POST * identifier. */ uint32_t file_post_id; }; struct distren_job { char *joburi; }; /* functions */ /** Avoid poluting the public namespace until we fix visibility. */ #define _malloc _distren_malloc /** All of libdistren should use this rather than malloc.h's malloc. */ void *_malloc(distren_t distren, size_t size); /** Avoid poluting the public namespace until we fix visibility. */ #define _free _distren_free /** All of libdisren should use this instead of malloc.h's free() */ void _free(distren_t distren, void *tofree); /** * Sets up the distren handle with information garnered from * configuration files, etc. Uses the environment variable * DISTREN_CONFIG or the built-in default config file location. * * Also initializes multiio. */ int _distren_getoptions(distren_t handle); /** * Unsets-up the distren handle with options loadable from a config file. * * Also unloads multiio. */ int _distren_loseoptions(distren_t handle); /** * Handle newly read data. * * Matches remoteio_read_handle_func_t */ size_t libdistren_remoteio_read_handle(struct remoteio *rem, void *garbage, void *buf, size_t len, distren_t distren); /** * React to a remoteio-based connection closing. * * Matches remoteio_close_handle_func_t */ void libdistren_remoteio_close_handle(void *garbage, distren_t distren); #endif