/*
* Command-line utility to transmit a server command.
*
- * Copyright (c) 1987-2012 by the citadel.org team
+ * 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.
* GNU General Public License for more details.
*/
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include "citadel.h"
-
-
+#include "include/citadel_dirs.h"
+#include <libcitadel.h>
int serv_sock = (-1);
-
int uds_connectsock(char *sockpath)
{
int s;
}
-
/*
* input string from socket - implemented in terms of serv_read()
*/
}
-
-
/*
* Main loop. Do things and have fun.
*/
{
int a;
int watchdog = 60;
- char *ctdl_home_directory = CTDLDIR;
char buf[SIZ];
int xfermode = 0;
+ int relh=0;
+ int home=0;
+ char relhome[PATH_MAX]="";
+ char ctdldir[PATH_MAX]=CTDLDIR;
+
+ StartLibCitadel(SIZ);
/* Parse command line */
while ((a = getopt(argc, argv, "h:w:")) != EOF) {
switch (a) {
case 'h':
- ctdl_home_directory = strdup(optarg);
+ relh=optarg[0]!='/';
+ if (!relh) {
+ strncpy(ctdl_home_directory, optarg, sizeof ctdl_home_directory);
+ } else {
+ strncpy(relhome, optarg, sizeof relhome);
+ }
+ home = 1;
break;
case 'w':
watchdog = atoi(optarg);
+ break;
default:
fprintf(stderr, "sendcommand: usage: sendcommand [-h server_dir] [-w watchdog_timeout]\n");
return(1);
}
}
- fprintf(stderr, "sendcommand: started (pid=%d) connecting to Citadel server in %s\n",
+ fprintf(stderr, "sendcommand: started (pid=%d) connecting to Citadel server at %s\n",
(int) getpid(),
- ctdl_home_directory
+ file_citadel_admin_socket
);
fflush(stderr);
alarm(watchdog);
- snprintf(buf, sizeof buf, "%s/citadel-admin.socket", ctdl_home_directory);
- serv_sock = uds_connectsock(buf);
-
+ serv_sock = uds_connectsock(file_citadel_admin_socket);
serv_gets(buf);
fprintf(stderr, "%s\n", buf);
xfermode = buf[0];
if ((xfermode == '4') || (xfermode == '8')) { /* send text */
- while (fgets(buf, sizeof buf, stdin)) {
- buf[strlen(buf)-1] = 0;
+ while (fgets(buf, sizeof buf, stdin) > 0) {
+ if (buf[strlen(buf)-1] == '\n') {
+ buf[strlen(buf)-1] = 0;
+ }
serv_puts(buf);
- alarm(watchdog); /* reset the watchdog timer */
}
serv_puts("000");
}
if ((xfermode == '1') || (xfermode == '8')) { /* receive text */
- while (serv_gets(buf), strcmp(buf, "000")) {
+ while(serv_gets(buf), strcmp(buf, "000")) {
printf("%s\n", buf);
- alarm(watchdog); /* reset the watchdog timer */
}
}