ctl_srvr.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
static const char rcsid[] = "$Id: ctl_srvr.c,v 8.26 2002/07/08 05:10:25 marka Exp $";
#endif /* not lint */
/*
* Copyright (c) 1998,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Extern. */
#include "port_before.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <isc/assertions.h>
#include <isc/eventlib.h>
#include <isc/memcluster.h>
#include "ctl_p.h"
#include "port_after.h"
#ifdef SPRINTF_CHAR
#else
#endif
/* Macros. */
/* Types. */
enum state {
};
union sa_un {
struct sockaddr_in in;
#ifndef NO_SOCKADDR_UN
struct sockaddr_un un;
#endif
};
struct ctl_sess {
int sock;
const void * respctx;
void * uap;
void * csctx;
};
struct ctl_sctx {
void * uctx;
int sock;
int max_sess;
int cur_sess;
};
/* Forward. */
static void ctl_accept(evContext, void *, int,
const void *, int,
const void *, int);
static void ctl_new_state(struct ctl_sess *,
enum state,
const char *);
static void ctl_start_read(struct ctl_sess *);
static void ctl_stop_read(struct ctl_sess *);
static void ctl_readable(evContext, void *, int, int);
static void ctl_rdtimeout(evContext, void *,
struct timespec,
struct timespec);
static void ctl_wrtimeout(evContext, void *,
struct timespec,
struct timespec);
static void ctl_docommand(struct ctl_sess *);
static void ctl_writedone(evContext, void *, int, int);
static void ctl_morehelp(struct ctl_sctx *,
struct ctl_sess *,
const struct ctl_verb *,
const char *,
u_int, const void *, void *);
static void ctl_signal_done(struct ctl_sctx *,
struct ctl_sess *);
/* Private data. */
static const char * state_names[] = {
"available", "initializing", "writing", "reading",
"reading_data", "processing", "idling", "quitting", "closing"
};
static const char space[] = " ";
static const struct ctl_verb fakehelpverb = {
};
/* Public. */
/*
* void
* ctl_server()
* create, condition, and start a listener on the control port.
*/
struct ctl_sctx *
{
static const char me[] = "ctl_server";
static const int on = 1;
int save_errno;
logger = ctl_logger;
connverb++)
break;
return (NULL);
}
return (NULL);
}
}
save_errno = errno;
errno = save_errno;
return (NULL);
}
return (NULL);
}
#ifdef NO_UNIX_REUSEADDR
#endif
"%s: setsockopt(REUSEADDR): %s",
}
save_errno = errno;
errno = save_errno;
return (NULL);
}
}
save_errno = errno;
errno = save_errno;
return (NULL);
}
return (ctx);
}
/*
* void
* ctl_endserver(ctx)
* if the control listener is open, close it. clean out all eventlib
* stuff. close all active sessions.
*/
void
static const char me[] = "ctl_endserver";
}
}
}
}
/*
* If body is non-NULL then it we add a "." line after it.
* Caller must have escaped lines with leading ".".
*/
void
{
static const char me[] = "ctl_response";
int n;
me, address_expr);
goto untimely;
}
me, address_expr);
goto untimely;
}
text));
*pc = '\040';
char *tmp;
}
goto untimely;
}
{
goto untimely;
}
return;
}
}
void
static const char me[] = "ctl_sendhelp";
}
void *
}
void *
return (old);
}
/* Private functions. */
static void
{
static const char me[] = "ctl_accept";
if (fd < 0) {
return;
}
return;
}
return;
}
}
else
}
static void
{
static const char me[] = "ctl_new_state";
}
static void
static const char me[] = "ctl_close";
}
}
}
}
static void
static const char me[] = "ctl_start_read";
{
return;
}
return;
}
}
static void
static const char me[] = "ctl_stop_read";
}
}
static void
static const char me[] = "ctl_readable";
ssize_t n;
me, address_expr);
return;
}
if (n <= 0) {
return;
}
} else {
}
else
return;
}
me, address_expr);
}
}
static void
{
static const char me[] = "ctl_wrtimeout";
me, address_expr);
}
}
static void
{
static const char me[] = "ctl_rdtimeout";
me, address_expr);
}
static void
static const char me[] = "ctl_docommand";
if (*rest != '\0') {
*rest++ = '\0';
}
verb++)
break;
} else {
char buf[1100];
if (sizeof "Unrecognized command \"\" (args \"\")" +
else
"Unrecognized command \"%s\" (args \"%s\")",
NULL, 0);
}
}
static void
static const char me[] = "ctl_writedone";
int save_errno = errno;
if (bytes < 0) {
return;
}
return;
} else {
}
}
static void
{
if (lastverb_p(next))
}
static void
}
}