* Implement GNET/SNET commands in IPC code; provide a CtdlIPC_delete();
authorMichael Hampton <io_error@uncensored.citadel.org>
Fri, 12 Mar 2004 19:28:04 +0000 (19:28 +0000)
committerMichael Hampton <io_error@uncensored.citadel.org>
Fri, 12 Mar 2004 19:28:04 +0000 (19:28 +0000)
  emit warnings when client code uses CtdlIPC_getline() or CtdlIPC_putline()
  (These are reserved and should not be used by client code.)

citadel/ChangeLog
citadel/citadel_ipc.c
citadel/citadel_ipc.h

index 945eee18f52f1ceccfe42f59bd01eef8cc6fee86..d16b7cb67857a9479e8df7ae335d51417c8f0f0b 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 614.70  2004/03/12 19:28:04  error
+ * Implement GNET/SNET commands in IPC code; provide a CtdlIPC_delete();
+   emit warnings when client code uses CtdlIPC_getline() or CtdlIPC_putline()
+   (These are reserved and should not be used by client code.)
+
  Revision 614.69  2004/03/10 04:50:04  ajc
  * serv_expire.c: auto-purge any Citadel account that is associated with
    a Unix account that no longer exists.
@@ -5476,3 +5481,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index 87dbc631cd16a3de7b35d050ec13b50bf3c57345..7163617f1ce6f9ed7404bd584011b434a292210f 100644 (file)
@@ -77,6 +77,8 @@ static void endtls(SSL *ssl);
 static unsigned long id_callback(void);
 #endif /* THREADED_CLIENT */
 #endif /* HAVE_OPENSSL */
+/* static */ void CtdlIPC_getline(CtdlIPC* ipc, char *buf);
+/* static */ void CtdlIPC_putline(CtdlIPC *ipc, const char *buf);
 
 
 /*
@@ -118,13 +120,23 @@ int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret)
  */
 int CtdlIPCQuit(CtdlIPC *ipc)
 {
-       register int ret;
+       register int ret = 221;         /* Default to successful quit */
        char aaa[128];
 
        CtdlIPC_lock(ipc);
-       CtdlIPC_putline(ipc, "QUIT");
-       CtdlIPC_getline(ipc, aaa);
-       ret = atoi(aaa);
+       if (ipc->sock > -1) {
+               CtdlIPC_putline(ipc, "QUIT");
+               CtdlIPC_getline(ipc, aaa);
+               ret = atoi(aaa);
+       }
+#ifdef HAVE_OPENSSL
+       if (ipc->ssl)
+               SSL_shutdown(ipc->ssl);
+       ipc->ssl = NULL;
+#endif
+       if (ipc->sock)
+               shutdown(ipc->sock, 2); /* Close connection; we're dead */
+       ipc->sock = -1;
        CtdlIPC_unlock(ipc);
        return ret;
 }
@@ -1828,6 +1840,31 @@ int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
 }
 
 
+/* GNET */
+int CtdlIPCGetRoomNetworkConfig(CtdlIPC *ipc, char **listing, char *cret)
+{
+       size_t bytes;
+
+       if (!cret) return -2;
+       if (!listing) return -2;
+       if (*listing) return -2;
+
+       return CtdlIPCGenericCommand(ipc, "GNET", NULL, 0,
+                       listing, &bytes, cret);
+}
+
+
+/* SNET */
+int CtdlIPCSetRoomNetworkConfig(CtdlIPC *ipc, const char *listing, char *cret)
+{
+       if (!cret) return -2;
+       if (!listing) return -2;
+
+       return CtdlIPCGenericCommand(ipc, "SNET", listing, strlen(listing),
+                       NULL, NULL, cret);
+}
+
+
 /* REQT */
 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret)
 {
@@ -2765,7 +2802,7 @@ static unsigned long id_callback(void) {
 /*
  * input string from socket - implemented in terms of serv_read()
  */
-void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
+/* static */ void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
 {
        int i;
 
@@ -2786,11 +2823,15 @@ void CtdlIPC_getline(CtdlIPC* ipc, char *buf)
        if (buf[i] == 13) buf[i--] = 0;
 }
 
+void CtdlIPC_chat_recv(CtdlIPC* ipc, char* buf)
+{
+       return CtdlIPC_getline(ipc, buf);
+}
 
 /*
  * send line to server - implemented in terms of serv_write()
  */
-void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
+/* static */ void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
 {
        /* error_printf("< %s\n", buf); */
        serv_write(ipc, buf, strlen(buf));
@@ -2799,6 +2840,11 @@ void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
        ipc->last_command_sent = time(NULL);
 }
 
+void CtdlIPC_chat_send(CtdlIPC* ipc, const char* buf)
+{
+       return CtdlIPC_putline(ipc, buf);
+}
+
 
 /*
  * attach to server
@@ -2889,6 +2935,38 @@ CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf)
        return ipc;
 }
 
+
+/*
+ * Disconnect and delete the IPC class (destructor)
+ */
+void CtdlIPC_delete(CtdlIPC* ipc)
+{
+#ifdef HAVE_OPENSSL
+       if (ipc->ssl) {
+               SSL_shutdown(ipc->ssl);
+               SSL_free(ipc->ssl);
+               ipc->ssl = NULL;
+       }
+#endif
+       if (ipc->sock > -1) {
+               shutdown(ipc->sock, 2); /* Close it up */
+               ipc->sock = -1;
+       }
+       ifree(ipc);
+}
+
+
+/*
+ * Disconnect and delete the IPC class (destructor)
+ * Also NULLs out the pointer
+ */
+void CtdlIPC_delete_ptr(CtdlIPC** pipc)
+{
+       CtdlIPC_delete(*pipc);
+       *pipc = NULL;
+}
+
+
 /*
  * return the file descriptor of the server socket so we can select() on it.
  *
index 953c6337cc4170e4aec0fa2a77dee5d2d1d53a1b..dd34d3da7312a6d4fff2e796291b439d09c8d961 100644 (file)
@@ -81,10 +81,10 @@ CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf);
 void CtdlIPC_delete(CtdlIPC* ipc);
 /* Convenience destructor; also nulls out caller's pointer */
 void CtdlIPC_delete_ptr(CtdlIPC** pipc);
-/* Read a line from server, discarding newline */
-void CtdlIPC_getline(CtdlIPC* ipc, char *buf);
-/* Write a line to server, adding newline */
-void CtdlIPC_putline(CtdlIPC* ipc, const char *buf);
+/* Read a line from server, discarding newline, for chat, will go away */
+void CtdlIPC_chat_recv(CtdlIPC* ipc, char *buf);
+/* Write a line to server, adding newline, for chat, will go away */
+void CtdlIPC_chat_send(CtdlIPC* ipc, const char *buf);
 
 struct ctdlipcroom {
        char RRname[ROOMNAMELEN];       /* Name of room */
@@ -300,6 +300,8 @@ int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
                char **listing, char *cret);
 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
               const char *listing, char *cret);
+int CtdlIPCGetRoomNetworkConfig(CtdlIPC *ipc, char **listing, char *cret);
+int CtdlIPCSetRoomNetworkConfig(CtdlIPC *ipc, const char *listing, char *cret);
 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret);
 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret);
 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret);