Annotation of fam/fam/ServerConnection.c++, Revision 1.1
1.1 ! trev 1: // Copyright (C) 1999 Silicon Graphics, Inc. All Rights Reserved.
! 2: //
! 3: // This program is free software; you can redistribute it and/or modify it
! 4: // under the terms of version 2 of the GNU General Public License as
! 5: // published by the Free Software Foundation.
! 6: //
! 7: // This program is distributed in the hope that it would be useful, but
! 8: // WITHOUT ANY WARRANTY; without even the implied warranty of
! 9: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Further, any
! 10: // license provided herein, whether implied or otherwise, is limited to
! 11: // this program in accordance with the express provisions of the GNU
! 12: // General Public License. Patent licenses, if any, provided herein do not
! 13: // apply to combinations of this program with other product or programs, or
! 14: // any other product whatsoever. This program is distributed without any
! 15: // warranty that the program is delivered free of the rightful claim of any
! 16: // third person by way of infringement or the like. See the GNU General
! 17: // Public License for more details.
! 18: //
! 19: // You should have received a copy of the GNU General Public License along
! 20: // with this program; if not, write the Free Software Foundation, Inc., 59
! 21: // Temple Place - Suite 330, Boston MA 02111-1307, USA.
! 22:
! 23: #include "ServerConnection.h"
! 24:
! 25: #include <assert.h>
! 26: #include <ctype.h>
! 27: #include <stdlib.h>
! 28:
! 29: #include "Cred.h"
! 30: #include "Event.h"
! 31: #include "Log.h"
! 32:
! 33: ServerConnection::ServerConnection(int fd,
! 34: EventHandler eh, DisconnectHandler dh,
! 35: void *clos)
! 36: : NetConnection(fd, NULL, NULL),
! 37: event_handler(eh), disconnect_handler(dh), closure(clos)
! 38: {
! 39: assert(fd >= 0);
! 40: assert(eh);
! 41: assert(dh);
! 42: }
! 43:
! 44: bool
! 45: ServerConnection::input_msg(const char *msg, unsigned nbytes)
! 46: {
! 47:
! 48: // If there's an error parsing the message, then just forget about
! 49: // the message and return true. If we returned false, then the
! 50: // connection would go down, but the remote fam would notice and
! 51: // reconnect almost immediately, and send another bad message,
! 52: // which would result in thrashing on both ends.
! 53:
! 54: if (msg == NULL)
! 55: { (*disconnect_handler)(closure); // Disconnected.
! 56: return true;
! 57: }
! 58:
! 59: if (nbytes == 0 || msg[nbytes - 1])
! 60: { Log::debug("protocol error");
! 61: return true;
! 62: }
! 63:
! 64: char *p = (char *) msg;
! 65: char opcode = *p++;
! 66: Request request = strtol(p, &p, 10);
! 67: // If the opcode is "c", then the next part of the msg contains a
! 68: // list of character flags indicating what changed about the
! 69: // file. We currently ignore those flags.
! 70: //
! 71: if (opcode == 'c')
! 72: {
! 73: p++;
! 74: while (isascii(*p) && !isspace(*p))
! 75: p++;
! 76: }
! 77:
! 78: const Event *event = Event::getEventFromOpcode(opcode);
! 79:
! 80: // Skip over the space
! 81: p++;
! 82:
! 83: char name[PATH_MAX + 1];
! 84: int i;
! 85: for (i = 0; *p; i++)
! 86: { if (i >= PATH_MAX)
! 87: { Log::error("path name too long (%d chars)", i);
! 88: return true;
! 89: }
! 90: name[i] = *p++;
! 91: }
! 92: if ((i > 0) && (name[i - 1] != '\n'))
! 93: {
! 94: Log::error("path name doesn't end in newline");
! 95: return true;
! 96: }
! 97: name[i ? i - 1 : 0] = '\0'; // strip the trailing newline
! 98:
! 99: (*event_handler)(event, request, name, closure);
! 100: return true;
! 101: }
! 102:
! 103: void
! 104: ServerConnection::send_monitor(ClientInterest::Type code, Request request,
! 105: const char *path, const Cred& cr)
! 106: {
! 107:
! 108: const char * cred_buf = cr.getAddlGroupsString();
! 109: if (cred_buf[0])
! 110: mprintf("%c%d %d %d %s\n%c%s", code, request, cr.uid(), cr.gid(), path,
! 111: '\0', cred_buf);
! 112: else
! 113: mprintf("%c%d %d %d %s\n", code, request, cr.uid(), cr.gid(), path);
! 114: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>