297{
298 char str[1000], text[10000], uname[80], upwd[80];
299 char host_name[256], logbook[32], textfile[256], password[80];
302 INT i,
n, fh, n_att, n_attr, size, port;
304
305 text[0] = textfile[0] = uname[0] = upwd[0] = 0;
306 host_name[0] = logbook[0] = password[0] = n_att = n_attr = 0;
307 port = 80;
309 attachment[
i][0] = 0;
312 }
313
314
315 for (
i = 1;
i < argc;
i++) {
316 if (argv[
i][0] ==
'-' && argv[
i][1] ==
'v')
318 else {
319 if (argv[
i][0] ==
'-') {
320 if (
i + 1 >= argc || argv[
i + 1][0] ==
'-')
322 if (argv[
i][1] ==
'h')
324 else if (argv[
i][1] ==
'p')
325 port = atoi(argv[++
i]);
326 else if (argv[
i][1] ==
'l')
327 strcpy(logbook, argv[++
i]);
328 else if (argv[
i][1] ==
'w')
329 strcpy(password, argv[++
i]);
330 else if (argv[
i][1] ==
'u') {
331 strcpy(uname, argv[++
i]);
332 strcpy(upwd, argv[++
i]);
333 }
else if (argv[
i][1] ==
'a') {
334 strcpy(
str, argv[++
i]);
335 if (strchr(
str,
'=')) {
336 strcpy(attrib[n_attr], strchr(
str,
'=') + 1);
337 *strchr(
str,
'=') = 0;
338 strcpy(attr_name[n_attr],
str);
339 n_attr++;
340 } else {
341 printf
342 ("Error: Attributes must be supplied in the form \"-a <attribute>=<value>\".\n");
343 return 0;
344 }
345 }
else if (argv[
i][1] ==
'f')
346 strcpy(attachment[n_att++], argv[++
i]);
347 else if (argv[
i][1] ==
'm')
348 strcpy(textfile, argv[++
i]);
349 else {
351 printf("\nusage: elog -h <hostname> [-p port]\n");
352 printf(" [-l logbook/experiment]\n");
353 printf(" [-v] for verbose output\n");
354 printf
355 (" [-w password] write password defined on server\n");
356 printf(" [-u username password] user name and password\n");
357 printf(" [-f <attachment>] (up to %d times)\n",
359 printf(" -a <attribute>=<value> (up to %d times)\n",
361 printf(" -m <textfile>] | <text>\n");
362 printf("\nArguments with blanks must be enclosed in quotes\n");
363 printf("The elog message can either be submitted on the command line\n");
364 printf
365 ("or in a file with the -m flag. Multiple attributes and attachments\n");
366 printf("can be supplied\n");
367 return 0;
368 }
369 } else
370 strcpy(text, argv[
i]);
371 }
372 }
373
374 if (
host_name[0] == 0 || n_attr == 0 || (text[0] == 0 && textfile[0] == 0))
376
377
378
379 if (textfile[0]) {
380 fh = open(textfile, O_RDONLY |
O_BINARY);
381 if (fh < 0) {
382 printf("Message file \"%s\" does not exist.\n", textfile);
383 return 0;
384 }
385
386 size = lseek(fh, 0, SEEK_END);
387 lseek(fh, 0, SEEK_SET);
388
389 if (size > (int)sizeof(text) - 1) {
390 printf("Message file \"%s\" is too long (%d bytes max).\n", textfile,
391 (int)sizeof(text));
392 return 0;
393 }
394
395 memset(text, 0, sizeof(text));
396 i =
read(fh, text, size);
398 printf("Cannot fully read message file \"%s\".\n", textfile);
399 return 0;
400 }
401
402 close(fh);
403 }
404
405
406
408 if (!attachment[
i][0])
409 break;
410
411 fh = open(attachment[
i], O_RDONLY |
O_BINARY);
412 if (fh < 0) {
413 printf(
"Attachment file \"%s\" does not exist.\n", attachment[
i]);
414 return 0;
415 }
416
417 att_size[
i] = lseek(fh, 0, SEEK_END);
418 lseek(fh, 0, SEEK_SET);
419
420 buffer[
i] = (
char*)malloc(att_size[
i] + 1);
421 if (buffer[
i] == NULL || att_size[
i] > 500 * 1024) {
422 printf(
"Attachment file \"%s\" is too long (500k max).\n", attachment[
i]);
423 return 0;
424 }
425
426 n =
read(fh, buffer[
i], att_size[
i]);
427 if (
n < att_size[
i]) {
428 printf(
"Cannot fully read attachment file \"%s\".\n", attachment[
i]);
429 return 0;
430 }
432
433 close(fh);
434 }
435
436
438 uname, upwd,
439 attr_name, attrib, n_attr, text, attachment, buffer, att_size);
440
444
445 return 1;
446}
char host_name[HOST_NAME_LENGTH]
INT submit_elog(char *host, int port, char *experiment, char *passwd, char *uname, char *upwd, char attrib_name[MAX_N_ATTR][NAME_LENGTH], char attrib[MAX_N_ATTR][NAME_LENGTH], int n_attr, char *text, char afilename[MAX_ATTACHMENTS][256], char *buffer[MAX_ATTACHMENTS], INT buffer_size[MAX_ATTACHMENTS])