bool Settings::LoadSettings() //////////////////////////////////////////////////////////////////////// { #define GETSTRING(a,b) if (settingsfile.GetString(a, tempstring)) Set##b(tempstring); #define GETBOOL(a,b) if (settingsfile.GetBool(a, tempbool)) Set##b(tempbool); #define GETINT(a,b) if (settingsfile.GetInteger(a, tempint)) Set##b(tempint); BString tempstring; bool tempbool; int tempint; DataFile settingsfile; if (settingsfile.LoadDataFile(GetSettingsFile())) { if (settingsfile.GetBool("ASKONEXIT", tempbool)) SetAskOnExit(tempbool); if (settingsfile.GetString("LANGUAGE", tempstring)) SetLanguage(tempstring); if (settingsfile.GetInteger("WINDOWLEFT", tempint)) SetWindowLeft(tempint); GETINT("WINDOWTOP", WindowTop); GETINT("WINDOWWIDTH", WindowWidth); GETINT("WINDOWHEIGHT", WindowHeight); GETSTRING("TERMINALWINDOW", TerminalWindow); GETSTRING("LEFTPANELPATH", LeftPanelPath); GETSTRING("RIGHTPANELPATH", RightPanelPath); return true; } else return false; }
void Forwarder::Summary::onEnable() { int interval = GETINT(cfg::summary::interval); if (!this->isActive() || !interval || (!GETINT(cfg::summary::inAutoAway) && Ctrl->IMessageDirect(api::isAutoAway, Ctrl->ID()))) return; this->timer->repeat(interval * 60 * 1000); }
void Forwarder::Summary::send() { int minMsgCount = GETINT(cfg::summary::minMsgCount); int interval = GETINT(cfg::summary::interval); if (!this->isActive() || !this->receivedMsgCount || !Ctrl->ICMessage(IMC_CONNECTED) || !interval || !this->parent->preSummary() || (minMsgCount && this->receivedMsgCount < minMsgCount)) return; this->parent->send(this->getBody()); this->clear(); }
VAL idris_bigMinus(VM* vm, VAL x, VAL y) { if (ISINT(x) && ISINT(y)) { i_int vx = GETINT(x); i_int vy = GETINT(y); if ((vx <= 0 && vy <=0) || (vx >=0 && vy <=0)) { return INTOP(-, x, y); } i_int res = vx - vy; if (res >= 1<<30 || res <= -(1 << 30)) { return bigSub(vm, GETBIG(vm, x), GETBIG(vm, y)); } else { return MKINT(res); } } else {
void Forwarder::Forward::onNewMsg(int cnt, Message *msg) { if (!this->isActive() || !strlen(msg->fromUid) || (!GETINT(cfg::fwd::inAutoAway) && Ctrl->IMessageDirect(api::isAutoAway, Ctrl->ID())) || !this->parent->preForward(cnt, msg)) { return; } this->parent->send(this->getBody(cnt, msg)); }
VAL GETBIG(VM * vm, VAL x) { idris_requireAlloc(IDRIS_MAXGMP); if (ISINT(x)) { mpz_t* bigint; VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0); idris_doneAlloc(); bigint = (mpz_t*)(((char*)cl) + sizeof(Closure)); mpz_init(*bigint); mpz_set_si(*bigint, GETINT(x)); SETTY(cl, CT_BIGINT); cl -> info.ptr = (void*)bigint; return cl; } else { idris_doneAlloc(); switch(GETTY(x)) { case CT_FWD: return GETBIG(vm, x->info.ptr); default: return x; } } }
int main() { VM* vm = init_vm(100,100); do_main(vm, NULL); printf("%ld\n", GETINT(RVAL)); printf("%d %d %d\n", vm->valstack, vm->valstack_base, vm->valstack_top); }
VAL idris_bigPlus(VM* vm, VAL x, VAL y) { if (ISINT(x) && ISINT(y)) { i_int vx = GETINT(x); i_int vy = GETINT(y); if ((vx <= 0 && vy >=0) || (vx >=0 && vy <=0)) { return ADD(x, y); } i_int res = vx + vy; if (res >= 1<<30 || res <= -(1 << 30)) { return bigAdd(vm, GETBIG(vm, x), GETBIG(vm, y)); } else { return MKINT(res); } } else { return bigAdd(vm, GETBIG(vm, x), GETBIG(vm, y)); } }
// VAL is RawPacket int prim_send(int socket, VAL stuff) { VAL pkt = GETPTR(PROJECT(stuff,0)); int len = GETINT(PROJECT(stuff,1)); int words = len >> 5; if ((len & 31)!=0) ++words; return send(socket, pkt, words*sizeof(uint32_t), 0); }
void Control::changeStatus(int status, std::string info, int net) { if (net && (net != kZmieniacz::net)) { sCtrl->changeStatus(net, info, status); return; } sCtrl->changeStatus(info, status); int lastSt = (status != -1) ? status : GETINT(cfg::lastSt); if (lastSt != GETINT(cfg::lastSt) || info != GETSTRA(cfg::lastStInfo)) PlugStatusChange(lastSt, info.c_str()); if (status != -1) { SETINT(cfg::lastSt, status); Helpers::chgBtn(ui::tb::tb, ui::tb::btnOk, 0, 0, this->stIcon(status), -1); } SETSTR(cfg::lastStInfo, info.c_str()); this->refreshCombo(info); }
VAL bigAShiftRight(VM* vm, VAL x, VAL y) { idris_requireAlloc(IDRIS_MAXGMP); mpz_t* bigint; VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0); idris_doneAlloc(); bigint = (mpz_t*)(((char*)cl) + sizeof(Closure)); mpz_fdiv_q_2exp(*bigint, GETMPZ(GETBIG(vm,x)), GETINT(y)); SETTY(cl, CT_BIGINT); cl -> info.ptr = (void*)bigint; return cl; }
void Control::changeStatus(int status, int net) { if (status == -1) return; if (net && (net != kZmieniacz::net)) { sCtrl->changeStatus(net, status); return; } sCtrl->changeStatus(status); if (status != GETINT(cfg::lastSt)) PlugStatusChange(status, 0); SETINT(cfg::lastSt, status); Helpers::chgBtn(ui::tb::tb, ui::tb::btnOk, 0, 0, this->stIcon(status), -1); }
VAL GETBIG(VM * vm, VAL x) { if (ISINT(x)) { mpz_t* bigint; VAL cl = allocate(vm, sizeof(ClosureType) + sizeof(void*)); bigint = allocate(vm, sizeof(mpz_t)); mpz_init(*bigint); mpz_set_si(*bigint, GETINT(x)); cl -> ty = BIGINT; cl -> info.ptr = (void*)bigint; return cl; } else { return x; } }
VAL GETBIG(VM * vm, VAL x) { if (ISINT(x)) { mpz_t* bigint; VAL cl = allocate(vm, sizeof(ClosureType) + sizeof(void*) + sizeof(mpz_t), 0); bigint = (mpz_t*)(((char*)cl) + sizeof(ClosureType) + sizeof(void*)); mpz_init(*bigint); mpz_set_si(*bigint, GETINT(x)); SETTY(cl, BIGINT); cl -> info.ptr = (void*)bigint; return cl; } else { return x; } }
int prim_sendTo(int socket, char* host, int port, VAL stuff) { VAL pkt = GETPTR(PROJECT(stuff,0)); int len = GETINT(PROJECT(stuff,1)); int words = len >> 5; if ((len & 31)!=0) ++words; struct sockaddr_in other; memset((char *) &other, 0, sizeof(other)); other.sin_family = AF_INET; other.sin_port = htons(port); if (inet_aton(host, &other.sin_addr)==0) { return -1; } return sendto(socket, pkt, words*sizeof(uint32_t), 0, (struct sockaddr*)&other, sizeof(other)); }
VAL GETBIG(VM * vm, VAL x) { if (ISINT(x)) { mpz_t* bigint; VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0); bigint = (mpz_t*)(((char*)cl) + sizeof(Closure)); mpz_init(*bigint); mpz_set_si(*bigint, GETINT(x)); SETTY(cl, BIGINT); cl -> info.ptr = (void*)bigint; return cl; } else { switch(GETTY(x)) { case FWD: return GETBIG(vm, x->info.ptr); default: return x; } } }
struct child_config *child_config_from_json(json_object *obj) { struct child_config *ret; json_object *t, *s; int i, len; ret = child_config_new(); #define GET(X, Y) if ((t = json_object_object_get(obj, Y)) != NULL) { \ if (!json_object_is_type(t, json_type_string)) { \ child_config_free(ret); \ return NULL; \ } \ X = xstrdup(json_object_get_string(t)); \ } #define GETINT(X, Y) if ((t = json_object_object_get(obj, Y)) != NULL) { \ if (!json_object_is_type(t, json_type_int)) { \ child_config_free(ret); \ return NULL; \ } \ X = json_object_get_int(t); \ } GET(ret->cc_name, "name"); if (ret->cc_name == NULL) { child_config_free(ret); return NULL; } GET(ret->cc_stdout, "stdout"); GET(ret->cc_stderr, "stderr"); GET(ret->cc_dir, "dir"); GET(ret->cc_heartbeat, "heartbeat"); GET(ret->cc_fatal_cb, "fatal_cb"); GET(ret->cc_username, "username"); GET(ret->cc_groupname, "groupname"); GETINT(ret->cc_instances, "instances"); GETINT(ret->cc_status, "status"); GETINT(ret->cc_killsig, "killsig"); GETINT(ret->cc_uid, "uid"); GETINT(ret->cc_gid, "gid"); GETINT(ret->cc_error, "error"); GETINT(ret->cc_age, "age"); if ((t = json_object_object_get(obj, "args")) != NULL) { if (!json_object_is_type(t, json_type_array)) { child_config_free(ret); return NULL; } len = json_object_array_length(t); ret->cc_command = xmalloc(sizeof(char *) * (len + 1)); for (i = 0; i < len; i++) { if ((s = json_object_array_get_idx(t, i)) == NULL) { ret->cc_command[i] = NULL; child_config_free(ret); return NULL; } if (!json_object_is_type(s, json_type_string)) { child_config_free(ret); return NULL; } ret->cc_command[i] = xstrdup(json_object_get_string(s)); } ret->cc_command[i] = NULL; } return ret; }
void *htext_get_method(void *h) { htext_handle *handle = (htext_handle*)h; CURL *curl; htext_partial *partial_array, head; size_t unused, fsize, stream_size, last_size; char err_buffer[CURL_ERROR_SIZE]; void *f; int i, npartials; /* Create the file */ f = GETIO(handle)->open(GETSTR(handle, HTEXTOP_DESTINATIONURL), "w", GETPTR(handle, HTEXTOP_IO_HANDLER_DATA)); if (!f) { handle->status = HTEXTS_FAILED; strerror_r(errno, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); return NULL; } GETIO(handle)->close(f); /* Create and initialize CURL handle with common stuff */ curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_buffer); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, htext_header_callback); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_URL, GETSTR(handle, HTEXTOP_SOURCEURL)); curl_easy_setopt(curl, CURLOPT_USERAGENT, GETSTR(handle, HTEXTOP_CLIENTID)); curl_easy_setopt(curl, CURLOPT_CAPATH, GETSTR(handle, HTEXTOP_CAPATH)); curl_easy_setopt(curl, CURLOPT_CAINFO, GETSTR(handle, HTEXTOP_CAFILE)); curl_easy_setopt(curl, CURLOPT_SSLCERT, GETSTR(handle, HTEXTOP_USERCERTIFICATE)); curl_easy_setopt(curl, CURLOPT_SSLKEY, GETSTR(handle, HTEXTOP_USERPRIVKEY)); curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, GETSTR(handle, HTEXTOP_USERPRIVKEYPASS)); curl_easy_setopt(curl, CURLOPT_SSL_CIPHER_LIST, htext_cipher_suite()); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); if (GETINT(handle, HTEXTOP_VERBOSITY) > 1) { curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, htext_debug_callback); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } if (GETINT(handle, HTEXTOP_BUFFERSIZE) > 0) { curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, GETINT(handle, HTEXTOP_BUFFERSIZE)); } /* Shared */ curl_easy_setopt(curl, CURLOPT_SHARE, handle->curl_share); /* Do a HEAD to get the size */ htext_partial_init(&head); fsize = 0; head.partial_total = &fsize; head.partial_done = &unused; curl_easy_setopt(curl, CURLOPT_NOBODY, 1); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_HEADERDATA, &head); handle->status = HTEXTS_WAITING; htext_log(handle, "Asking for the size"); if (curl_easy_perform(curl) != CURLE_OK) { htext_error(handle, err_buffer); } if (head.http_status >= 400 || handle->status == HTEXTS_FAILED) { handle->http_status = head.http_status; handle->status = HTEXTS_FAILED; htext_partial_clean(&head); curl_easy_cleanup(curl); return NULL; } /* Did we get the location, and is it cacheable? */ if (head.location && head.redirect_is_cacheable) { curl_easy_setopt(curl, CURLOPT_URL, head.location); } /* Calculate stream size and final stream size */ if (fsize) { npartials = GETINT(handle, HTEXTOP_NUMBEROFSTREAMS); if (fsize % npartials == 0) { stream_size = last_size = fsize / npartials; } else { stream_size = fsize / npartials; last_size = stream_size + (fsize % npartials); } } else { /* No size? Too bad, won't be able to stream */ npartials = 1; stream_size = last_size = 0; htext_log(handle, "No Content-Length, so no multistream possible"); } /* Set progress function */ curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, htext_progress_callback); /* Set up partials */ handle->partial_total = calloc(sizeof(size_t), npartials); handle->partial_done = calloc(sizeof(size_t), npartials); handle->partials = npartials; /* Spawn a thread per partial */ htext_log(handle, "Downloading"); handle->status = HTEXTS_RUNNING; partial_array = calloc(sizeof(htext_partial), npartials); for (i = 0; i < npartials; ++i) { htext_partial_init(&(partial_array[i])); partial_array[i].index = i; partial_array[i].handle = handle; partial_array[i].curl = curl_easy_duphandle(curl); partial_array[i].partial_total = &(handle->partial_total[i]); partial_array[i].partial_done = &(handle->partial_done[i]); /* duphandle doesn't duplicate this :( */ curl_easy_setopt(partial_array[i].curl, CURLOPT_SHARE, handle->curl_share); /* Open */ partial_array[i].fd = GETIO(handle)->open(GETSTR(handle, HTEXTOP_DESTINATIONURL), "w", GETPTR(handle, HTEXTOP_IO_HANDLER_DATA)); if (!partial_array[i].fd) { handle->status = HTEXTS_FAILED; break; } /* Range and seek */ partial_array[i].start = i * stream_size; if (i < handle->partials - 1) partial_array[i].end = partial_array[i].start + stream_size - 1; else partial_array[i].end = partial_array[i].start + last_size - 1; *(partial_array[i].partial_total) = partial_array[i].end - partial_array[i].start; if (GETIO(handle)->seek(partial_array[i].fd, partial_array[i].start, SEEK_SET) < 0) { handle->status = HTEXTS_FAILED; break; } /* Launch */ pthread_create(&(partial_array[i].thread), NULL, htext_get_subthread, &(partial_array[i])); } /* Exited on error? */ if (handle->status == HTEXTS_FAILED) { strerror_r(errno, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); } /* Wait for all of them */ for (i = 0; i < npartials; ++i) { /* Wait, or kill if failed */ if (handle->status == HTEXTS_FAILED) pthread_cancel(partial_array[i].thread); pthread_join(partial_array[i].thread, NULL); if (handle->status != HTEXTS_FAILED) handle->http_status = partial_array[i].http_status; /* Clean partial */ htext_partial_clean(&(partial_array[i])); /* Check code */ if (handle->http_status < 200 || handle->http_status >= 300) { handle->status = HTEXTS_FAILED; } } /* Done */ if (handle->status == HTEXTS_RUNNING) { handle->status = HTEXTS_SUCCEEDED; } curl_easy_cleanup(curl); htext_partial_clean(&head); free(partial_array); return NULL; }
/** * Do the delegation * @param handle The handle * @param url The delegation endpoint * @param err_buffer Used to build the error string * @return NULL on failure, or an allocated string with the delegation ID */ static char *htext_delegate(htext_handle *handle, char *url, char *err_buffer) { char *delegation_id = NULL; char *reqtxt = NULL, *certtxt = NULL; char *keycert = NULL; struct soap *soap_get = NULL, *soap_put = NULL; struct tns__getNewProxyReqResponse getNewProxyReqResponse; char *ucert = NULL, *ukey = NULL, *capath = NULL; int lifetime; /* Get from the handle */ ucert = GETSTR(handle, HTEXTOP_USERCERTIFICATE); ukey = GETSTR(handle, HTEXTOP_USERPRIVKEY); capath = GETSTR(handle, HTEXTOP_CAPATH); lifetime = GETINT(handle, HTEXTOP_PROXYLIFE); /* Only one is needed if they are the same */ if (ucert && !ukey) ukey = ucert; if (!ucert && ukey) ucert = ukey; /* Cert and key need to be in the same file */ if (strcmp(ucert, ukey) == 0) { keycert = strdup(ucert); } else { FILE *ifp, *ofp; int fd; char c; keycert = strdup("/tmp/.XXXXXX"); fd = mkstemp(keycert); ofp = fdopen(fd, "w"); ifp = fopen(ukey, "r"); while ((c = fgetc(ifp)) != EOF) fputc(c, ofp); fclose(ifp); ifp = fopen(ukey, "r"); while ((c = fgetc(ifp)) != EOF) fputc(c, ofp); fclose(ifp); fclose(ofp); } /* Initialize SSL */ ERR_load_crypto_strings (); OpenSSL_add_all_algorithms(); /* Request a new delegation ID */ soap_get = soap_new(); if (soap_ssl_client_context(soap_get, SOAP_SSL_DEFAULT, keycert, "", NULL, capath, NULL) == 0) { soap_call_tns__getNewProxyReq(soap_get, url, "http://www.gridsite.org/namespaces/delegation-1", &getNewProxyReqResponse); if(soap_get->error == 0) { reqtxt = getNewProxyReqResponse.getNewProxyReqReturn->proxyRequest; delegation_id = strdup(getNewProxyReqResponse.getNewProxyReqReturn->delegationID); /* Generate proxy */ if (GRSTx509MakeProxyCert(&certtxt, stderr, reqtxt, ucert, ukey, lifetime) == GRST_RET_OK) { /* Submit the proxy */ soap_put = soap_new(); if (soap_ssl_client_context(soap_put, SOAP_SSL_DEFAULT, keycert, "", NULL, capath, NULL) == 0) { soap_call_tns__putProxy(soap_put, url, "http://www.gridsite.org/namespaces/delegation-1", delegation_id, certtxt, NULL); if (soap_put->error) { /* Could not PUT */ #ifndef NO_SOAP_SPRINT soap_sprint_fault(soap_put, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); #else soap_print_fault(soap_put, stderr); handle->status = HTEXTS_FAILED; #endif } } else { /* soap_put ssl error */ #ifndef NO_SOAP_SPRINT soap_sprint_fault(soap_put, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); #else soap_print_fault(soap_put, stderr); handle->status = HTEXTS_FAILED; #endif } soap_free(soap_put); } else { htext_error(handle, "Could not generate the proxy"); } } else { /* Could not get ID */ #ifndef NO_SOAP_SPRINT soap_sprint_fault(soap_get, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); #else soap_print_fault(soap_get, stderr); handle->status = HTEXTS_FAILED; #endif } } else { /* soap_get ssl error */ #ifndef NO_SOAP_SPRINT soap_sprint_fault(soap_get, err_buffer, sizeof(err_buffer)); htext_error(handle, err_buffer); #else soap_print_fault(soap_put, stderr); handle->status = HTEXTS_FAILED; #endif } /* Clean soap_get */ soap_free(soap_get); free(keycert); free(certtxt); /* Return delegation ID */ return delegation_id; }
void *htext_copy_method(void *h) { htext_handle *handle = (htext_handle*)h; CURL *curl; char *delegation_id = NULL, *location; htext_partial control; char buffer[CURL_MAX_WRITE_SIZE], err_buffer[CURL_ERROR_SIZE]; char host[64]; /* Create and initialize CURL handle */ curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_buffer); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, htext_header_callback); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, htext_write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &control); curl_easy_setopt(curl, CURLOPT_URL, GETSTR(handle, HTEXTOP_SOURCEURL)); curl_easy_setopt(curl, CURLOPT_USERAGENT, GETSTR(handle, HTEXTOP_CLIENTID)); curl_easy_setopt(curl, CURLOPT_CAPATH, GETSTR(handle, HTEXTOP_CAPATH)); curl_easy_setopt(curl, CURLOPT_CAINFO, GETSTR(handle, HTEXTOP_CAFILE)); curl_easy_setopt(curl, CURLOPT_SSLCERT, GETSTR(handle, HTEXTOP_USERCERTIFICATE)); curl_easy_setopt(curl, CURLOPT_SSLKEY, GETSTR(handle, HTEXTOP_USERPRIVKEY)); curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, GETSTR(handle, HTEXTOP_USERPRIVKEYPASS)); if (GETINT(handle, HTEXTOP_VERBOSITY) > 1) { curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, htext_debug_callback); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); } curl_easy_setopt(curl, CURLOPT_SHARE, handle->curl_share); /* Reserve space for the partials */ handle->partial_done = calloc(sizeof(size_t), 1); handle->partial_total = calloc(sizeof(size_t), 1); handle->partials = 1; /* Do a HEAD to know where do we have to go */ htext_partial_init(&control); control.partial_total = handle->partial_total; control.partial_done = handle->partial_done; control.handle = handle; curl_easy_setopt(curl, CURLOPT_NOBODY, 1); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_HEADERDATA, &control); curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &control); handle->status = HTEXTS_WAITING; htext_log(handle, "Retrieving the actual location"); if (curl_easy_perform(curl) != CURLE_OK) htext_error(handle, buffer); /* If we got it, delegate */ if (handle->status != HTEXTS_FAILED && control.location) location = control.location; else htext_error(handle, "Could not get the location"); /* Delegate */ if (handle->status != HTEXTS_FAILED) { /* Pick from configuration if not available */ if (control.delegation_service == NULL) { control.delegation_service = GETSTR(handle, HTEXTOP_DELEGATION_URL); } /* Not yet? */ if (control.delegation_service == NULL) { htext_error(handle, "Could not get the delegation endpoint"); } /* Build the full URL */ else { snprintf(buffer, sizeof(buffer), "https://%s%s", get_host(location, host), control.delegation_service); htext_log(handle, "Delegation endpoint: %s", buffer); delegation_id = htext_delegate(handle, buffer, err_buffer); htext_log(handle, "Got delegation id %s", delegation_id); } } /* Do the COPY */ if (handle->status != HTEXTS_FAILED) { char *full_url; htext_log(handle, "Running the remote copy"); handle->status = HTEXTS_RUNNING; full_url = malloc(strlen(location) + strlen(delegation_id) + 14); /* Beware: when copying, the user cert is needed, so ignore http:// prefixes, * and assume https:// */ if (strncmp(location, "http:", 5) == 0) { sprintf(full_url, "https:%s&delegation=%s", location + 5, delegation_id); } else { sprintf(full_url, "%s&delegation=%s", location, delegation_id); } curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "COPY"); curl_easy_setopt(curl, CURLOPT_URL, full_url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, htext_copy_write_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &control); /* Need to flush often to get progress */ curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 64); snprintf(buffer, sizeof(buffer), "Destination: %s", GETSTR(handle, HTEXTOP_DESTINATIONURL)); control.headers = curl_slist_append(control.headers, buffer); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, control.headers); control.http_status = 0; /* Reset this */ control.extra = buffer; buffer[0] = '\0'; if (curl_easy_perform(curl) != CURLE_OK) { htext_error(handle, err_buffer); } else if (control.http_status >= 400 || handle->status == HTEXTS_FAILED) { htext_error(handle, NULL); } else { handle->status = HTEXTS_SUCCEEDED; } handle->http_status = control.http_status; free(full_url); } /* Clean up */ free(delegation_id); htext_partial_clean(&control); curl_easy_cleanup(curl); return NULL; }
EXPORT int MM_antisafelame(int action, Imodman *mm_, Arena *arena) { BMM_FUNC_HEADER(); if (action == MM_LOAD) { mm = mm_; GET_USUAL_INTERFACES(); GETINT(stats, I_STATS); BREG_PARENA_DATA(); BREG_PPLAYER_DATA(); return MM_OK; } else if (action == MM_UNLOAD) { ml->ClearTimer(perSecond, 0); UNREG_PARENA_DATA(); UNREG_PPLAYER_DATA(); Lfailload: RELEASEINT(stats); RELEASE_USUAL_INTERFACES(); DO_RETURN(); } else if (action == MM_ATTACH) { /* cfghelp: antisafelame:MinBounty, arena, int, def: 10, mod: antisafelame * The amount of bounty where no more bounty is removed from people in safe. */ ad->minBounty = cfg->GetInt(arena->cfg, "antisafelame", "minbounty", 10); /* cfghelp: antisafelame:SubtractInterval, arena, int, def: 2, mod: antisafelame * How often in seconds to remove one bounty from people in safe zones. */ ad->interval = cfg->GetInt(arena->cfg, "antisafelame", "subtractinterval", 2); mm->RegCallback(CB_SHIPFREQCHANGE, shipfreqchange, arena); mm->RegCallback(CB_PLAYERACTION, playeraction, arena); mm->RegCallback(CB_KILL, playerkill, arena); ml->SetTimer(perSecond, 100, 100, arena, arena); return MM_OK; } else if (action == MM_DETACH) { ml->ClearTimer(perSecond, arena); mm->UnregCallback(CB_KILL, playerkill, arena); mm->UnregCallback(CB_SHIPFREQCHANGE, shipfreqchange, arena); mm->UnregCallback(CB_PLAYERACTION, playeraction, arena); //Lfailattach: DO_RETURN(); } return MM_FAIL; }
bool wxVideoXANIM::CollectInfo() { wxVideoXANIMOutput *xanimProcess; wxString xanim_command; wxStringTokenizer tokenizer; xanimProcess = new wxVideoXANIMOutput; xanim_command = wxT("xanim +v +Zv -Ae "); xanim_command += m_filename; if (!wxExecute(xanim_command, false, xanimProcess)) return false; wxInputStream *infoStream = xanimProcess->GetInputStream(); wxString totalOutput; while (infoStream->GetLastError() == wxSTREAM_NO_ERROR) { char line[100]; infoStream->Read(line, sizeof(line)-1); if (infoStream->LastRead() == 0) break; line[infoStream->LastRead()] = 0; totalOutput += wxString::FromAscii(line); } // This is good for everything ... :-) int position = totalOutput.Find(wxT("Video Codec:")); totalOutput.Remove(0, position+13); position = totalOutput.Find(wxT("depth=")); m_movieCodec = totalOutput(0, position); totalOutput.Remove(0, position); tokenizer.SetString(totalOutput, wxT("\n\r")); // the rest of the line wxString token = tokenizer.GetNextToken(); unsigned long my_long; #define GETINT(i) \ totalOutput.ToULong(&my_long); \ i = my_long; // 'Audio Codec:' totalOutput = tokenizer.GetString(); totalOutput.Remove(0, totalOutput.Find(wxT(":"))+2); position = totalOutput.Find(wxT("Rate")); m_audioCodec = totalOutput(0, position-1); // 'Rate=' totalOutput.Remove(0, totalOutput.Find(wxT("="))+1); GETINT(m_sampleRate); // 'Chans=' totalOutput.Remove(0, totalOutput.Find(wxT("="))+1); GETINT(m_channels); // 'Bps=' totalOutput.Remove(0, totalOutput.Find(wxT("="))+1); GETINT(m_bps); // 'Frame Stats:' tokenizer.Reinit(totalOutput); tokenizer.GetNextToken(); totalOutput = tokenizer.GetString(); totalOutput.Remove(0, totalOutput.Find(wxT(":"))+2); // 'Size=' totalOutput.Remove(0, totalOutput.Find(wxT("="))+1); GETINT(m_size[0]); // 'x' totalOutput.Remove(0,1); GETINT(m_size[1]); // 'Frames=' totalOutput.Remove(0, totalOutput.Find(wxT("="))+1); GETINT(m_frames); // 'avfps=' totalOutput.Remove(0, totalOutput.Find(wxT("="))+1); totalOutput.ToDouble(&m_frameRate); // We wait for the conclusion while (!xanimProcess->IsTerminated()) wxYield(); delete xanimProcess; return true; }
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN * "AS IS" BASIS, AND DAVID GAY AND GUSTAV HALLBERG HAVE NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ #include "runtime.h" #include "../interpret.h" #include <string.h> TYPEDOP(new_bitset, 0, "`n -> `bitset. Returns an empty bitset usable for storing at" " least `n bits.", 1, (value n), OP_LEAF | OP_NOESCAPE, "n.s") { long size = GETINT(n); if (size < 0) runtime_error(error_bad_value); size = (size + 7) >> 3; struct string *newp = alloc_empty_string(size); memset(newp->str, 0, size); return newp; } TYPEDOP(bclear, 0, "`bitset -> `bitset. Clears all bits of `bitset and returns it", 1, (struct string *b), OP_LEAF | OP_NOALLOC | OP_NOESCAPE, "s.s") { TYPEIS(b, type_string);
static int r2plugin(duk_context *ctx) { RLibStruct *lib_struct; int ret = R_TRUE; // args: type, function const char *type = duk_require_string (ctx, 0); if (strcmp (type, "asm")) { eprintf ("TODO: duk.r2plugin only supports 'asm' plugins atm\n"); return R_FALSE; } // call function of 2nd parameter, or get object if (duk_is_function (ctx, 1)) { duk_push_string (ctx, "TODO"); // TODO: this must be the RAsm object to get bits, offset, .. duk_call (ctx, 1); duk_to_object (ctx, 1); } if (!duk_is_object (ctx, 1)) { eprintf ("Expected object or function\n"); return R_FALSE; } duk_to_object (ctx, 1); #define ap asm_plugin ap = R_NEW0 (RAsmPlugin); #define GETSTR(x,y,or) \ duk_dup_top (ctx); \ duk_get_prop_string (ctx, 1, y); \ if (or) { \ const char *str = duk_to_string (ctx, -1); \ x = mystrdup (str? str: or); \ } else { \ x = mystrdup (duk_require_string (ctx, -1)); \ } \ duk_pop (ctx); #define GETINT(x,y,or) \ duk_dup_top (ctx); \ duk_get_prop_string (ctx, 1, y); \ if (or) { \ x = duk_is_number (ctx, -1)? \ duk_to_int (ctx, -1): or; \ } else { \ x = duk_require_int (ctx, -1); \ } \ duk_pop (ctx); #define GETFUN(x,y) \ duk_dup_top (ctx); \ duk_get_prop_string (ctx, 1, y); \ x = duk_require_tval (ctx, 1); \ duk_pop (ctx); // mandatory GETSTR (ap->name, "name", NULL); GETSTR (ap->arch, "arch", NULL); // optional GETSTR (ap->license, "license", "unlicensed"); GETSTR (ap->desc, "description", "JS Disasm Plugin"); GETINT (ap->bits, "bits", 32); // mandatory unless we handle asm+disasm ap->user = duk_require_tval (ctx, -1); //ap->user = duk_dup_top (ctx); // clone object inside user //GETFUN (ap->user, "disassemble"); duk_push_global_stash(ctx); duk_get_prop_string (ctx, 1, "disassemble"); duk_put_prop_string(ctx, -2, "disfun"); // TODO: prefix plugin name somehow ap->disassemble = duk_disasm; duk_push_global_stash(ctx); duk_get_prop_string (ctx, 1, "assemble"); duk_put_prop_string(ctx, -2, "asmfun"); // TODO: prefix plugin name somehow ap->assemble = duk_assemble; #if 0 duk_get_prop_string (ctx, 1, "disassemble"); duk_push_string (ctx, "WINRAR"); duk_call (ctx, 1); #endif #if 0 duk_get_prop_string (ctx, 1, "disassemble"); void *a = duk_require_tval (ctx, -1); if (duk_is_callable (ctx, -1)) { ut8 *b = a; eprintf ("IS FUNCTION %02x %02x \n", b[0], b[1]); } else eprintf ("NOT CALLABLE\n"); ap->user = a; eprintf ("---- %p\n", a); duk_push_string (ctx, "F**K YOU"); //duk_dup_top(ctx); //duk_call_method (ctx, 0); duk_call (ctx, 1); duk_push_tval (ctx, ap->user); // push fun duk_push_string (ctx, "WINRAR"); duk_call (ctx, 1); duk_pop (ctx); #endif // TODO: add support to assemble from js too //ap->assemble = duk_disasm; #define lp lib_struct lp = R_NEW0 (RLibStruct); lp->type = R_LIB_TYPE_ASM; // TODO resolve from handler lp->data = ap; r_lib_open_ptr (Gcore->lib, "duktape.js", NULL, lp); duk_push_boolean (ctx, ret); return 1; }
const ImageIOParameter * ImageSpec::find_attribute (string_view name, ImageIOParameter &tmpparam, TypeDesc searchtype, bool casesensitive) const { ImageIOParameterList::const_iterator iter = extra_attribs.find (name, searchtype, casesensitive); if (iter != extra_attribs.end()) return &(*iter); // Check named items in the ImageSpec structs, not in extra_attrubs #define MATCH(n,t) (((!casesensitive && Strutil::iequals(name,n)) || \ ( casesensitive && name == n)) && \ (searchtype == TypeDesc::UNKNOWN || searchtype == t)) #define GETINT(n) if (MATCH(#n,TypeDesc::TypeInt)) { \ tmpparam.init (#n, TypeDesc::TypeInt, 1, &this->n); \ return &tmpparam; \ } GETINT(nchannels); GETINT(width); GETINT(height); GETINT(depth); GETINT(x); GETINT(y); GETINT(z); GETINT(full_width); GETINT(full_height); GETINT(full_depth); GETINT(full_x); GETINT(full_y); GETINT(full_z); GETINT(tile_width); GETINT(tile_height); GETINT(tile_depth); GETINT(alpha_channel); GETINT(z_channel); // some special cases if (MATCH("geom", TypeDesc::TypeString)) { ustring s = (depth <= 1 && full_depth <= 1) ? ustring::format ("%dx%d%+d%+d", width, height, x, y) : ustring::format ("%dx%dx%d%+d%+d%+d", width, height, depth, x, y, z); tmpparam.init ("geom", TypeDesc::TypeString, 1, &s); return &tmpparam; } if (MATCH("full_geom", TypeDesc::TypeString)) { ustring s = (depth <= 1 && full_depth <= 1) ? ustring::format ("%dx%d%+d%+d", full_width, full_height, full_x, full_y) : ustring::format ("%dx%dx%d%+d%+d%+d", full_width, full_height, full_depth, full_x, full_y, full_z); tmpparam.init ("full_geom", TypeDesc::TypeString, 1, &s); return &tmpparam; } #undef GETINT #undef MATCH return NULL; }