static void cli_command(struct cli *c) { struct config f; int res; if (config->cli_debug > 1) log(L_TRACE "CLI: %s", c->rx_buf); bzero(&f, sizeof(f)); f.mem = c->parser_pool; cf_read_hook = cli_cmd_read_hook; cli_rh_pos = c->rx_buf; cli_rh_len = strlen(c->rx_buf); cli_rh_trick_flag = 0; this_cli = c; lp_flush(c->parser_pool); res = cli_parse(&f); if (!res) cli_printf(c, 9001, f.err_msg); }
/* * Sends a list of files to the LDM as data-products. * * Arguments: * ldmProxy The LDM proxy data-structure. * offer The description of the class of data-products that this * process is willing to send. * origin The identifier of the host that created the * data-products (typically the host running this program). * seq_start The starting value of the data-product sequence number. * nfiles The number of files to send. * filenames The pathnames of the files to send. * * Returns: * 0 Success. * SYSTEM_ERROR O/S failure. "log_add()" called. * CONNECTION_ABORTED The connection was aborted. "log_add()" * called. */ static int ldmsend( LdmProxy* ldmProxy, prod_class_t* offer, char* origin, int seq_start, int nfiles, char* filenames[]) { int status = 0; char* filename; int fd; struct stat statb; prod_info info; MD5_CTX* md5ctxp = NULL; prod_class_t* want; /* * Allocate an MD5 context */ md5ctxp = new_MD5_CTX(); if (md5ctxp == NULL) { log_syserr_q("new_md5_CTX failed"); return SYSTEM_ERROR; } status = lp_hiya(ldmProxy, offer, &want); if (status != 0) { status = CONNECTION_ABORTED; } else { /* These members are constant over the loop. */ info.origin = origin; info.feedtype = offer->psa.psa_val->feedtype; for (info.seqno = seq_start; exitIfDone(1) && nfiles > 0; filenames++, nfiles--, info.seqno++) { filename = *filenames; info.ident = filename; /* * ?? This could be the creation time of the file. */ (void) set_timestamp(&info.arrival); /* * Checks 'arrival', 'feedtype', and 'ident' * against what the other guy has said he wants. */ if (!prodInClass(offer, &info)) { log_info_q("Not going to send %s", filename); continue; } if (!prodInClass(want, &info)) { log_info_q("%s doesn't want %s", lp_host(ldmProxy), filename); continue; } fd = open(filename, O_RDONLY, 0); if (fd == -1) { log_syserr_q("open: %s", filename); continue; } if (fstat(fd, &statb) == -1) { log_syserr_q("fstat: %s", filename); (void) close(fd); continue; } log_info_q("Sending %s, %d bytes", filename, statb.st_size); /* These members, and seqno, vary over the loop. */ if (fd_md5(md5ctxp, fd, statb.st_size, info.signature) != 0) { (void) close(fd); continue; } if (lseek(fd, 0, SEEK_SET) == (off_t)-1) { log_syserr_q("rewind: %s", filename); (void) close(fd); continue; } info.sz = (u_int)statb.st_size; (void)exitIfDone(1); status = send_product(ldmProxy, fd, &info); (void) close(fd); if (0 != status) { log_add("Couldn't send file \"%s\" to LDM", filename); break; } } /* file loop */ if (lp_flush(ldmProxy)) log_add("Couldn't flush connection"); free_prod_class(want); } /* HIYA succeeded */ free_MD5_CTX(md5ctxp); return status; }