Moved from citadel.h to server.h
[citadel.git] / citadel / utils / sendcommand.c
index 7d8e089853fc1416e11739d8a29a23f3da922d06..6380f4eecb3a8d7ab8485bd5f7b6220716ee72f2 100644 (file)
@@ -1,16 +1,9 @@
-/*
- * Command-line utility to transmit a server command.
- *
- * Copyright (c) 1987-2021 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program 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 General Public License for more details.
- */
+// Command-line utility to transmit a server command.
+//
+// Copyright (c) 1987-2023 by the citadel.org team
+//
+// This program is open source software.  Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License, version 3.
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <limits.h>
 #include <sys/socket.h>
 #include <sys/un.h>
-#include "citadel.h"
-#include "citadel_dirs.h"
+#include "../server/citadel.h"
+#include "../server/server.h"
+#include "../server/citadel_dirs.h"
 #include <libcitadel.h>
 
 int serv_sock = (-1);
 
-int uds_connectsock(char *sockpath)
-{
+int uds_connectsock(char *sockpath) {
        int s;
        struct sockaddr_un addr;
 
@@ -57,11 +50,8 @@ int uds_connectsock(char *sockpath)
 }
 
 
-/*
- * input binary data from socket
- */
-void serv_read(char *buf, int bytes)
-{
+// input binary data from socket
+void serv_read(char *buf, int bytes) {
        int len, rlen;
 
        len = 0;
@@ -75,11 +65,8 @@ void serv_read(char *buf, int bytes)
 }
 
 
-/*
- * send binary to server
- */
-void serv_write(char *buf, int nbytes)
-{
+// send binary to server
+void serv_write(char *buf, int nbytes) {
        int bytes_written = 0;
        int retval;
        while (bytes_written < nbytes) {
@@ -92,59 +79,45 @@ void serv_write(char *buf, int nbytes)
 }
 
 
-/*
- * input string from socket - implemented in terms of serv_read()
- */
-void serv_gets(char *buf)
-{
+// input string from socket - implemented in terms of serv_read()
+void serv_gets(char *buf) {
        int i;
 
-       /* Read one character at a time.
-        */
+       // Read one character at a time.
        for (i = 0;; i++) {
                serv_read(&buf[i], 1);
                if (buf[i] == '\n' || i == (SIZ-1))
                        break;
        }
 
-       /* If we got a long line, discard characters until the newline.
-        */
+       // If we got a long line, discard characters until the newline.
        if (i == (SIZ-1)) {
                while (buf[i] != '\n') {
                        serv_read(&buf[i], 1);
                }
        }
 
-       /* Strip all trailing nonprintables (crlf)
-        */
+       // Strip all trailing nonprintables (crlf)
        buf[i] = 0;
 }
 
 
-/*
- * send line to server - implemented in terms of serv_write()
- */
-void serv_puts(char *buf)
-{
+// send line to server - implemented in terms of serv_write()
+void serv_puts(char *buf) {
        serv_write(buf, strlen(buf));
        serv_write("\n", 1);
 }
 
 
-/*
- * Main loop.  Do things and have fun.
- */
-int main(int argc, char **argv)
-{
+// Main loop.  Do things and have fun.
+int main(int argc, char **argv) {
        int a;
        int watchdog = 60;
        char buf[SIZ];
        int xfermode = 0;
        char ctdldir[PATH_MAX]=CTDLDIR;
 
-       StartLibCitadel(SIZ);
-
-       /* Parse command line */
+       // Parse command line
        while ((a = getopt(argc, argv, "h:w:")) != EOF) {
                switch (a) {
                case 'h':
@@ -190,7 +163,7 @@ int main(int argc, char **argv)
 
        xfermode = buf[0];
 
-       if ((xfermode == '4') || (xfermode == '8')) {           /* send text */
+       if ((xfermode == '4') || (xfermode == '8')) {           // send text
                while (fgets(buf, sizeof buf, stdin) > 0) {
                        if (buf[strlen(buf)-1] == '\n') {
                                buf[strlen(buf)-1] = 0;
@@ -200,13 +173,13 @@ int main(int argc, char **argv)
                serv_puts("000");
        }
 
-       if ((xfermode == '1') || (xfermode == '8')) {           /* receive text */
+       if ((xfermode == '1') || (xfermode == '8')) {           // receive text
                while(serv_gets(buf), strcmp(buf, "000")) {
                        printf("%s\n", buf);
                }
        }
        
-       if (xfermode == '6') {                                  /* receive binary */
+       if (xfermode == '6') {                                  // receive binary
                size_t len = atoi(&buf[4]);
                size_t bytes_remaining = len;
 
@@ -220,24 +193,11 @@ int main(int argc, char **argv)
        }
 
        close(serv_sock);
-       alarm(0);                                               /* cancel the watchdog timer */
+       alarm(0);                                               // cancel the watchdog timer
+
        fprintf(stderr, "sendcommand: processing ended.\n");
        if (xfermode == '5') {
                return(1);
        }
        return(0);
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-