Changeset - 92659c5651ef
[Not reviewed]
default
1 23 0
Nathan Brink (binki) - 15 years ago 2010-07-22 00:03:45
ohnobinki@ohnopublishing.net
Reformed buildsystem.
- replace malloc.h with stdlib.h
- use AC_CONFIG_HEADERS for cleaner compile output
- clean out some useless AC_* macros and add useful AC_TYPE_UINT* macros
24 files changed with 95 insertions and 97 deletions:
0 comments (0 inline, 0 general)
configure.ac
Show inline comments
 
@@ -8,73 +8,62 @@
 
# (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 <http://www.gnu.org/licenses/>.
 

	
 
AC_PREREQ(2.61)
 
AC_INIT([distren],[0.0],[http://bugs.ohnopub.net/], [], [http://ohnopub.net/distren/])
 
AC_CONFIG_HEADERS([src/common/config.h])
 
AC_CONFIG_SRCDIR([src/server/distrend.c])
 
AC_CONFIG_MACRO_DIR([m4])
 

	
 
AC_PROG_CC
 
AC_PROG_LIBTOOL
 
#AC_PROG_RANLIB #don't add this even if autoscan says to, because AC_PROG_LIBTOOL is enough
 

	
 
AM_INIT_AUTOMAKE([gnu dist-bzip2 subdir-objects -Wall])
 
AM_PROG_CC_C_O
 

	
 
#basic low-level checks (suggested by autoscan)
 
AC_CHECK_FUNCS([dup2])
 
AC_CHECK_FUNCS([memset])
 
AC_CHECK_FUNCS([strdup])
 

	
 
AC_CHECK_HEADERS([fcntl.h])
 
AC_CHECK_HEADERS([malloc.h])
 

	
 
AC_FUNC_FORK
 
AC_FUNC_MALLOC
 

	
 
dnl these macros force the refered to types to be available without me
 
dnl writing my own magic :-)
 
AC_TYPE_PID_T
 
AC_TYPE_SIZE_T
 

	
 
# selective compilation
 
# For now, this is only left for when the C-based client is
 
# reintroducded.
 
AC_TYPE_UINT8_T
 
AC_TYPE_UINT16_T
 
AC_TYPE_UINT32_T
 

	
 
dnl selective compilation
 
dnl For now, this is only left for when the C-based client is
 
dnl reintroducded.
 
AC_ARG_ENABLE([server],
 
	[AS_HELP_STRING([--disable-server],[Don't build the distren server])],
 
	[enable_server=$enableval],
 
	[enable_server=yes])
 
AM_CONDITIONAL([ENABLE_SERVER],
 
	[test "x$enable_server" = "xyes"])
 

	
 
# to grab GNU-specific function prototypes for the following functions:
 
# getline
 
AC_DEFINE([_GNU_SOURCE], [1])
 
dnl package dependencies:
 

	
 
#package dependencies:
 

	
 
PKG_PROG_PKG_CONFIG(0.17.2)
 

	
 

	
 
PKGCONFIG_OHNOWRAP([DISTLIBS], [libconfuse >= 2.5 libcurl libxml-2.0 liblist >= 2.2.1 libarchive >= 2.8.0 ])
 
PKG_CHECK_MODULES([DISTLIBS], [libconfuse >= 2.5 libcurl libxml-2.0 liblist >= 2.3.1 libarchive >= 2.8.0])
 
AX_LIB_MYSQL
 
AS_IF( [test "x${MYSQL_VERSION}" = "x"],
 
	[ AC_MSG_ERROR([I need mysql]) ] )
 

	
 
PKGCONFIG_OHNOWRAP([CHECK], [check >= 0.9.3])
 
PKG_CHECK_MODULES([CHECK], [check >= 0.9.3])
 

	
 
# define paths for configuration files:
 
dnl define paths for configuration files until a better arrangement is
 
dnl made:
 

	
 
AC_DEFINE_DIR([LOCALSTATEDIR], [localstatedir], [Default directory for storing state information])
 
AC_DEFINE_DIR([RUNSTATEDIR], [localstatedir/run], [Default directory for registering runtime information like pid-files])
 

	
 
AC_CONFIG_FILES([Makefile
 
etc/distrendaemon.conf
 
etc/distrenslave.conf
 
	etc/distrendaemon.conf
 
	etc/distrenslave.conf
 
])
 

	
 
AC_OUTPUT
m4/pkgconfig_ohnowrap.m4
Show inline comments
 
deleted file
src/client/distren.c
Show inline comments
 
@@ -20,33 +20,34 @@
 

	
 
/* This code is meant to submit files to the distren server(s). Let's say server for now. And let's state file purpose in each file just so we don't get screwed up! */
 

	
 

	
 
/* Ideas for php-side stuff:
 
 *
 
 * PHP adds the users... has captcha and email confirmation wth a pseudo-random number that
 
 * the user must enter on the site. Apache should be running mod_peruser for safety, and I'm
 
 * thinking zserver2 for web serving for convenience...
 
 */
 

	
 

	
 
#include "common/config.h"
 

	
 
#include "distren.h"
 

	
 
#include <stdio.h> /* sprintf, printf */
 
#include <stdlib.h> /* malloc, free */
 
#include <unistd.h> /* getopt */
 
#include <confuse.h>
 
#include <string.h> // for strcat
 

	
 

	
 
int main(int argc, char *argv[])
 
{
 
  int doLogin = 0;
 

	
 
  char *input;
 
  char *output;
 
  char *jobid;
 

	
 
  char *username;
 
  char *password;
 

	
 
  char curopt;
src/client/libdistren.c
Show inline comments
 
@@ -12,28 +12,30 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
/*
 
  Implementation of distren_* functions from distren.h excluding distren_job_* functions.
 
 */
 

	
 
#include "common/config.h"
 

	
 
#include "libdistren.h"
 

	
 
#include <malloc.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 

	
 
/**
 
   @todo needs to read configuration in
 
 */
 
int distren_init_mf(distren_t *handle, distren_malloc_t mymalloc, distren_free_t myfree)
 
{
 
  if(!handle
 
     || !mymalloc
 
     || !myfree)
 
    {
 
      fprintf(stderr, "distren_init_mf passed NULL pointers\n");
 
      return 1;
src/client/libdistren_config.c
Show inline comments
 
@@ -12,24 +12,26 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
/*
 
  Functions and code for retrieving the client's configuration information.
 
 */
 

	
 
#include "common/config.h"
 

	
 
#include "client/libdistren.h"
 
#include "common/options.h"
 

	
 
/**
 
@todo Stub
 
 */
 
int _distren_getoptions(distren_t handle)
 
{
 
  cfg_t *cfg;
 

	
 
  cfg_opt_t cfg_opts[] =
 
    {
src/client/libdistren_job.c
Show inline comments
 
@@ -12,24 +12,26 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
/*
 
  Implementation of distren_job_* functions from distren.h.
 
 */
 

	
 
#include "common/config.h"
 

	
 
#include "libdistren.h"
 

	
 
/**
 
   @todo Stub
 
 */
 
int distren_job_getid(distren_job_t job, char **jobid)
 
{
 
  return 1;
 
}
 

	
 
/**
 
   @todo Stub
src/client/libdistren_unbias.c
Show inline comments
 
@@ -12,23 +12,25 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
/*
 
  Implementation of libdistren functions that exist to prevent this library from being biased toward certain methods of reporting errors/debug info or free()ing and malloc()ing
 
 */
 

	
 
#include "common/config.h"
 

	
 
#include "libdistren.h"
 

	
 
void *_malloc(distren_t distren, size_t size)
 
{
 
  return (*distren->malloc)(size);
 
}
 

	
 
void _free(distren_t distren, void *tofree)
 
{
 
  (*distren->free)(tofree);
 
}
src/common/asprintf.c
Show inline comments
 
@@ -8,24 +8,26 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <stdarg.h>
 
#include <string.h>
 

	
 
int _distren_asprintf(char **strp, const char *fmt, ...)
 
{
 
  va_list ap;
 
  size_t needed;
 

	
 
  va_start(ap, fmt);
 
  /**
src/common/execio.c
Show inline comments
 
@@ -8,33 +8,34 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "execio.h"
 
#include "common/config.h"
 

	
 
#include "common/execio.h"
 

	
 
#include <unistd.h>
 
#include <sys/types.h>
 
#ifndef _WIN32
 
#include <sys/wait.h>
 
#endif
 
#include <signal.h>
 
#include <malloc.h>
 
#include <fcntl.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <errno.h>
 

	
 
int execio_open(struct execio **rem, const char *progname, char *const argv[])
 
{
 
  /* pipe used to write to child */
 
  int pipe_write[2];
 
  /* pipe used to read from child */
 
  int pipe_read[2];
 

	
src/common/misc.c
Show inline comments
 
@@ -8,30 +8,32 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "common/misc.h"
 

	
 
#include <errno.h>
 
#include <malloc.h>
 
#include <unistd.h>
 
#include <stddef.h>
 
#include <stdlib.h>
 

	
 
char *distren_getcwd()
 
{
 
  char *mycwd;
 
  size_t counter;
 
  
 
  /**
 
     This is completely wrong, feel free to rewrite with
 
     pathconf() in mind.
 
   */
 
  for(counter = 128; ; counter +=32)
 
    {
src/common/multiio.c
Show inline comments
 
@@ -9,31 +9,33 @@
 
  (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 <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "common/multiio.h"
 

	
 
#include <list.h>
 
#include <fcntl.h>
 
#include <malloc.h>
 
#include <poll.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 

	
 
struct multiio_socket_info
 
{
 
  /* the type of socket */
 
  multiio_socket_type_t socket_type;
 
  /* to be passed to the socket handler */
 
  void *socket_data;
 
};
 

	
 
struct multiio_socket_type_info
 
{
src/common/options.c
Show inline comments
 
@@ -8,24 +8,26 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "common/options.h"
 

	
 
#include "common/asprintf.h"
 
#include "common/misc.h"
 
#include "common/multiio.h"
 
#include "common/libremoteio.h"
 
#include "common/protocol.h"
 

	
 
#include <confuse.h>
 
#include <string.h>
 
#include <stdio.h>
 
#include <stdlib.h>
src/common/protocol.c
Show inline comments
 
@@ -8,29 +8,31 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "protocol.h"
 
#include "remoteio.h"
 
#include "common/config.h"
 

	
 
#include <malloc.h>
 
#include "common/protocol.h"
 
#include "common/remoteio.h"
 

	
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 

	
 
#define DISTREN_REQUEST_MAGIC ((uint32_t)0x32423434)
 

	
 
int distren_request_new(struct distren_request **req, uint32_t len, enum distren_request_type type)
 
{
 
  struct distren_request *newreq;
 

	
 
  newreq = malloc(sizeof(struct distren_request));
 
  if(!newreq)
 
    {
 
      (*req) = NULL;
src/common/remoteio.c
Show inline comments
 
@@ -9,27 +9,29 @@
 
  (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 <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
#include "libremoteio.h"
 
#include "execio.h"
 
#include "asprintf.h"
 
#include "common/config.h"
 

	
 
#include "common/libremoteio.h"
 
#include "common/execio.h"
 
#include "common/asprintf.h"
 

	
 
#include <list.h>
 

	
 
#include <errno.h>
 
#ifndef _WIN32
 
#include <netdb.h>
 
#endif
 
#include <poll.h>
 
#include <stdlib.h>
 
#include <stdio.h>
 
#include <string.h>
 
#include <sys/types.h>
 
@@ -107,30 +109,30 @@ void remoteio_packet_free(struct remotei
 
int remoteio_config(cfg_t *cfg, struct remoteio_opts *opts)
 
{
 
  size_t numservers;
 
  size_t counter, counter2;
 
  static int haslisted_methods = 0;
 
  
 
  struct remoteio_server aserver;
 

	
 
  multiio_socket_type_register(opts->multiio, &opts->socket_type);
 

	
 
  multiio_event_handler_register(opts->multiio,
 
				 opts->socket_type,
 
				 POLLWRNORM,
 
				 POLLOUT,
 
				 (multiio_event_handler_func_t)&_remoteio_handle_write,
 
				 opts);
 
  multiio_event_handler_register(opts->multiio,
 
				 opts->socket_type,
 
				 POLLRDNORM,
 
				 POLLIN,
 
				 (multiio_event_handler_func_t)&_remoteio_handle_read,
 
				 opts);
 

	
 
  opts->servers = list_init();
 
  if(!opts->servers)
 
    {
 
      fprintf(stderr, "@todo cleanup!\n");
 
      abort();
 
    }
 
  
 
  numservers = cfg_size(cfg, "server");
 
  for(counter = 0; counter < numservers; counter ++)
 
@@ -215,25 +217,25 @@ int remoteio_open_socket(struct remoteio
 
			 struct remoteio_opts *opts,
 
			 remoteio_read_handle_func_t read_handler,
 
			 void *read_handler_data,
 
			 remoteio_close_handle_func_t close_handler,
 
			 int fd)
 
{
 
  struct remoteio *rem;
 
  if(remoteio_open_common(remoteio, REMOTEIO_METHOD_SOCKET, opts, read_handler, read_handler_data, close_handler))
 
    return 1;
 
  rem = *remoteio;
 

	
 
  rem->sock = fd;
 
  multiio_socket_add(opts->multiio, rem->sock, opts->socket_type, rem, POLLRDNORM);
 
  multiio_socket_add(opts->multiio, rem->sock, opts->socket_type, rem, POLLIN);
 

	
 
  return 0;
 
}
 

	
 
int remoteio_open_server(struct remoteio **remoteio,
 
			 struct remoteio_opts *opts,
 
			 remoteio_read_handle_func_t read_handler,
 
			 void *read_handler_data,
 
			 remoteio_close_handle_func_t close_handler,
 
			 const char *servername)
 
{
 
  struct remoteio_server *theserver;
 
@@ -272,25 +274,25 @@ int remoteio_open_server(struct remoteio
 
      free(rem->inbuf.data);
 
      q_free(rem->outmsgs, QUEUE_NODEALLOC);
 
      free(rem);
 
      *remoteio = NULL;
 
      return tmp;
 
    }
 

	
 
  /**
 
   * @todo make this code slightly more generic... able to handle
 
   * execio's multi-sockets by letting execio register itself with
 
   * multiio instead of us registering here perhaps
 
   */
 
  multiio_socket_add(opts->multiio, rem->sock, opts->socket_type, rem, POLLRDNORM);
 
  multiio_socket_add(opts->multiio, rem->sock, opts->socket_type, rem, POLLIN);
 
  
 
  return 0;
 
}
 

	
 
/**
 
 * Implementation of multiio_event_handler_func_t
 
 */
 
int _remoteio_handle_read(multiio_context_t multiio,
 
			  int fd,
 
			  short revent,
 
			  struct remoteio_opts *opts,
 
			  struct remoteio *rem)
 
@@ -362,28 +364,28 @@ int remoteio_write(struct remoteio *rem,
 
  ssize_t bytes_written;
 

	
 
  /**
 
   * This is probably about the only optimization that exists in
 
   * distren.... :-D
 
   *
 
   * Write to the client immediately if there are no other messages
 
   * waiting and if the client will accept it.
 
   */
 
  if(q_empty(rem->outmsgs))
 
    {
 
      pollfd.fd = rem->sock;
 
      pollfd.revents = POLLWRNORM;
 
      pollfd.revents = POLLOUT;
 
      pollfd.events = 0;
 
      poll(&pollfd, 1, 0);
 
      if(pollfd.events & POLLWRNORM)
 
      if(pollfd.events & POLLOUT)
 
	{
 
	  bytes_written = write(rem->sock, buf, len);
 
	  if(bytes_written > 0)
 
	    {
 
	      len -= bytes_written;
 
	      buf += bytes_written;
 
	    }
 
	}
 
    }
 

	
 
  /**
 
   * zero length is easy... and might be possible if the above
 
@@ -402,69 +404,69 @@ int remoteio_write(struct remoteio *rem,
 
  packet->len = len;
 
  packet->data = malloc(len);
 
  if(!packet->data)
 
    {
 
      free(packet);
 
      fprintf(stderr, "OOM\n");
 
      return 1;
 
    }
 

	
 
  memcpy(packet->data, buf, len);
 

	
 
  q_enqueue(rem->outmsgs, packet, 0);
 
  multiio_socket_event_enable(rem->opts->multiio, rem->sock, POLLWRNORM);
 
  multiio_socket_event_enable(rem->opts->multiio, rem->sock, POLLOUT);
 

	
 
  return 0;
 
}
 

	
 
int _remoteio_handle_write(multiio_context_t multiio,
 
			   int fd,
 
			   short revent,
 
			   struct remoteio_opts *opts,
 
			   struct remoteio *rem)
 
{
 
  struct remoteio_packet *packet;
 
  size_t written_amount;
 

	
 
  int tmp;
 

	
 
  fprintf(stderr, "%s:%d: <del>My</del><ins>Someone else's</ins> traversal says that sock %d is available for writing\n",
 
	  __FILE__, __LINE__, fd);
 

	
 
  /*
 
   * check if we're out of stuff to write.
 
   */
 
  if(q_empty(rem->outmsgs))
 
    {
 
      multiio_socket_event_disable(multiio, fd, POLLWRNORM);
 
      multiio_socket_event_disable(multiio, fd, POLLOUT);
 
      return 0;
 
    }
 

	
 
  packet = q_front(rem->outmsgs);
 
  tmp = funcmap[rem->method].write_func(rem, packet->data, packet->len, &written_amount);
 

	
 
  /**
 
     Disconnect in case of write error.
 
  */
 
  if(tmp)
 
    {
 
      fprintf(stderr, __FILE__ ":%d: error handling for write() needs to be inserted into remoteio.... perhaps.. ;-)\n", __LINE__);
 
    }
 
  if(packet->len == written_amount)
 
    {
 
      q_dequeue(rem->outmsgs);
 
      remoteio_packet_free(packet);
 

	
 
      if(q_empty(rem->outmsgs))
 
	multiio_socket_event_disable(multiio, fd, POLLWRNORM);
 
	multiio_socket_event_disable(multiio, fd, POLLOUT);
 
    }
 
  else
 
    {
 
      /**
 
       * shifting seems the simplest solution.
 
       */
 
      packet->len -= written_amount;
 
      memmove(packet->data, packet->data + written_amount, packet->len);
 
    }
 

	
 
  return 0;
 
}
src/common/request.c
Show inline comments
 
@@ -8,24 +8,26 @@
 
 * 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 <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#include "common/config.h"
 

	
 
#include "common/protocol.h"
 

	
 
#include <stdlib.h>
 
#include <string.h>
 

	
 
int distren_request_free_with_data(struct distren_request *req, void *data)
 
{
 
  free(data);
 
  return distren_request_free(req);
 
}
 

	
 
int distren_request_poing(struct distren_request **req, void **data, short is_ping, const void *poing_cookie, size_t poing_data_len)
src/server/distrend.c
Show inline comments
 
@@ -11,36 +11,37 @@
 
  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 <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
/* This file contains the code which both processes (renders) jobs as a slave, and the code which distributes frames to slaves after receiving them from the client portion of the codebase. */
 

	
 
#include "common/config.h"
 

	
 
#include "distrenjob.h"
 
#include "listen.h"
 
#include "slavefuncs.h"
 
#include "mysql.h"
 

	
 
#include "common/asprintf.h"
 
#include "common/execio.h"
 
#include "common/options.h"
 
#include "common/protocol.h"
 

	
 
#include <confuse.h>
 
#include <malloc.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <sys/stat.h>
 
#include <sys/types.h>
 
#include <time.h>
 
#include <unistd.h>
 

	
 
#include <libxml/encoding.h>
 
#include <libxml/parser.h>
 
#include <libxml/tree.h>
 
#include <libxml/xmlmemory.h>
src/server/distrenjob.c
Show inline comments
 
@@ -8,32 +8,35 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "distrenjob.h"
 
#include "slavefuncs.h"
 

	
 
#include "common/asprintf.h"
 

	
 
#include <libxml/parser.h>
 
#include <libxml/tree.h>
 
#include <libxml/xmlwriter.h>
 
#include <time.h>
 

	
 
void distrenjob_free(struct distrenjob **distrenjob)
 
{
 
  struct distrenjob *dj;
 

	
 
  dj = *distrenjob;
 
  xmlFree(dj->name);
 
  xmlFree(dj->submitter);
 

	
 
  free(dj->frameset);
 

	
 
  free(dj);
src/server/listen.c
Show inline comments
 
@@ -8,33 +8,36 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "listen.h"
 

	
 
#include "common/protocol.h"
 
#include "common/remoteio.h"
 

	
 
#include <errno.h>
 
#include <list.h>
 
#include <malloc.h>
 
#include <netinet/in.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <sys/types.h>
 
#include <poll.h>
 
#include <sys/socket.h>
 
#include <unistd.h>
 

	
 
/* local */
 

	
 
struct distrend_request_handler_info
 
{
 
  enum distren_request_type request_type;
 
  distrend_handle_request_func_t handler;
 
@@ -94,25 +97,25 @@ struct distrend_listens *distrend_listen
 
  listens->tabletennis = tabletennis_new(listens, 32, 16);
 

	
 
  /* This type is used for accepting connections with accept() */
 
  multiio_socket_type_register(multiio, &listens->socket_type);
 

	
 
  multiio_event_handler_register(multiio,
 
				 listens->socket_type,
 
				 POLLERR | POLLHUP | POLLNVAL,
 
				 (multiio_event_handler_func_t)&listen_handle_error,
 
				 listens);
 
  multiio_event_handler_register(multiio,
 
				 listens->socket_type,
 
				 POLLRDNORM,
 
				 POLLIN,
 
				 (multiio_event_handler_func_t)&listen_handle_accept,
 
				 listens);
 

	
 
  return listens;
 
}
 

	
 
int distrend_listen_add(struct distrend_listens *listens, int port)
 
{
 
  int tmp;
 
  int fd;
 
  int *saved_port;
 

	
 
@@ -147,25 +150,25 @@ int distrend_listen_add(struct distrend_
 
    }
 

	
 
  saved_port = malloc(sizeof(int));
 
  if(!saved_port)
 
    {
 
      perror("malloc");
 
      close(fd);
 

	
 
      return 1;
 
    }
 
  *saved_port = port;
 

	
 
  tmp = multiio_socket_add(listens->multiio, fd, listens->socket_type, saved_port, POLLRDNORM);
 
  tmp = multiio_socket_add(listens->multiio, fd, listens->socket_type, saved_port, POLLIN);
 
  if(tmp)
 
    {
 
      close(fd);
 

	
 
      return 1;
 
    }
 

	
 
  /**
 
   * @todo perhaps we'll someday want the ability to unlisten()? :-p
 
   * Then we have to store the fd somewheres so that we can call
 
   * multiio_socket_del() on it. So far, however, that functionality
 
   * isn't needed.
src/server/mysql.c
Show inline comments
 
@@ -9,24 +9,26 @@
 
  (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 <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "mysql.h"
 
#include <mysql/mysql.h>
 

	
 
#include "common/asprintf.h"
 
#include "common/protocol.h"
 

	
 
#include <stdio.h>
 
#include <string.h>
 
#include <unistd.h>
 
#include <stdlib.h>
 
#include <sys/stat.h>
 
#include <fcntl.h>
src/server/simpleslave.c
Show inline comments
 
@@ -9,24 +9,26 @@
 
  (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 <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "slavefuncs.h"
 

	
 
#include "common/asprintf.h"
 
#include "common/options.h"
 

	
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <sys/stat.h>
 
#include <unistd.h>
 

	
 
#define DEBUG 1
src/server/slave.c
Show inline comments
 
@@ -9,24 +9,26 @@
 
  (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 <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "slavefuncs.h"
 

	
 
#include "common/asprintf.h"
 
#include "common/multiio.h"
 
#include "common/options.h"
 
#include "common/protocol.h"
 
#include "common/remoteio.h"
 
#include "common/request.h"
 

	
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
src/server/slavefuncs.c
Show inline comments
 
@@ -8,24 +8,26 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "distrenjob.h"
 
#include "slavefuncs.h"
 

	
 
#include "common/asprintf.h"
 
#include "common/execio.h"
 
#include "common/protocol.h"
 
#include "common/remoteio.h"
 

	
 
#include <curl/curl.h>
 
#include <curl/easy.h>
 
#include <curl/types.h>
 

	
src/server/tabletennis.c
Show inline comments
 
@@ -8,24 +8,26 @@
 
 * 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 <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#include "common/config.h"
 

	
 
#include "distrend.h"
 
#include "listen.h"
 
#include "tabletennis.h"
 

	
 
#include "common/request.h"
 
#include "common/protocol.h"
 

	
 
#include <queue.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <time.h>
 

	
src/server/user_mgr.c
Show inline comments
 
@@ -8,37 +8,38 @@
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "common/config.h"
 

	
 
#include "user_mgr.h"
 

	
 
#include "common/asprintf.h"
 

	
 

	
 
#include <libxml/xmlmemory.h>
 
#include <libxml/parser.h>
 
#include <libxml/tree.h>
 
#include <libxml/encoding.h>
 
#include <libxml/xmlwriter.h>
 
#include <libxml/xmlreader.h>
 

	
 
#include <malloc.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <unistd.h>
 
#include <sys/stat.h>
 

	
 
struct user_mgr_info
 
{
 
	struct user *user_array;
 
	int current_users;
 
	int user_array_size;
 
} user_mgr_info;
 
@@ -71,36 +72,38 @@ int resize_user_array()
 
	// change the pointer to point to the new user array
 
	user_mgr_info.user_array = new_user_array;
 

	
 
	return 1;
 
}
 

	
 
struct user *findUser(char *nameOfUser)
 
{
 
	int high;
 
	int low;
 
	int middle;
 
	int result;
 

	
 
	high = user_mgr_info.user_array_size - 1;
 
	low = 0;
 
	result = -1;
 

	
 
	for(middle = (low+high)/2; 1 == 1; middle = (low+high)/2)
 
	{
 
		// in case middle lands on a part of the array with no user
 
		while(user_mgr_info.user_array[middle].username == 0)
 
		{
 
			if(result < 0)
 
				middle--;
 
				middle --;
 
			else
 
				middle++;
 
				middle ++;
 
		}
 

	
 
		// this is where the array is cut in half and the half that the nameOfUser is on is kept
 
		result = strcmp(nameOfUser, user_mgr_info.user_array[middle].username);
 
		if(result == 0)
 
			return &user_mgr_info.user_array[middle];
 
		else if(result < 0)
 
			high = middle;
 
		else
 
			low = middle;
 

	
 
		// in case the user doesn't exist
 
@@ -133,24 +136,26 @@ int createUser(struct user *user_ptr, ch
 
	user_mgr_info.current_users++;
 

	
 
	return 1;
 
}
 

	
 
// places the new user at position index in the array, moves other users if it needs to
 
int placeUser(int index, char *nameOfUser)
 
{
 
	int higher;
 
	int lower;
 
	int total_moves;
 

	
 
	total_moves = 0;
 

	
 
	// I shift data in the array to create an open the space where the user should be added
 
	// but first I figure out which way is the shortest
 
	if(user_mgr_info.user_array[index].username != 0)
 
	{
 
		higher = index + 1;
 
		while(user_mgr_info.user_array[higher].username != 0)
 
			higher++;
 

	
 
		lower = index - 1;
 
		while(user_mgr_info.user_array[lower].username != 0)
 
			lower--;
 

	
 
@@ -163,38 +168,40 @@ int placeUser(int index, char *nameOfUse
 
		  }
 
		else
 
		  {
 
		    total_moves = higher - index;
 
		    for(; higher > index; higher--)
 
				memcpy(&user_mgr_info.user_array[higher], &user_mgr_info.user_array[higher - 1], sizeof(struct user));
 
		  }
 
	}
 

	
 
	// add the user to the array
 
	createUser(&user_mgr_info.user_array[index], nameOfUser);
 

	
 
	if(total_moves > 50){
 
	if(total_moves > 50)
 
	  resize_user_array();
 
	}
 

	
 
	return 1;
 
}
 

	
 
int addUser(char *nameOfUser)
 
{
 
	int high;
 
	int low;
 
	int middle;
 
	int result;
 

	
 
	high = user_mgr_info.user_array_size - 1;
 
	low = 0;
 
	result = -1;
 

	
 
	for(middle = (low+high)/2; 1 == 1; middle = (low+high)/2)
 
	{
 
		// in case middle lands on a part of the array with no user
 
		while(user_mgr_info.user_array[middle].username == 0)
 
		{
 
			if(result < 0)
 
				middle--;
 
			else
 
				middle++;
 
		}
 

	
0 comments (0 inline, 0 general)