int main(int argc, char **argv) { xr_init(); bool eval = false; bool verbose = false; int c; while ((c = getopt(argc, argv, "ev")) != -1) { switch (c) { case 'e': eval = true; break; case 'v': verbose = true; break; } } XR obj_list; if (optind < argc) { char *file = argv[optind]; obj_list = xr_parse_dump_file(file); } else { obj_list = xr_parse_dump_from_stdin(); } if (verbose) log("# Objs: %ld\n", xrListLen(obj_list)); XR root_mt = xrMTable(root); assert(root_mt); /* Lookup the "init" method */ XR init_m = xrClosureAt(send(root_mt, s_at, xr_sym("init")), 0); if (verbose) qsend(init_m, "show"); if (!eval) { FILE *fp = fopen("blahtestsymfile", "w"); qsend(root, "pack", fp); fclose(fp); return 0; } if (verbose) log("##############\nRunning VM\n##############\n"); xr_run_method(init_m); return 0; }
void TembooSession::qsend(const char* s) { char c = *s++; while(c != '\0') { qsend(c); c = *s++; } }
void TembooSession::qsendProgmem(const char* s) { char c = pgm_read_byte(s++); while(c != '\0') { qsend(c); c = pgm_read_byte(s++); } }
void syncthread0(void *a) { Queue *q; Syncpath *s; threadsetname("syncthread"); startclient(); q = a; for(;;){ s = qrecv(q); assert(s->state == SyncStart); syncstat(s); if(s->state == SyncError){ Err: syncfinish(s); continue; } synctriage(s); if(s->state == SyncError) goto Err; if(s->triage != DoNothing) tralog("%P %s%s: [%$] [%$]", s->p, s->conflict ? "conflict " : "", workstr(s, s->triage), s->a.s, s->b.s); qsend(s->sync->triageq, s); } }
END_TEST START_TEST (test_symbol_string) { XR sym = xr_sym("symbol"); XR str = send(sym, s_string); fail_unless(qsend(str, "eq", xr_str("symbol")) == VAL_TRUE); }
END_TEST /* START_TEST (test_symbol_pack_unpack) { XR foo = xr_sym("foo"); FILE *fp = fopen("test_symbol_pack.tmp", "w"); qsend( } END_TEST */ START_TEST (test_symbol_literal) { XR sym = xr_sym("symbol"); XR lit = send(sym, s_literal); fail_unless(qsend(lit, "eq", xr_str(":symbol")) == VAL_TRUE); }
int TembooSession::executeChoreo( const char* accountName, const char* appKeyName, const char* appKeyValue, const char* path, const ChoreoInputSet& inputSet, const ChoreoOutputSet& outputSet, const ChoreoPreset& preset) { DataFormatter fmt(&inputSet, &outputSet, &preset); char auth[HMAC_HEX_SIZE_BYTES + 1]; char buffer[11]; // We use the current time-of-day as salt on the app key. // We keep track of time-of-day by getting the current time // from the server and applying an offset (the length of time // we've been running.) uint32toa((uint32_t)TembooSession::getTime(), buffer); uint16_t contentLength = getAuth(fmt, appKeyValue, buffer, auth); m_client.stop(); m_client.flush(); int connected = 0; TEMBOO_TRACE("Connecting: "); // reserve space for the "host" string sufficient to hold either the // (dotted-quad) IP address + port, or the default <account>.temboolive.com // host string. int hostLen = (m_addr == INADDR_NONE ? (strlen_P(TEMBOO_DOMAIN) + strlen(accountName) + 1):21); char host[hostLen]; // If no explicit IP address was specified (the normal case), construct // the "host" string from the account name and the temboo domain name. if (m_addr == INADDR_NONE) { strcpy(host, accountName); strcat_P(host, TEMBOO_DOMAIN); TEMBOO_TRACELN(host); connected = m_client.connect(host, m_port); } else { // If an IP address was explicitly specified (presumably for testing purposes), // convert it to a dotted-quad text string. host[0] = '\0'; for(int i = 0; i < 4; i++) { uint16toa(m_addr[i], &host[strlen(host)]); strcat(host, "."); } // replace the last '.' with ':' host[strlen(host)-1] = ':'; // append the port number uint16toa(m_port, &host[strlen(host)]); TEMBOO_TRACELN(host); connected = m_client.connect(m_addr, m_port); } if (connected) { TEMBOO_TRACELN("OK. req:"); qsendProgmem(POST); qsendProgmem(BASE_CHOREO_URI); qsend(path); qsendProgmem(SDK_ID); qsendlnProgmem(POSTAMBLE); // Send our custom authentication header // (app-key-name:hmac) qsendProgmem(HEADER_AUTH); qsend(appKeyName); qsend(":"); qsendln(auth); // send the standard host header qsendProgmem(HEADER_HOST); qsendln(host); // send the standard accept header qsendlnProgmem(HEADER_ACCEPT); // send our custom account name neader qsendProgmem(HEADER_ORG); qsend(accountName); qsendlnProgmem(HEADER_DOM); // send the standard content type header qsendlnProgmem(HEADER_CONTENT_TYPE); // send our custom client time header qsendProgmem(HEADER_TIME); qsendln(buffer); // send the standard content length header qsendProgmem(HEADER_CONTENT_LENGTH); qsendln(uint16toa(contentLength, buffer)); qsendProgmem(EOL); // Format and send the body of the request fmt.reset(); while(fmt.hasNext()) { qsend(fmt.next()); } qsendProgmem(EOL); qflush(); return 0; } else { TEMBOO_TRACELN("FAIL"); return 1; } }
void TembooSession::qsendln(const char* s) { qsend(s); qsendProgmem(EOL); }
int synckids(Syncpath *s) { int i, ret, n; Channel *c; Kids *ak, *bk; c = chan(Kids*); ak = emalloc(sizeof(*ak)); ak->repl = s->sync->ra; ak->p = s->p; ak->c = c; spawn(kidthread, ak); bk = emalloc(sizeof(*bk)); bk->repl = s->sync->rb; bk->p = s->p; bk->c = c; spawn(kidthread, bk); threadstate("synckids wait %p", c); recvp(c); threadstate("synckids wait %p", c); recvp(c); chanfree(c); ret = -1; if(ak->err){ s->err = ak->err; ak->err = 0; s->state = SyncError; goto End; } if(bk->err){ s->err = bk->err; bk->err = 0; s->state = SyncError; goto End; } ret = 0; if(ak->nk) qsort(ak->k, ak->nk, sizeof(ak->k[0]), kidnamecmp); if(bk->nk) qsort(bk->k, bk->nk, sizeof(bk->k[0]), kidnamecmp); n = mergekids(s, ak->k, ak->nk, bk->k, bk->nk, 0); if(n == 0){ s->state = SyncDone; syncfinish(s); goto End; } mergekids(s, ak->k, ak->nk, bk->k, bk->nk, n); s->npend = s->nkid; s->finishstate = SyncDone; for(i=0; i<n; i++){ if(s->kid[i].a.s == nil) s->kid[i].a.s = mkemptystate(s->a.s->synctime); if(s->kid[i].b.s == nil) s->kid[i].b.s = mkemptystate(s->b.s->synctime); qsend(s->sync->syncq, &s->kid[i]); } End: if(ak->err) free(ak->err); if(bk->err) free(bk->err); freekids(ak->k, ak->nk); freekids(bk->k, bk->nk); free(ak); free(bk); return ret; }
//------------------------------------------------------------------------- ssize_t irs_send(idarpc_stream_t *irs, const void *buf, size_t n) { return qsend(sock_from_irs(irs), buf, (int)n); }
void syncfinish(Syncpath *s) { int iscomplete; Vtime *m; /* * We need to figure out whether a and b are now * up to date with respect to the other. This state is * stored in s->a.complete and s->b.complete. * If a or b was complete or incomplete without * doing any work, these are already set. Else they are -1. * * If the sync failed, we map -1 to 0. * If the sync succeeded, we map -1 to 1. * * If the sync was one-way only, then the value * of s->a.complete is incorrect but will not be used. */ iscomplete = (s->state == SyncDone); if(nop){ s->a.complete = 0; s->b.complete = 0; } dbg(DbgSync, "syncfinish %P %d %d %d\n", s->p, iscomplete, s->a.complete, s->b.complete); if(s->a.complete == -1) s->a.complete = iscomplete; if(s->b.complete == -1) s->b.complete = iscomplete; dbg(DbgSync, "syncfinish %P %d %d\n", s->p, s->a.complete, s->b.complete); /* * Update the sync time on the now synced systems. * For a directory, propagate the mtime too. * * BUG: I think that when we create a directory tree * (meaning one of the ->state's is not SDir), * we might not set the mtime properly. Check this. */ if(s->b.complete){ m = nil; /* BUG: why is this both instead of just one? */ if(s->a.s->state==SDir && s->b.s->state==SDir) m = s->a.s->mtime; if(rpcaddtime(s->sync->rb, s->p, s->a.s->synctime, m) < 0){ s->state = SyncError; s->err = rpcerror(); s->b.complete = 0; s->a.complete = 0; goto Err; } } if(!s->sync->oneway && s->a.complete){ m = nil; if(s->b.s->state==SDir && s->a.s->state==SDir) m = s->b.s->mtime; if(rpcaddtime(s->sync->ra, s->p, s->b.s->synctime, m) < 0){ s->state = SyncError; s->err = rpcerror(); s->a.complete = 0; goto Err; } } Err: qsend(s->sync->finishq, s); }
int TembooSession::executeChoreo( const char* accountName, const char* appKeyName, const char* appKeyValue, const char* path, const ChoreoInputSet& inputSet, const ChoreoOutputSet& outputSet, const ChoreoPreset& preset) { DataFormatter fmt(&inputSet, &outputSet, &preset); char auth[HMAC_HEX_SIZE_BYTES + 1]; char buffer[11]; // We use the current time-of-day as salt on the app key. // We keep track of time-of-day by getting the current time // from the server and applying an offset (the length of time // we've been running.) uint32toa((uint32_t)TembooSession::getTime(), buffer); uint16_t contentLength = getAuth(fmt, appKeyValue, buffer, auth); m_client.stop(); m_client.flush(); int connected = 0; TEMBOO_TRACE("Connecting: "); // reserve space for the "host" string sufficient to hold either the // (dotted-quad) IP address + port, or the default <account>.temboolive.com // host string. int hostLen = strlen_P(TEMBOO_DOMAIN) + strlen(accountName) + 1; char host[hostLen]; // Construct the "host" string from the account name and the temboo domain name. strcpy(host, accountName); strcat_P(host, TEMBOO_DOMAIN); bool useProxy = false; if (m_addr == INADDR_NONE) { TEMBOO_TRACELN(host); connected = m_client.connect(host, m_port); } else { TEMBOO_TRACELN(host); connected = m_client.connect(m_addr, m_port); useProxy = true; } if (connected) { TEMBOO_TRACELN("OK. req:"); qsendProgmem(POST); if(useProxy) { qsendProgmem(HTTP); qsend(host); } qsendProgmem(BASE_CHOREO_URI); qsend(path); qsendProgmem(SDK_ID); qsendlnProgmem(POSTAMBLE); // Send our custom authentication header // (app-key-name:hmac) qsendProgmem(HEADER_AUTH); qsend(appKeyName); qsend(":"); qsendln(auth); // send the standard host header qsendProgmem(HEADER_HOST); qsendln(host); // send the standard accept header qsendlnProgmem(HEADER_ACCEPT); // send our custom account name neader qsendProgmem(HEADER_ORG); qsend(accountName); qsendlnProgmem(HEADER_DOM); // send the standard content type header qsendlnProgmem(HEADER_CONTENT_TYPE); // send our custom client time header qsendProgmem(HEADER_TIME); qsendln(buffer); // send the standard content length header qsendProgmem(HEADER_CONTENT_LENGTH); qsendln(uint16toa(contentLength, buffer)); qsendProgmem(EOL); // Format and send the body of the request fmt.reset(); while(fmt.hasNext()) { qsend(fmt.next()); } qsendProgmem(EOL); qflush(); return 0; } else { TEMBOO_TRACELN("FAIL"); return 1; } }