* Copyright (C) 1987 by the Massachusetts Institute of Technology
*
* $Log$
- * Revision 1.2 1987-05-31 22:03:23 wesommer
- * It's working better.
+ * Revision 1.3 1987-06-16 17:47:20 wesommer
+ * Clean up memory allocation, indenting.
*
+ * Revision 1.2 87/05/31 22:03:23 wesommer
+ * It's working better.
+ *
* Revision 1.1 87/05/20 03:11:18 wesommer
* Initial revision
*
int sms_auth()
{
- int status;
- sms_params *params = NULL, *reply = NULL;
- KTEXT_ST auth;
+ register int status;
+ sms_params params_st;
+ char *args[1];
+ int argl[1];
+
+ register sms_params *params = ¶ms_st;
+ sms_params *reply = NULL;
+ KTEXT_ST auth;
+
+ CHECK_CONNECTED;
- if (!_sms_conn) {
- return SMS_NOT_CONNECTED;
- }
+ /*
+ * Build a Kerberos authenticator.
+ * The "service" and "instance" should not be hardcoded here.
+ */
- /*
- * Build a Kerberos authenticator.
- */
+ status = mk_ap_req(&auth, "sms", "sms", "ATHENA.MIT.EDU", 0);
+ if (status != KSUCCESS) {
+ status += krb_err_base;
+ return status;
+ }
+ params->sms_procno = SMS_AUTH;
+ params->sms_argc = 1;
+ params->sms_argv = args;
+ params->sms_argl = argl;
+ params->sms_argv[0] = (char *)auth.dat;
+ params->sms_argl[0] = auth.length;
- status = mk_ap_req(&auth, "sms", "sms", "ATHENA.MIT.EDU", 0);
- if (status != KSUCCESS) {
- status += krb_err_base;
- goto punt;
- }
- params = (struct sms_params *) malloc(sizeof(*params));
- params->sms_procno = SMS_AUTH;
- params->sms_argc = 1;
+ if ((status = sms_do_call(params, &reply)) == 0)
+ status = reply->sms_status;
- params->sms_argv = (char **)malloc(sizeof(char *) * 2);
- params->sms_argl = (int *)malloc(sizeof(int) * 2);
- params->sms_argv[0] = (char *)auth.dat;
- params->sms_argl[0] = auth.length;
- params->sms_argv[1] = NULL;
- params->sms_argl[1] = 0;
-
- if ((status = sms_do_call(params, &reply)) || (status = reply->sms_status))
- goto punt;
-punt:
- sms_destroy_reply(reply);
-ok:
- if(params) {
- if(params->sms_argv)
- free(params->sms_argv);
- if(params->sms_argl)
- free(params->sms_argl);
- free(params);
- }
- return status;
+ sms_destroy_reply(reply);
+
+ return status;
}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */
* Copyright (C) 1987 by the Massachusetts Institute of Technology
*
* $Log$
- * Revision 1.4 1987-06-04 01:32:18 wesommer
- * Renamed gdb calls.
+ * Revision 1.5 1987-06-16 17:47:50 wesommer
+ * Clean up memory allocation, indenting.
*
- * Revision 1.3 87/06/01 03:33:54 wesommer
- * Added destroy_reply.
- *
- * Revision 1.2 87/05/31 22:03:37 wesommer
- * Fixed numerous bugs; still shaky.
- *
*/
#ifndef lint
#include "sms_private.h"
-/*
- * GDB operations to send and recieve RPC requests and replies.
- */
-
-static sms_abort_send() {}
-static sms_abort_recv() {}
-
-/*
- * This doesn't get called until after the actual buffered write completes.
- * In a non-preflattening version of this, this would then queue the
- * write of the next bunch of data.
- */
-
-sms_cont_send(op, hcon, arg)
- OPERATION op;
- HALF_CONNECTION hcon;
- struct sms_params *arg;
-{
- op->result = OP_SUCCESS;
- db_free(arg->sms_flattened, arg->sms_size);
-#ifdef notdef
- db_free(arg, sizeof(struct sms_params));
-#endif notdef
- return OP_COMPLETE;
-}
-
-sms_start_send(op, hcon, arg)
- OPERATION op;
- HALF_CONNECTION hcon;
- register struct sms_params *arg;
-{
- int sms_size, i, len;
- int *argl;
- char *buf, *bp;
-
- /*
- * This should probably be split into several routines.
- * It could also probably be made more efficient (punting most
- * of the argument marshalling stuff) by doing I/O directly
- * from the strings. Anyone for a scatter/gather sms_send_data?
- *
- * that would look a lot like the uio stuff in the kernel.. hmm.
- */
-
- /*
- * Marshall the entire data right now..
- * We are sending the version number,
- * total request size, request number,
- * argument count, and then each argument.
- * At least for now, each argument is a string, which is
- * sent as a count of bytes followed by the bytes
- * (including the trailing '\0'), padded
- * to a longword boundary.
- */
-
- sms_size = 4 * sizeof(long);
-
- argl = (int *)malloc(sizeof(int) * arg->sms_argc);
-
- /*
- * For each argument, figure out how much space is needed.
- */
-
- for (i = 0; i < arg->sms_argc; ++i) {
- if (arg->sms_argl)
- argl[i] = len = arg->sms_argl[i];
- else
- argl[i] = len = strlen(arg->sms_argv[i]) + 1;
- sms_size += sizeof(long) + len;
- sms_size += sizeof(long) * howmany(sms_size, sizeof(long));
- }
-
- arg->sms_flattened = buf = db_alloc(sms_size);
-
- bzero(arg->sms_flattened, sms_size);
-
- arg->sms_size = sms_size;
-
- /*
- * This is gross. Any better suggestions, anyone?
- * It should work on the RT's, since malloc is guaranteed to
- * return a pointer which is aligned correctly for any data.
- */
-
- ((long *)buf)[0] = htonl(sms_size);
- ((long *)buf)[1] = htonl(SMS_VERSION_1);
- ((long *)buf)[2] = htonl(arg->sms_procno);
- ((long *)buf)[3] = htonl(arg->sms_argc);
-
- /*
- * bp is a pointer into the point in the buffer to put
- * the next argument.
- */
-
- bp = (char *)(((long *)buf) + 4);
-
- for (i = 0; i<arg->sms_argc; ++i) {
- len = argl[i];
- *((long *)bp) = htonl(len);
- bp += sizeof(long);
- bcopy(arg->sms_argv[i], bp, len);
- bp += sizeof(long) * howmany(len, sizeof(long));
- }
- op->fcn.cont = sms_cont_send;
- arg->sms_size = sms_size;
-
- if (gdb_send_data(hcon, arg->sms_flattened, sms_size) == OP_COMPLETE)
- return sms_cont_send(op, hcon, arg);
- else return OP_RUNNING;
-}
-
-sms_cont_recv(op, hcon, argp)
- OPERATION op;
- HALF_CONNECTION hcon;
- sms_params **argp;
-{
- int done = FALSE;
- char *cp;
- int *ip;
- int i;
- register sms_params *arg = *argp;
-
- while (!done) {
- switch (arg->sms_state) {
- case S_RECV_START:
- arg->sms_state = S_RECV_DATA;
- if (gdb_receive_data(hcon, (caddr_t)&arg->sms_size,
- sizeof(long)) == OP_COMPLETE)
- continue;
- done = TRUE;
- break;
- case S_RECV_DATA:
- /* Should validate that length is reasonable */
- arg->sms_size = ntohl(arg->sms_size);
- arg->sms_flattened = db_alloc(arg->sms_size);
- arg->sms_state = S_DECODE_DATA;
- bcopy((caddr_t)&arg->sms_size, arg->sms_flattened, sizeof(long));
-
- if (gdb_receive_data(hcon,
- arg->sms_flattened + sizeof(long),
- arg->sms_size - sizeof(long))
- == OP_COMPLETE)
- continue;
- done = TRUE;
- break;
- case S_DECODE_DATA:
- cp = arg->sms_flattened;
- ip = (int *) cp;
- /* we already got the overall length.. */
- for(i=1; i <4; i++) ip[i] = ntohl(ip[i]);
- if (ip[1] != SMS_VERSION_1)
- arg->sms_status = SMS_VERSION_MISMATCH;
- else arg->sms_status = ip[2];
- arg->sms_argc = ip[3];
- cp += 4 * sizeof(int);
- arg->sms_argv=(char **)db_alloc(arg->sms_argc *sizeof(char **));
- arg->sms_argl=(int *)db_alloc(arg->sms_argc *sizeof(int *));
-
- for (i = 0; i<arg->sms_argc; ++i) {
- int nlen = ntohl(* (int *) cp);
- cp += sizeof (long);
- arg->sms_argv[i] = (char *)db_alloc(nlen);
- bcopy(cp, arg->sms_argv[i], nlen);
- arg->sms_argl[i]=nlen;
- cp += sizeof(long) *
- howmany(nlen, sizeof(long));
- }
- return OP_COMPLETE;
- }
- }
- return OP_RUNNING;
-}
-
-
-sms_start_recv(op, hcon, argp)
- OPERATION op;
- HALF_CONNECTION hcon;
- struct sms_params **argp;
-{
- register sms_params *arg = *argp;
- if (!arg) {
- *argp = arg = (sms_params *)db_alloc(sizeof(sms_params));
- arg->sms_argl = NULL;
- arg->sms_argv = NULL;
- arg->sms_flattened = NULL;
- }
- arg->sms_state = S_RECV_START;
- op->fcn.cont = sms_cont_recv;
- return sms_cont_recv(op, hcon, argp);
-}
-
-sms_do_call(parms, reply)
- struct sms_params *parms;
- struct sms_params **reply;
-{
- if (!_sms_conn)
- return SMS_NOT_CONNECTED;
-
- if (!_sms_send_op)
- _sms_send_op = create_operation();
-
- if (!_sms_recv_op)
- _sms_recv_op = create_operation();
-
- initialize_operation(_sms_send_op, sms_start_send, parms,
- sms_abort_send);
- queue_operation(_sms_conn, CON_OUTPUT, _sms_send_op);
-
- initialize_operation(_sms_recv_op, sms_start_recv, reply,
- sms_abort_recv);
- queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
-
- /* Block until operation done. */
- complete_operation(_sms_send_op);
- complete_operation(_sms_recv_op);
- /* Look at results */
- if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
- return SMS_ABORTED;
- }
- return 0;
-}
-
-sms_destroy_reply(reply)
- sms_params *reply;
+sms_do_call(params, reply)
+ struct sms_params *params;
+ struct sms_params **reply;
{
- int i;
- if (reply) {
- if (reply->sms_argl)
- free(reply->sms_argl);
- reply->sms_argl = NULL;
- if (reply->sms_flattened)
- free(reply->sms_flattened);
- reply->sms_flattened = NULL;
- if (reply->sms_argv) {
- for (i=0; i<reply->sms_argc; i++) {
- if (reply->sms_argv[i])
- free (reply->sms_argv[i]);
- reply->sms_argv[i] = NULL;
- }
- free(reply->sms_argv);
- }
- reply->sms_argv = NULL;
- free(reply);
- }
+ CHECK_CONNECTED;
+
+ if (!_sms_send_op)
+ _sms_send_op = create_operation();
+
+ if (!_sms_recv_op)
+ _sms_recv_op = create_operation();
+
+ initialize_operation(_sms_send_op, sms_start_send, (char *)params,
+ (int (*)())NULL);
+ queue_operation(_sms_conn, CON_OUTPUT, _sms_send_op);
+
+ initialize_operation(_sms_recv_op, sms_start_recv, (char *)reply,
+ (int (*)())NULL);
+ queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
+
+ /* Block until operation done. */
+ complete_operation(_sms_send_op);
+ complete_operation(_sms_recv_op);
+ /* Look at results */
+ if ((OP_STATUS(_sms_send_op) != OP_COMPLETE) ||
+ (OP_STATUS(_sms_recv_op) != OP_COMPLETE)) {
+ sms_disconnect();
+ return SMS_ABORTED;
+ }
+ return 0;
}
-
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */
int sms_connect()
{
- extern int errno;
+ extern int errno;
- if (!sms_inited) sms_init();
-
- /*
- * should do a hesiod call to find the sms machine name & service
- * number/name.
- */
- /* XXX gdb doesn't give real return codes. Can we trust errno?*/
- errno = 0;
- _sms_conn = start_server_connection(SMS_GDB_SERV, "");
- if (_sms_conn == NULL) {
- return errno;
- }
- return 0;
+ if (!sms_inited) sms_init();
+ if (_sms_conn) return SMS_ALREADY_CONNECTED;
+
+ /*
+ * * should do a hesiod call to find the sms machine name & service
+ * * number/name.
+ * */
+ /* XXX gdb doesn't give real return codes. Can we trust errno?*/
+ errno = 0;
+ _sms_conn = start_server_connection(SMS_GDB_SERV, "");
+ if (_sms_conn == NULL) {
+ return errno;
+ }
+ return 0;
}
int sms_disconnect()
{
- if (!_sms_conn) {
- return SMS_NOT_CONNECTED;
- }
- /* Is this guaranteed NOT to fail?? I don't believe it, but.. */
- _sms_conn = sever_connection(_sms_conn);
- return 0;
+ CHECK_CONNECTED;
+ _sms_conn = sever_connection(_sms_conn);
+ return 0;
}
int sms_noop()
{
- int status;
- struct sms_params *parms = NULL;
- struct sms_params *reply = NULL;
-
+ int status;
+ sms_params param_st;
+ struct sms_params *params = NULL;
+ struct sms_params *reply = NULL;
- parms = (struct sms_params *) malloc(sizeof(*parms));
-
- parms->sms_procno = SMS_NOOP;
- parms->sms_argc = 0;
- parms->sms_argl = NULL;
- parms->sms_argv = NULL;
-
- if ((status = sms_do_call(parms, &reply)) || (status = reply->sms_status))
- goto punt;
+ CHECK_CONNECTED;
+ params = ¶m_st;
+ params->sms_procno = SMS_NOOP;
+ params->sms_argc = 0;
+ params->sms_argl = NULL;
+ params->sms_argv = NULL;
+ if ((status = sms_do_call(params, &reply)) == 0)
+ status = reply->sms_status;
-punt:
- sms_destroy_reply(reply);
-ok:
- free(parms);
- return status;
-}
-
-int sms_shutdown(why)
- char *why;
-{
- int status;
- sms_params *parms=NULL;
- sms_params *reply=NULL;
+ sms_destroy_reply(reply);
- parms = (sms_params *) malloc(sizeof(*parms));
-
- parms->sms_procno = SMS_SHUTDOWN;
- parms->sms_argc = 1;
- parms->sms_argv = (char **)malloc(sizeof(char *) * 2);
- parms->sms_argv[0] = why;
- parms->sms_argv[1] = NULL;
- parms->sms_argl = NULL;
-
- if ((status = sms_do_call(parms, &reply)) || (status = reply->sms_status))
- goto punt;
-
-
-punt:
- sms_destroy_reply(reply);
-ok:
- if(parms) {
- if(parms->sms_argv)
- free(parms->sms_argv);
- free(parms);
- }
- return status;
+ return status;
}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */
* Private declarations of the SMS library.
*
* $Log$
- * Revision 1.2 1987-05-31 22:07:06 wesommer
- * Private data to the sms server and library.
+ * Revision 1.3 1987-06-16 17:48:39 wesommer
+ * Clean up memory allocation, indenting.
*
+ * Revision 1.2 87/05/31 22:07:06 wesommer
+ * Private data to the sms server and library.
+ *
* Revision 1.1 87/05/20 03:12:00 wesommer
* Initial revision
*
*/
-#include <stdio.h>
-#include <gdb.h>
-#include <sms.h>
-
-typedef struct sms_params {
- int sms_size;
- int sms_version_no;
- union {
- int procno; /* for call */
- int status; /* for reply */
- } u;
-#define sms_procno u.procno
-#define sms_status u.status
- int sms_argc;
- char **sms_argv;
- int *sms_argl;
- char *sms_flattened;
- int sms_state;
-} sms_params;
+#include "sms_proto.h"
extern CONNECTION _sms_conn;
-
extern OPERATION _sms_send_op, _sms_recv_op;
-extern int sms_start_recv(), sms_start_send();
-extern int sms_inited;
-#define SMS_GDB_SERV "sms:#8973"
+extern int sms_inited;
/*
* You are in a maze of twisty little FSM's, all different.
#define EVER (;;)
+#define CHECK_CONNECTED {if (!_sms_conn) return SMS_NOT_CONNECTED;}
+
+/*
+ * There should be an include file for these..
+ */
+
+extern char *malloc();
+#ifndef htonl
+extern u_long htonl(), ntohl();
+extern u_short htons(), ntohs();
+#endif htonl
+
+
+
* Copyright (C) 1987 by the Massachusetts Institute of Technology
*
* $Log$
- * Revision 1.1 1987-06-04 01:29:32 wesommer
- * Initial revision
+ * Revision 1.2 1987-06-16 17:48:58 wesommer
+ * Clean up memory allocation, indenting.
*
+ * Revision 1.1 87/06/04 01:29:32 wesommer
+ * Initial revision
+ *
*/
#ifndef lint
#include "sms_private.h"
+/*
+ * This routine is the primary external interface to the sms library.
+ *
+ * It builds a new argument vector with the query handle prepended,
+ * and calls sms_query_internal.
+ */
+
int sms_query(name, argc, argv, callproc, callarg)
- char *name; /* Query name */
- int argc; /* Arg count */
- char **argv; /* Args */
- int (*callproc)(); /* Callback procedure */
- char *callarg; /* Callback argument */
+ char *name; /* Query name */
+ int argc; /* Arg count */
+ char **argv; /* Args */
+ int (*callproc)(); /* Callback procedure */
+ char *callarg; /* Callback argument */
{
- int status;
- sms_params *params = NULL, *reply = NULL;
-
- if (!_sms_conn) {
- return SMS_NOT_CONNECTED;
- }
-
- params = (struct sms_params *) malloc(sizeof(*params));
- params->sms_procno = SMS_QUERY;
- params->sms_argc = 1 + argc;
- params->sms_argl = NULL;
+ register char **nargv = (char **)malloc(sizeof(char *) * (argc+1));
+ register int status = 0;
+ nargv[0] = name;
+ bcopy((char *)argv, (char *)(nargv+1), sizeof(char *) * argc);
+ status = sms_query_internal(argc+1, nargv, callproc, callarg);
+ free(nargv);
+ return status;
+}
+/*
+ * This routine makes an SMS query.
+ *
+ * argv[0] is the query name.
+ * argv[1..argc-1] are the query arguments.
+ *
+ * callproc is called once for each returned value, with arguments
+ * argc, argv, and callarg.
+ * If it returns a non-zero value, further calls to it are not done, and
+ * all future data from the server is ignored (there should be some
+ * way to send it a quench..)
+ */
- params->sms_argv = (char **)malloc(sizeof(char *) * params->sms_argc);
+int sms_query_internal(argc, argv, callproc, callarg)
+ int argc; /* Arg count */
+ char **argv; /* Args */
+ int (*callproc)(); /* Callback procedure */
+ char *callarg; /* Callback argument */
+{
+ int status;
+ sms_params params_st;
+ register sms_params *params = NULL;
+ sms_params *reply = NULL;
+ int stopcallbacks = 0;
+
+ CHECK_CONNECTED;
- params->sms_argv[0] = name;
- bcopy((char *)argv, (char *)(params->sms_argv + 1),
- sizeof(char *) * argc);
+ params = ¶ms_st;
+ params->sms_procno = SMS_QUERY;
+ params->sms_argc = argc;
+ params->sms_argl = NULL;
+ params->sms_argv = argv;
- if ((status = sms_do_call(params, &reply)))
- goto punt;
+ if ((status = sms_do_call(params, &reply)))
+ goto punt;
- while ((status = reply->sms_status) == SMS_MORE_DATA) {
+ while ((status = reply->sms_status) == SMS_MORE_DATA) {
+ if (!stopcallbacks)
+ stopcallbacks =
(*callproc)(reply->sms_argc, reply->sms_argv, callarg);
- sms_destroy_reply(reply);
- reply = NULL;
- /*XXX error handling here sucks */
- initialize_operation(_sms_recv_op, sms_start_recv, &reply,
- (int (*)())NULL);
- queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
- complete_operation(_sms_recv_op);
- }
-
-punt:
sms_destroy_reply(reply);
- if(params) {
- if(params->sms_argv)
- free(params->sms_argv);
- if(params->sms_argl)
- free(params->sms_argl);
- free(params);
+ reply = NULL;
+
+ initialize_operation(_sms_recv_op, sms_start_recv, &reply,
+ (int (*)())NULL);
+ queue_operation(_sms_conn, CON_INPUT, _sms_recv_op);
+
+ complete_operation(_sms_recv_op);
+ if (OP_STATUS(_sms_recv_op) != OP_COMPLETE) {
+ sms_disconnect();
+ return SMS_ABORTED;
}
- return status;
+ }
+punt:
+ sms_destroy_reply(reply);
+
+ return status;
}
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */