22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
73 struct sockaddr_in address;
77 errstream = (
n_cgi) ? stdout : stderr;
79 *n_sockfd = socket(AF_INET, SOCK_STREAM, 0);
80 address.sin_family = AF_INET;
81 address.sin_addr.s_addr = inet_addr(server_ip);
82 address.sin_port = htons(atoi(port_address));
83 n_len =
sizeof(address);
85 n_result = connect(*n_sockfd, (
struct sockaddr *)&address, n_len);
89 fprintf(errstream,
"could not establish server connection\n");
91 fprintf(errstream,
"(1) Check the settings for the server IP address and the port. You can set these either on the command line or in your init file\n(2)The refdb server may be stopped or crashed or otherwise unwilling to process the request.\n(3) The machine running the server may be down or overloaded.\n");
118 errstream = (
n_cgi) ? stdout : stderr;
121 memset((
void*)scrambled_passwd, (
int)
'\0', (
size_t)(
PASSWD_LENGTH+1));
129 fprintf(errstream,
"could not write to refdbd\n");
137 fprintf(errstream,
"\n");
146 fprintf(errstream,
"could not read from refdbd\n");
150 if (strlen(inbuffer) != 12) {
152 fprintf(errstream,
"server error: incorrect scramble string\n");
158 fprintf(errstream,
"password encryption error\n");
188 int listvalue (
char* arg,
char* command,
char* help_string,
char* err_string,
int n_with_summary)
197 if (!command || !*command) {
202 errstream = (
n_cgi) ? stdout : stderr;
211 slvals.
outbuffer = malloc(strlen(arg) + strlen(command) + 128);
218 if (strncmp(arg,
"-h", 2) == 0) {
220 fprintf(errstream, help_string);
228 fprintf(errstream,
"could not connect to server\n");
233 strcpy(scrambled_passwd,
passwd);
237 fprintf(errstream,
"password transfer failed\n");
243 sprintf(slvals.
outbuffer,
"%s ", command);
259 strcat(slvals.
outbuffer, scrambled_passwd);
268 if (!retval && err_string && *err_string
269 && strncmp(slvals.
inbuffer, err_string, strlen(err_string)) == 0) {
298 size_t byte_written = 0;
301 int n_curr_trailing_z = 0;
302 int n_last_trailing_z = 0;
307 errstream = (
n_cgi) ? stdout : stderr;
315 fprintf(errstream,
"\n");
325 && cs_status != 803) {
328 fprintf(errstream,
"\n");
329 if (n_with_summary != 2) {
342 else if (slvals->
n_pipe) {
352 fprintf(stderr,
"could not read from refdbd. Stop\n");
366 if (n_curr_trailing_z >=
TERM_LEN) {
373 else if (n_curr_trailing_z == numbyte
374 && n_curr_trailing_z + n_last_trailing_z >=
TERM_LEN) {
380 else if (n_curr_trailing_z == numbyte) {
382 n_last_trailing_z += n_curr_trailing_z;
389 if (n_last_trailing_z) {
390 byte_written += fwrite(
cs_term,
sizeof(
char), n_last_trailing_z, pagerfp);
392 byte_written += fwrite(slvals->
inbuffer,
sizeof(
char), numbyte-n_curr_trailing_z, pagerfp);
395 if (n_read_done && n_with_summary ==1) {
400 && cs_status != 803) {
408 fprintf(stderr,
"could not read from refdbd. Stop\n");
417 n_last_trailing_z = n_curr_trailing_z;
419 }
while (!n_read_done);
423 fprintf(errstream,
"%d byte written to %s\n", byte_written, slvals->
outfile);
429 if (n_with_summary == 1) {
430 fprintf(errstream,
"%s", slvals->
inbuffer);
463 char *batchstring, *new_batchstring;
466 stringsize = strlen(s)+2;
467 batchstring = malloc(stringsize);
468 if (batchstring == NULL) {
471 strcpy(batchstring, s);
474 if ((new_batchstring =
mstrcat(batchstring, the_command, &stringsize, 0)) == NULL) {
479 batchstring = new_batchstring;
483 if (argv[optind] && argv[optind][0]) {
485 while (argv[i] && argv[i][0]) {
486 if ((new_batchstring =
mstrcat(batchstring,
" ", &stringsize, 0)) == NULL) {
491 batchstring = new_batchstring;
493 if ((new_batchstring =
mstrcat(batchstring, argv[i], &stringsize, 0)) == NULL) {
498 batchstring = new_batchstring;
530 int send_xml_data(FILE *infp, FILE *pagerfp, FILE *errstream,
int n_sockfd,
size_t* ptr_byte_written) {
531 int n_style_file_done = 0;
534 int n_chunk_count = 0;
545 buffer = malloc(n_chunksize);
546 if (buffer == NULL) {
559 n_result = fread(buffer, 1, n_chunksize, infp);
563 if (n_result < n_chunksize && !feof(infp)) {
566 fprintf(errstream,
"\n");
571 else if (n_result < n_chunksize) {
579 sprintf(thebytes,
"%d", n_result);
585 fprintf(errstream,
"could not write to refdbd. Stop\n");
595 fprintf(errstream,
"\n");
602 numbyte =
iwrite(n_sockfd, buffer, n_result);
605 fprintf(errstream,
"could not write to refdbd. Stop\n");
616 if (cs_status == 400) {
635 *ptr_byte_written += fwrite(inbuffer,
sizeof(
char), numbyte-num_trailz, pagerfp);
638 }
while (!n_read_done);
649 }
while (!n_style_file_done);
689 int send_ris_data(FILE *infp, FILE *pagerfp, FILE *errstream,
int n_sockfd,
char** ptr_ris_set_buffer,
size_t* ptr_n_setlength,
int* ptr_n_setcount,
char*
default_ris,
int n_cgi,
size_t* ptr_byte_written) {
692 int n_ris_file_done = 0;
696 char thebytes[11] =
"";
705 (*ptr_ris_set_buffer)[0] =
'\0';
707 n_result =
read_ris_set(infp, default_ris, ptr_ris_set_buffer, ptr_n_setlength, 0);
712 fprintf(errstream,
"\n");
716 else if (n_result == 2) {
728 sprintf(thebytes,
"%d", *ptr_n_setlength);
734 fprintf(errstream,
"could not write to refdbd. Stop\n");
743 fprintf(errstream,
"\n");
750 numbyte =
iwrite(n_sockfd, *ptr_ris_set_buffer, *ptr_n_setlength);
753 fprintf(errstream,
"could not write to refdbd. Stop\n");
768 || cs_status == 702) {
787 *ptr_byte_written += fwrite(inbuffer,
sizeof(
char), numbyte-num_trailz, pagerfp);
791 }
while (!n_read_done);
794 || cs_status == 702) {
806 }
while (!n_ris_file_done);
828 int n_curr_trailing_z = 0;
829 int n_last_trailing_z = 0;
830 size_t byte_written = 0;
837 if (n_curr_trailing_z) {
846 fprintf(stderr,
"\n");
854 if (n_curr_trailing_z >=
TERM_LEN) {
857 n_last_trailing_z = 0;
867 else if (n_curr_trailing_z == numbyte
868 && n_curr_trailing_z + n_last_trailing_z >=
TERM_LEN) {
870 n_last_trailing_z = 0;
876 else if (n_curr_trailing_z == numbyte) {
879 n_last_trailing_z += n_curr_trailing_z;
886 if (n_last_trailing_z) {
888 byte_written += fwrite(
cs_term,
sizeof(
char), n_last_trailing_z, pagerfp);
891 byte_written += fwrite(ptr_slvals->
inbuffer,
sizeof(
char), numbyte-n_curr_trailing_z, pagerfp);
897 n_last_trailing_z = n_curr_trailing_z;
899 }
while (!n_read_done);
936 fprintf(stderr,
"aborting...\n");