void nemo_main(void) { while (input_data()) { /* input mass and test data */ force_calc(); /* find force at test pos */ out_result(); /* write snap with results */ } }
std::unique_ptr<SQLiteResult> SQLiteQuery::Execute() { std::unique_ptr<SQLiteResult> out_result(new SQLiteResult()); char* err_info = query; while (1) { int result = sqlite3_step(stmt); if (result == SQLITE_DONE) break; if (result == SQLITE_ROW) { // data! /*if (!out_result) { // no data was expected error = SQL_ERRCODE_NDE; break; }*/ std::unique_ptr<SQLiteRow> row(new SQLiteRow()); int columns = sqlite3_column_count(stmt); for (int x = 0; x < columns; x++) { int type = sqlite3_column_type(stmt, x); const char* name = sqlite3_column_name(stmt, x); switch (type) { case SQLITE_INTEGER: row->AddColumn(Object::unique_ptr( new ObjNumber(sqlite3_column_int(stmt, x))), name); break; case SQLITE_FLOAT: row->AddColumn(Object::unique_ptr( new ObjNumber(sqlite3_column_double(stmt, x))), name); break; case SQLITE_TEXT: row->AddColumn(Object::unique_ptr( new ObjWString((const wchar_t*)sqlite3_column_text16(stmt, x))), name); break; case SQLITE_BLOB: row->AddColumn(Object::unique_ptr( new ObjBlob((BYTE*)sqlite3_column_blob(stmt, x), sqlite3_column_bytes(stmt, x))), name); break; } } out_result->AddRow(std::move(row)); } else { // error throw SQLiteError(parent.LastError()); } } sqlite3_finalize(stmt); stmt = NULL; return out_result; }
void out_result_oc(link_m *m, char *path) { out_data *out_data_t = malloc(sizeof(struct out_data)); memset(out_data_t, 0, sizeof(out_data)); out_data_t->path = path; out_result_funcs funcs = {oc_ready_out, oc_out_class, oc_will_out_property, oc_out_property, oc_to_next_property, oc_to_next_class, oc_out_end, out_data_t}; out_result(m, &funcs); free(out_data_t); }
static void put_file(const char *remote_path, const char *fname) { int fd, ret; /* * get fd for src file & put */ fd = do_open(fname); ret = ne_put(session.sess, remote_path, fd); if (ret != NE_OK) { printf("%s\n", remote_path); out_result(ret); quit(1); } count++; }
/* callback for md generator */ static void get_file(const char *remote_path, off_t start, off_t end) { int fd, ret; ne_content_range range; range.start = start; range.end = end; range.total = end - start + 1; printf("start: %ld end: %ld total: %ld\n", range.start, range.end, range.total); /* * open dest & get */ fd = open(tmp_fname, O_CREAT|O_WRONLY|O_TRUNC, 0644); if (fd == -1) { perror(tmp_fname); quit(1); } ret = ne_get_range(session.sess, remote_path, &range, fd); if (ret != NE_OK) { out_result(ret); quit(1); } if (close(fd) == -1) { perror("close"); quit(1); } if (validate) { if (of_check_file_range(tmp_fname, start, end)) { /* leave file for inspection */ exit(1); } } count++; }
static void get_file(const char *remote_path, const char *fname) { int fd, ret; /* * open dest & get */ fd = open(fname, O_CREAT|O_WRONLY|O_TRUNC, 0644); if (fd == -1) { perror(fname); quit(1); } ret = ne_get(session.sess, remote_path, fd); if (ret != NE_OK) { out_result(ret); quit(1); } if (close(fd) == -1) { perror("close"); quit(1); } }
void test01(WORD testNo, char *testName, BYTE tcpNotUdp, DWORD *blockSizes, WORD blockSizesCount) { DWORD start = getTicks(); //---------- out_test_header(testNo, testName); // show test header //---------- // find out the largest block size int i; int maxBlockSize = 0; for(i=0; i<blockSizesCount; i++) { if(maxBlockSize < (int)blockSizes[i]) { // if current max block size is smaller than this block size, store it maxBlockSize = blockSizes[i]; } } //---------- // open socket int handle; if(tcpNotUdp) { handle = TCP_open(SERVER_ADDR, SERVER_PORT_START, 0, maxBlockSize); } else { handle = UDP_open(SERVER_ADDR, SERVER_PORT_START + 4); } if(handle < 0) { out_result_string(0, "TCP/UDP open() failed"); return; } //---------- // if TCP (not UDP), wait for connected state if(tcpNotUdp) { // wait until connected int res; while(1) { res = TCP_wait_state(handle, TESTABLISH, 1); if(res == E_NORMAL) { break; } DWORD now = getTicks(); if((now - start) > 5*200) { out_result_string(0, "TCP_wait_state() timeout"); goto test01close; } } if(res != E_NORMAL) { out_result_error_string(0, res, "TCP_wait_state() failed"); goto test01close; } } //--------------------- int res; for(i=0; i<blockSizesCount; i++) { res = sendAndReceive(tcpNotUdp, blockSizes[i], handle, 1); if(!res) { // if single block-send-and-receive operation failed, quit and close goto test01close; } } //--------------------- out_result(1); // success! test01close: if(tcpNotUdp) { res = TCP_close(handle, 0, 0); // close } else { res = UDP_close(handle); // close } if(res != E_NORMAL) { out_result_error_string(0, res, "TCP/UDP close() failed"); } }
void test0130(void) { int handle, res, ok; int a,b,c; out_test_header(0x0130, "UDP - CNbyte_count() on 3 datagrams"); handle = UDP_open(SERVER_ADDR, SERVER_PORT_START + 4); if(handle >= 0) { // send 3 x 100 bytes (void) UDP_send(handle, wBuf, 100); (void) UDP_send(handle, wBuf, 100); (void) UDP_send(handle, wBuf, 100); sleep(1); res = CNbyte_count(handle); // see how many bytes we got for reading on this socket ok = (res == 300) ? 1 : 0; out_result_error(ok, res); //----------------------------------- out_test_header(0x0131, "UDP - CNget_block() on 3 datagrams"); // receive it using 3x CNget_block() a = CNget_block (handle, rBuf, 100); b = CNget_block (handle, rBuf, 100); c = CNget_block (handle, rBuf, 100); ok = (a == 100 && b == 100 && c == 100) ? 1 : 0; out_result_error(ok, res); //----------------------------------- UDP_close(handle); } else { out_result_string(0, "UDP_open failed"); } ////////////////////////////////////////////////////////////////////////////// out_test_header(0x0132, "UDP - CNbyte_count() after partial read"); handle = UDP_open(SERVER_ADDR, SERVER_PORT_START + 4); if(handle >= 0) { // send 300 bytes (void) UDP_send(handle, wBuf, 300); sleep(1); res = CNbyte_count(handle); // see how many bytes we got for reading on this socket ok = (res == 300) ? 1 : 0; if(!ok) { // if not enough data, fail out_result_error_string(ok, res, "not enough data"); } else { a = CNget_block (handle, rBuf, 100); b = CNbyte_count(handle); ok = (a == 100 && b == 200) ? 1 : 0; out_result_error(ok, b); } UDP_close(handle); } else { out_result_string(0, "UDP_open failed"); } ////////////////////////////////////////////////////////////////////////////// out_test_header(0x0133, "UDP - get 3 DGRAMs with 1 CNget_block"); handle = UDP_open(SERVER_ADDR, SERVER_PORT_START + 4); if(handle >= 0) { // send 300 bytes (void) UDP_send(handle, wBuf, 100); (void) UDP_send(handle, wBuf, 100); (void) UDP_send(handle, wBuf, 100); sleep(1); res = CNbyte_count(handle); // see how many bytes we got for reading on this socket ok = (res == 300) ? 1 : 0; if(!ok) { // if not enough data, fail out_result_error_string(ok, res, "not enough data"); } else { a = CNget_block (handle, rBuf, 300); b = CNbyte_count(handle); ok = (a == 300 && b == 0) ? 1 : 0; out_result_error(ok, b); } UDP_close(handle); } else { out_result_string(0, "UDP_open failed"); } ////////////////////////////////////////////////////////////////////////////// out_test_header(0x0134, "UDP - get 3 DGRAMs with 3x CNget_NDB"); handle = UDP_open(SERVER_ADDR, SERVER_PORT_START + 4); if(handle >= 0) { // send 300 bytes (void) UDP_send(handle, wBuf, 100); (void) UDP_send(handle, wBuf, 100); (void) UDP_send(handle, wBuf, 100); sleep(1); res = CNbyte_count(handle); // see how many bytes we got for reading on this socket ok = (res == 300) ? 1 : 0; if(!ok) { // if not enough data, fail out_result_error_string(ok, res, "not enough data"); } else { NDB *m,*n,*o; m = CNget_NDB(handle); n = CNget_NDB(handle); o = CNget_NDB(handle); ok = (m != NULL && n != NULL && o != NULL) ? 1 : 0; if(!ok) { out_result_string(ok, "some CNget_NDB failed"); } else { ok = (m->len == 100 && n->len == 100 && o->len == 100) ? 1 : 0; if(!ok) { out_result_string(ok, "length of NDB block wrong"); } else { out_result(1); } } } UDP_close(handle); } else { out_result_string(0, "UDP_open failed"); } ////////////////////////////////////////////////////////////////////////////// out_test_header(0x0135, "UDP - get 3 DGRAMs with CNget_char"); handle = UDP_open(SERVER_ADDR, SERVER_PORT_START + 4); if(handle >= 0) { // send 300 bytes (void) UDP_send(handle, wBuf, 100); (void) UDP_send(handle, wBuf, 100); (void) UDP_send(handle, wBuf, 100); sleep(1); res = CNbyte_count(handle); // see how many bytes we got for reading on this socket ok = (res == 300) ? 1 : 0; b = 1; // good for now if(!ok) { // if not enough data, fail out_result_error_string(ok, res, "not enough data"); } else { int i; for(i=0; i<300; i++) { a = CNget_char(handle); if(a >= 0) { rBuf[i] = a; } else { out_result_error_string(0, a, "error on CNget_char"); b = 0; // failed break; } } if(b) { // if good, check data a = memcmp(rBuf, wBuf, 100); b = memcmp(rBuf + 100, wBuf, 100); c = memcmp(rBuf + 200, wBuf, 100); ok = (a == 0 && b == 0 && c == 0) ? 1 : 0; out_result(ok); } } UDP_close(handle); } else { out_result_string(0, "UDP_open failed"); } }
/* TODO: does this work under cygwin? mkstemp() may or may not open the file using O_BINARY, and then we *do* upload it using O_BINARY, so maybe this will screw things up. Maybe we should fcntl it and set O_BINARY, if that is allowed under cygwin? */ void execute_edit(const char *remote) { char *real_remote; unsigned int can_lock; /* can we LOCK it? */ struct ne_lock *lock = NULL; char fname[PATH_MAX] = "/tmp/cadaver-edit-XXXXXX"; const char *pnt; int fd; int is_checkout, is_checkin; real_remote = resolve_path(session.uri.path, remote, false); /* Don't let them edit a collection, since PUT to a collection is * bogus. Really we want to be able to fetch a "DefaultDocument" * property, and edit on that instead: IIS does expose such a * property. Would be a nice hack to add the support to mod_dav * too. */ if (getrestype(real_remote) == resr_collection) { printf(_("You cannot edit a collection resource (%s).\n"), real_remote); goto edit_bail; } can_lock = is_lockable(real_remote); /* Give the local temp file the same extension as the remote path, * so the editor can have a stab at the content-type. */ pnt = strrchr(real_remote, '.'); if (pnt != NULL && strchr(pnt, '/') == NULL) { strncat(fname, pnt, PATH_MAX); fname[PATH_MAX-1] = '\0'; } fd = cad_mkstemp(fname); if (fd == -1) { printf(_("Could not create temporary file %s:\n%s\n"), fname, strerror(errno)); goto edit_bail; } /* Sanity check on the file perms. */ #ifdef HAVE_FCHMOD if (fchmod(fd, 0600) == -1) { #else if (chmod(fname, 0600) == -1) { #endif printf(_("Could not set file permissions for %s:\n%s\n"), fname, strerror(errno)); goto edit_bail; } if (can_lock) { lock = ne_lock_create(); ne_fill_server_uri(session.sess, &lock->uri); lock->uri.path = ne_strdup(real_remote); lock->owner = getowner(); out_start("Locking", remote); if (out_handle(ne_lock(session.sess, lock))) { ne_lockstore_add(session.locks, lock); } else { ne_lock_destroy(lock); goto edit_close; } } else { /* TODO: HEAD and get the Etag/modtime */ } /* Return 1: Checkin, 2: Checkout, 0: otherwise */ is_checkin = is_vcr(real_remote); if (is_checkin==1) { execute_checkout(real_remote); } output(o_download, _("Downloading `%s' to %s"), real_remote, fname); /* Don't puke if get fails -- perhaps we are creating a new one? */ out_result(ne_get(session.sess, real_remote, fd)); if (close(fd)) { output(o_finish, _("Error writing to temporary file: %s\n"), strerror(errno)); } else if (!run_editor(fname)) { int upload_okay = 0; fd = open(fname, O_RDONLY | OPEN_BINARY_FLAGS); if (fd < 0) { output(o_finish, _("Could not re-open temporary file: %s\n"), strerror(errno)); } else { do { output(o_upload, _("Uploading changes to `%s'"), real_remote); /* FIXME: conditional PUT using fetched Etag/modtime if * !can_lock */ if (out_handle(ne_put(session.sess, real_remote, fd))) { upload_okay = 1; } else { /* TODO: offer to save locally instead */ printf(_("Try uploading again (y/n)? ")); if (!yesno()) { upload_okay = 1; } } } while (!upload_okay); close(fd); } } if (unlink(fname)) { printf(_("Could not delete temporary file %s:\n%s\n"), fname, strerror(errno)); } /* Return 1: Checkin, 2: Checkout, 0: otherwise */ is_checkout = is_vcr(real_remote); if (is_checkout==2) { execute_checkin(real_remote); } /* UNLOCK it again whether we succeed or failed in our mission */ if (can_lock) { output(o_start, "Unlocking `%s':", remote); out_result(ne_unlock(session.sess, lock)); ne_lockstore_remove(session.locks, lock); ne_lock_destroy(lock); } goto edit_bail; edit_close: close(fd); edit_bail: free(real_remote); return; }
/* callback for md generator */ static void get_file(char **md_vals, int size_code) { int fd, ret; char remote_path[1024]; /* * construct path to get */ if (size_code > -1) { switch (size_code) { case 0: sprintf(remote_path, "%s/%s", "/webdav/oFotoHashDirs", md_vals[0]); break; case 1: sprintf(remote_path, "%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1]); break; case 2: sprintf(remote_path, "%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2]); break; case 3: sprintf(remote_path, "%s/%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2], md_vals[3]); break; case 4: sprintf(remote_path, "%s/%s/%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2], md_vals[3], md_vals[4]); break; case 5: sprintf(remote_path, "%s/%s/%s/%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2], md_vals[3], md_vals[4], md_vals[5]); break; default: return; } size_code = FILE_5K; } else { // full path sprintf(remote_path, "%s/%s/%s/%s/%s/%s/%s/%s", "/webdav/oFotoHashDirs", md_vals[0], md_vals[1], md_vals[2], md_vals[3], md_vals[4], md_vals[5], md_vals[6]); } if (hc_host == NULL) { printf("%s\n", remote_path); return; } if (verbose) printf("%s\n", remote_path); /* * open dest & get */ fd = open(tmp_fname, O_CREAT|O_WRONLY|O_TRUNC, 0644); if (fd < 0) { perror(tmp_fname); quit(1); } ret = ne_get(session.sess, remote_path, fd); if (ret != NE_OK) { printf("%s\n", remote_path); out_result(ret); quit(1); } if (close(fd) == -1) { perror("close"); quit(1); } if (validate) { if (of_check_file(tmp_fname, size_code)) { /* leave file for inspection */ fprintf(stderr, "ERROR\n"); exit(1); } } count++; }