static void do_snapshot_test( const char *orig_client, int expected_ret, void setup_callback( struct asfd *csin, struct asfd *csout, struct asfd *so_asfd ) ) { struct asfd *csin; struct asfd *csout; struct asfd *so_asfd; struct async *as; struct sel *sel; as=setup_async(); csin=asfd_mock_setup(&reads_csin, &writes_csin); csout=asfd_mock_setup(&reads_csout, &writes_csout); so_asfd=asfd_mock_setup(&reads_so, &writes_so); fail_unless((csin->desc=strdup_w("csin", __func__))!=NULL); fail_unless((csout->desc=strdup_w("csout", __func__))!=NULL); fail_unless((so_asfd->desc=strdup_w("so_asfd", __func__))!=NULL); as->asfd_add(as, csin); as->asfd_add(as, csout); as->asfd_add(as, so_asfd); as->read_write=async_rw_simple; as->write=async_write_simple; setup_callback(csin, csout, so_asfd); fail_unless((sel=sel_alloc())!=NULL); fail_unless(!status_client_ncurses_init(ACTION_STATUS_SNAPSHOT)); fail_unless(status_client_ncurses_main_loop( as, so_asfd, sel, orig_client )==expected_ret); sel_free(&sel); asfd_free(&csin); asfd_free(&csout); asfd_free(&so_asfd); asfd_mock_teardown(&reads_csin, &writes_csin); asfd_mock_teardown(&reads_csout, &writes_csout); asfd_mock_teardown(&reads_so, &writes_so); async_free(&as); alloc_check(); }
static void do_simple_test( const char *orig_client, int expected_ret, void setup_callback(struct asfd *asfd), void setup_stdout_callback(struct asfd *asfd) ) { struct asfd *asfd; struct asfd *so_asfd; struct async *as; as=setup_async(); asfd=asfd_mock_setup(&reads, &writes); so_asfd=asfd_mock_setup(&reads_so, &writes_so); as->asfd_add(as, asfd); as->asfd_add(as, so_asfd); asfd->as=as; as->read_write=async_rw_simple; as->write=async_write_simple; setup_callback(asfd); if(setup_stdout_callback) setup_stdout_callback(so_asfd); fail_unless(!status_client_ncurses_init(ACTION_STATUS_SNAPSHOT)); fail_unless(status_client_ncurses_main_loop( as, so_asfd, orig_client )==expected_ret); asfd_free(&asfd); asfd_free(&so_asfd); asfd_mock_teardown(&reads, &writes); asfd_mock_teardown(&reads_so, &writes_so); async_free(&as); alloc_check(); }
END_TEST static void do_status_test( const char *orig_client, int expected_ret, void setup_callback( struct asfd *csin, struct asfd *csout, struct asfd *nin, struct asfd *so_asfd ), void check_sel_callback( struct sel *sel ) ) { struct asfd *csin; struct asfd *csout; struct asfd *nin; struct asfd *so_asfd; struct async *as; struct sel *sel; as=setup_async(); csin=asfd_mock_setup(&reads_csin, &writes_csin); csout=asfd_mock_setup(&reads_csout, &writes_csout); nin=asfd_mock_setup(&reads_nin, &writes_nin); so_asfd=asfd_mock_setup(&reads_so, &writes_so); fail_unless((csin->desc=strdup_w("csin", __func__))!=NULL); fail_unless((csout->desc=strdup_w("csout", __func__))!=NULL); fail_unless((nin->desc=strdup_w("nin", __func__))!=NULL); fail_unless((so_asfd->desc=strdup_w("so_asfd", __func__))!=NULL); nin->streamtype=ASFD_STREAM_NCURSES_STDIN; as->asfd_add(as, csin); as->asfd_add(as, csout); as->asfd_add(as, nin); as->asfd_add(as, so_asfd); as->read_write=async_rw_both; as->write=async_write_simple; setup_callback(csin, csout, nin, so_asfd); fail_unless((sel=sel_alloc())!=NULL); fail_unless(!status_client_ncurses_init(ACTION_STATUS)); fail_unless(status_client_ncurses_main_loop( as, so_asfd, sel, orig_client )==expected_ret); if(check_sel_callback) check_sel_callback(sel); sel_free(&sel); asfd_free(&csin); asfd_free(&csout); asfd_free(&nin); asfd_free(&so_asfd); asfd_mock_teardown(&reads_csin, &writes_csin); asfd_mock_teardown(&reads_csout, &writes_csout); asfd_mock_teardown(&reads_nin, &writes_nin); asfd_mock_teardown(&reads_so, &writes_so); async_free(&as); alloc_check(); }
static enum cliret do_client(struct conf **confs, enum action action, int vss_restore) { enum cliret ret=CLIENT_OK; int rfd=-1; SSL *ssl=NULL; SSL_CTX *ctx=NULL; struct cntr *cntr=NULL; char *incexc=NULL; enum action act=action; struct async *as=NULL; struct asfd *asfd=NULL; // as->settimers(0, 100); // logp("begin client\n"); // logp("action %d\n", action); // Status monitor forks a child process instead of connecting to // the server directly. if(action==ACTION_STATUS || action==ACTION_STATUS_SNAPSHOT) { #ifdef HAVE_WIN32 logp("Status mode not implemented on Windows.\n"); goto error; #endif if(status_client_ncurses_init(act) || status_client_ncurses(confs)) ret=CLIENT_ERROR; goto end; } if(!(cntr=cntr_alloc()) || cntr_init(cntr, get_string(confs[OPT_CNAME]))) goto error; set_cntr(confs[OPT_CNTR], cntr); if(act!=ACTION_ESTIMATE && ssl_setup(&rfd, &ssl, &ctx, action, confs)) goto could_not_connect; if(!(as=async_alloc()) || !(asfd=asfd_alloc()) || as->init(as, act==ACTION_ESTIMATE) || asfd->init(asfd, "main socket", as, rfd, ssl, ASFD_STREAM_STANDARD, confs)) goto end; as->asfd_add(as, asfd); // Set quality of service bits on backup packets. if(act==ACTION_BACKUP || act==ACTION_BACKUP_TIMED || act==ACTION_TIMER_CHECK) as->asfd->set_bulk_packets(as->asfd); if(act!=ACTION_ESTIMATE) { if((ret=initial_comms(as, &act, &incexc, confs))) goto end; } rfd=-1; switch(act) { case ACTION_BACKUP: ret=backup_wrapper(asfd, act, "backupphase1", incexc, confs); break; case ACTION_BACKUP_TIMED: ret=backup_wrapper(asfd, act, "backupphase1timed", incexc, confs); break; case ACTION_TIMER_CHECK: ret=backup_wrapper(asfd, act, "backupphase1timedcheck", incexc, confs); break; case ACTION_RESTORE: case ACTION_VERIFY: ret=restore_wrapper(asfd, act, vss_restore, confs); break; case ACTION_ESTIMATE: if(do_backup_client(asfd, confs, act, 0)) goto error; break; case ACTION_DELETE: if(do_delete_client(asfd, confs)) goto error; break; case ACTION_MONITOR: if(do_monitor_client(asfd, confs)) goto error; break; case ACTION_DIFF: case ACTION_DIFF_LONG: /* if(!strcmp(get_string(confs[OPT_BACKUP2]), "n")) // Do a phase1 scan and diff that. ret=backup_wrapper(asfd, act, "backupphase1diff", incexc, confs); else */ // Diff two backups that already exist. // Fall through, the list code is all we need // for simple diffs on the client side. case ACTION_LIST: case ACTION_LIST_LONG: default: if(do_list_client(asfd, act, confs)) goto error; break; } if(asfd_flush_asio(asfd)) ret=CLIENT_ERROR; goto end; error: ret=CLIENT_ERROR; goto end; could_not_connect: ret=CLIENT_COULD_NOT_CONNECT; end: close_fd(&rfd); async_free(&as); asfd_free(&asfd); if(ctx) ssl_destroy_ctx(ctx); free_w(&incexc); set_cntr(confs[OPT_CNTR], NULL); cntr_free(&cntr); //logp("end client\n"); return ret; }