bool FuzzwinAlgorithm::checkSatFromSolver() const { char bufferRead[32] = {0}; // 32 caractères => large, tres large DWORD nbBytesRead = 0; bool result = false; // par défaut pas de réponse du solveur sendToSolver("(check-sat)\n"); Sleep(20); // pour permettre l'écriture des résultats (tricky) // lecture des données dans le pipe (1 seule ligne) BOOL fSuccess = ReadFile(_hReadFromZ3, bufferRead, 32, &nbBytesRead, NULL); if (fSuccess) { std::string bufferString(bufferRead); if ("sat" == bufferString.substr(0,3)) result = true; } else { this->logTimeStamp(); this->log("Erreur de lecture de la reponse du solveur !!"); this->logEndOfLine(); } return result; }
PyObject *PySocket_get_outbound_text(PySocket *self, void *closure) { SOCKET_DATA *sock = PySocket_AsSocket((PyObject *)self); if(sock == NULL) return NULL; else { return Py_BuildValue("s", bufferString(socketGetOutbound(sock))); } }
// // Takes a list of tokens, and builds the proper syntax for the command and // then sends it to the character. void show_parse_syntax_error(CHAR_DATA *ch, const char *cmd, LIST *tokens) { BUFFER *buf = newBuffer(1); LIST_ITERATOR *tok_i = newListIterator(tokens); PARSE_TOKEN *tok = NULL; bool optional_found = FALSE; int count = 0; // go through all of our tokens, and append their syntax to the buf ITERATE_LIST(tok, tok_i) { // make sure we add a space before anything else... if(count > 0) bprintf(buf, " "); count++; // have we encountered the "optional" marker? if so, switch our open/close if(tok->type == PARSE_TOKEN_OPTIONAL) { bprintf(buf, "["); optional_found = TRUE; // we don't want to put a space right after this [ count = 0; continue; } // append our message switch(tok->type) { case PARSE_TOKEN_MULTI: { bprintf(buf, "<"); LIST_ITERATOR *multi_i = newListIterator(tok->token_list); PARSE_TOKEN *mtok = NULL; int m_count = 0; ITERATE_LIST(mtok, multi_i) { if(m_count > 0) bprintf(buf, ", "); m_count++; bprintf(buf, "%s", get_datatype_format_error_mssg(mtok)); } deleteListIterator(multi_i); bprintf(buf, ">"); break; } case PARSE_TOKEN_FLAVOR: bprintf(buf, "%s%s%s", (tok->flavor_optional ? "[" : ""), tok->flavor, (tok->flavor_optional ? "]" : "")); break; default: bprintf(buf, "<%s>", get_datatype_format_error_mssg(tok)); break; } } deleteListIterator(tok_i); // send the message send_to_char(ch, "Proper syntax is: %s %s%s\r\n", cmd, bufferString(buf), (optional_found ? "]" : "")); deleteBuffer(buf); }
// // Send a message with Python statements potentially embedded in it. For //evaluating PyObject *PySocket_send(PyObject *self, PyObject *args, PyObject *kwds) { static char *kwlist[ ] = { "mssg", "dict", "newline", NULL }; SOCKET_DATA *me = NULL; char *text = NULL; PyObject *dict = NULL; bool newline = TRUE; if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|Ob", kwlist, &text, &dict, &newline)) { PyErr_Format(PyExc_TypeError, "Invalid arguments supplied to Mudsock.send"); return NULL; } // is dict None? set it to NULL for expand_to_char if(dict == Py_None) dict = NULL; // make sure the dictionary is a dictionary if(!(dict == NULL || PyDict_Check(dict))) { PyErr_Format(PyExc_TypeError, "Mudsock.send expects second argument to be a dict object."); return NULL; } // make sure we exist if( (me = PySocket_AsSocket(self)) == NULL) { PyErr_Format(PyExc_TypeError, "Tried to send nonexistent socket."); return NULL; } if(dict != NULL) PyDict_SetItemString(dict, "me", self); // build our script environment BUFFER *buf = newBuffer(1); bufferCat(buf, text); // expand out our dynamic descriptions if we have a dictionary supplied if(dict != NULL) { PyObject *env = restricted_script_dict(); PyDict_Update(env, dict); // do the expansion expand_dynamic_descs_dict(buf, env, get_script_locale()); Py_XDECREF(env); } if(newline == TRUE) bufferCat(buf, "\r\n"); text_to_buffer(me, bufferString(buf)); // garbage collection deleteBuffer(buf); return Py_BuildValue(""); }
void hedit_menu(SOCKET_DATA *sock, HELP_OLC *data) { send_to_socket(sock, "{g1) keywords : {c%s\r\n" "{g2) related : {c%s\r\n" "{g3) group restriction: {c%s\r\n" "{g4) Info:\r\n" "{c%s", data->keywords, data->related, data->user_groups, bufferString(data->info)); }
void save_help_olc(HELP_OLC *data) { // first, remove our old helpfile from disc LIST *kwds = parse_keywords(data->old_keywords); char *primary = listGet(kwds, 0); if(primary && *primary) remove_help(primary); deleteListWith(kwds, free); // now, add our new one add_help(data->keywords, bufferString(data->info), data->user_groups, data->related, TRUE); }
bool flush_output(SOCKET_DATA *dsock) { bool success = TRUE; BUFFER *buf = NULL; // run any hooks prior to flushing our text hookRun("flush", hookBuildInfo("sk", dsock)); // quit if we have no output and don't need/can't have a prompt if(bufferLength(dsock->outbuf) <= 0 && (!dsock->bust_prompt || !socketHasPrompt(dsock))) return success; buf = newBuffer(1); // send our outbound text if(bufferLength(dsock->outbuf) > 0) { hookRun("process_outbound_text", hookBuildInfo("sk", dsock)); hookRun("finalize_outbound_text", hookBuildInfo("sk", dsock)); //success = text_to_socket(dsock, bufferString(dsock->outbuf)); bufferCat(buf, bufferString(dsock->outbuf)); bufferClear(dsock->outbuf); } // send our prompt if(dsock->bust_prompt && success) { socketShowPrompt(dsock); hookRun("process_outbound_prompt", hookBuildInfo("sk", dsock)); hookRun("finalize_outbound_prompt", hookBuildInfo("sk", dsock)); //success = text_to_socket(dsock, bufferString(dsock->outbuf)); bufferCat(buf, bufferString(dsock->outbuf)); bufferClear(dsock->outbuf); dsock->bust_prompt = FALSE; } success = text_to_socket(dsock, bufferString(buf)); deleteBuffer(buf); // return our success return success; }
STORAGE_SET *resetStore (RESET_DATA *reset) { STORAGE_SET *set = new_storage_set(); store_int (set, "type", reset->type); store_int (set, "times", reset->times); store_int (set, "chance", reset->chance); store_int (set, "max", reset->max); store_int (set, "room_max", reset->room_max); store_string(set, "arg", bufferString(reset->arg)); store_list (set, "in", gen_store_list(reset->in, resetStore)); store_list (set, "on", gen_store_list(reset->on, resetStore)); store_list (set, "then", gen_store_list(reset->then, resetStore)); return set; }
void MaterializedViewMetadata::parsePredicate(catalog::MaterializedViewInfo *metadata) { std::string hexString = metadata->predicate(); if (hexString.size() == 0) return; assert (hexString.length() % 2 == 0); int bufferLength = (int)hexString.size() / 2 + 1; boost::shared_array<char> buffer(new char[bufferLength]); catalog::Catalog::hexDecodeString(hexString, buffer.get()); std::string bufferString(buffer.get()); json_spirit::Value predicateValue; json_spirit::read( bufferString, predicateValue ); if (!(predicateValue == json_spirit::Value::null)) { json_spirit::Object predicateObject = predicateValue.get_obj(); m_filterPredicate = AbstractExpression::buildExpressionTree(predicateObject); } }
void expand_to_char(CHAR_DATA *ch, const char *mssg, PyObject *dict, const char *locale, bool newline) { BUFFER *buf = newBuffer(1); bufferCat(buf, mssg); if(dict != NULL) { // build the script dictionary PyObject *script_dict = restricted_script_dict(); PyDict_Update(script_dict, dict); // do the expansion expand_dynamic_descs_dict(buf, script_dict, locale); // garbage collection and end Py_XDECREF(script_dict); } if(newline == TRUE) bufferCat(buf, "\r\n"); text_to_char(ch, bufferString(buf)); // garbage collection deleteBuffer(buf); }
const char *resetGetArg (const RESET_DATA *reset) { return bufferString(reset->arg); }
void input_handler() { LIST_ITERATOR *sock_i = newListIterator(socket_list); SOCKET_DATA *sock = NULL; ITERATE_LIST(sock, sock_i) { // Close sockects we are unable to read from, or if we have no handler // to take in input if ((FD_ISSET(sock->control, &rFd) && !read_from_socket(sock)) || listSize(sock->input_handlers) == 0) { close_socket(sock, FALSE); continue; } /* Ok, check for a new command */ next_cmd_from_buffer(sock); // are we idling? if(!sock->cmd_read) sock->idle += 1.0 / PULSES_PER_SECOND; /* Is there a new command pending ? */ else if (sock->cmd_read) { sock->idle = 0.0; IH_PAIR *pair = listGet(sock->input_handlers, 0); if(pair->python == FALSE) { void (* handler)(SOCKET_DATA *, char *) = pair->handler; char *cmddup = strdup(bufferString(sock->next_command)); handler(sock, cmddup); free(cmddup); } else { PyObject *arglist = Py_BuildValue("Os", socketGetPyFormBorrowed(sock), bufferString(sock->next_command)); PyObject *retval = PyEval_CallObject(pair->handler, arglist); // check for an error: if(retval == NULL) log_pyerr("Error with a Python input handler"); // garbage collection Py_XDECREF(retval); Py_XDECREF(arglist); } // append our last command to the command history. History buffer is // 100 commands, so pop off the earliest command if we're going over listPut(sock->command_hist, strdup(bufferString(sock->next_command))); if(listSize(sock->command_hist) > 100) free(listRemoveNum(sock->command_hist, 100)); bufferClear(sock->next_command); // we save whether or not we read a command until our next call to // input_handler(), at which time it is reset to FALSE if we didn't read // sock->cmd_read = FALSE; } #ifdef MODULE_ALIAS // ACK!! this is so yucky, but I can't think of a better way to do it... // if this command was put in place by an alias, decrement the alias_queue // counter by one. This counter is in place mainly so aliases do not end // up calling eachother and making us get stuck in an infinite loop. if(sock->player) { int alias_queue = charGetAliasesQueued(sock->player); if(alias_queue > 0) charSetAliasesQueued(sock->player, --alias_queue); } #endif } deleteListIterator(sock_i); }
// // read an IAC sequence from the socket's input buffer. When we hit a // termination point, send a hook and clear he buffer. Return how many // characters to skip ahead in the input handler int read_iac_sequence(SOCKET_DATA *dsock, int start) { // are we doing subnegotiation? bool subneg = strchr(bufferString(dsock->iac_sequence), SB) != NULL; int i = start; bool done = FALSE; for(; dsock->inbuf[i] != '\0'; i++) { // are we looking for IAC? if(bufferLength(dsock->iac_sequence) == 0) { // Oops! Something is broken if(dsock->inbuf[i] != (signed char) IAC) return 0; else bufferCatCh(dsock->iac_sequence, IAC); } // are we looking for a command? else if(bufferLength(dsock->iac_sequence) == 1) { // did we find subnegotiation? if(dsock->inbuf[i] == (signed char) SB) { bufferCatCh(dsock->iac_sequence, dsock->inbuf[i]); subneg = TRUE; } // basic three-character command else if(dsock->inbuf[i] == (signed char) WILL || dsock->inbuf[i] == (signed char) WONT || dsock->inbuf[i] == (signed char) DO || dsock->inbuf[i] == (signed char) DONT) bufferCatCh(dsock->iac_sequence, dsock->inbuf[i]); // something went wrong else { bufferClear(dsock->iac_sequence); return 2; } } // are we doing subnegotiation? else if(subneg) { int last_i = bufferLength(dsock->iac_sequence) - 2; signed char last = bufferString(dsock->iac_sequence)[last_i]; bufferCatCh(dsock->iac_sequence, dsock->inbuf[i]); // have hit the end of the subnegotiation? Break out if so if(last == (signed char) IAC && dsock->inbuf[i] == (signed char) SE) { done = TRUE; break; } } // this is the end else { bufferCatCh(dsock->iac_sequence, dsock->inbuf[i]); done = TRUE; break; } } int len = i - start + (dsock->inbuf[i] == '\0' ? 0 : 1); // broadcast the message we parsed, and prepare for the next sequence if(done == TRUE) { hookRun("receive_iac", hookBuildInfo("sk str", dsock,bufferString(dsock->iac_sequence))); bufferClear(dsock->iac_sequence); } return len; }
void expand_dynamic_descs_dict(BUFFER *desc, PyObject *dict,const char *locale){ // make our new buffer BUFFER *new_desc = newBuffer(bufferLength(desc)*2); BUFFER *code = newBuffer(1); // for things we have to evaluate bool proc_cond = FALSE; // are we processing a conditional statement? // copy over all of our description that is not dynamic text int start, end, i, j, size = bufferLength(desc); for(i = 0; i < size; i++) { // figure out when our next dynamic desc is. start = next_letter_in(bufferString(desc) + i, '['); // no more if(start == -1) { // copy the rest and skip to the end of the buffer bprintf(new_desc, "%s", bufferString(desc) + i); i = size - 1; } // we have another desc else { // copy everything up to start while(start > 0) { bprintf(new_desc, "%c", *(bufferString(desc) + i)); start--; i++; } // skip the start marker i++; // find our end end = next_letter_in(bufferString(desc) + i, ']'); // make sure we have it if(end == -1) break; // copy everything between start and end, and format the code bufferClear(code); for(j = 0; j < end; j++) bprintf(code, "%c", *(bufferString(desc) + i + j)); bufferReplace(code, "\n", " ", TRUE); bufferReplace(code, "\r", "", TRUE); // skip i up to the end i = i + end; // are we trying to process a conditional statement? if(!strncasecmp(bufferString(code), "if ", 3)) { // strip out the leading if and whitespace char *code_copy = strdup(bufferString(code)); char *ptr = code_copy + 3; while(isspace(*ptr)) ptr++; // copy over the cleaned-up code, signal we're processing a conditional bufferClear(code); bufferCat(code, ptr); proc_cond = TRUE; // garbage collection free(code_copy); } // evaluate the code PyObject *retval = eval_script(dict, bufferString(code), locale); // did we encounter an error? if(retval == NULL) break; // are we evaluating a conditional or no? else if(proc_cond) { BUFFER *cond_retval = expand_dynamic_conditional(desc, dict, retval, locale, &i); // if we have something to print, expand its embedded python if(*bufferString(cond_retval)) expand_dynamic_descs_dict(cond_retval, dict, locale); bufferCat(new_desc, bufferString(cond_retval)); deleteBuffer(cond_retval); proc_cond = FALSE; } // append the output else if(PyString_Check(retval)) bprintf(new_desc, "%s", PyString_AsString(retval)); else if(PyInt_Check(retval)) bprintf(new_desc, "%ld", PyInt_AsLong(retval)); else if(PyFloat_Check(retval)) bprintf(new_desc, "%lf", PyFloat_AsDouble(retval)); // invalid return type... else if(retval != Py_None) log_string("dynamic desc had invalid evaluation: %s", bufferString(code)); // oddly, freeing retval here corrupt memory. // And not freeing it doesn't cause a memory leak. So bizarre... // Py_XDECREF(retval); } } // copy over our contents bufferCopyTo(new_desc, desc); // garbage collection deleteBuffer(code); deleteBuffer(new_desc); }
// // Tries to expand out a conditional statement. Returns whatever is expanded. // Moves i to the proper place after the conditional has been expanded in the // originating buffer. BUFFER *expand_dynamic_conditional(BUFFER *desc, PyObject *dict, PyObject *retval, const char *locale, int *pos) { BUFFER *new_desc = newBuffer(bufferLength(desc)*2); BUFFER *code = newBuffer(1); // code we have to evaluate int j, i = *pos + 1; // +1 to skip the current closing ] bool match = PyObject_IsTrue(retval); while(TRUE) { // copy over all of our contents for the new desc and increment i while(*(bufferString(desc)+i) && !startswith(bufferString(desc)+i, "[else]") && !startswith(bufferString(desc)+i, "[elif ") && !startswith(bufferString(desc)+i, "[/if]")) { if(match == TRUE) bprintf(new_desc, "%c", *(bufferString(desc) + i)); i++; } // did we terminate? if(match == TRUE || startswith(bufferString(desc)+i, "[/if]")) break; // we haven't had a match yet. Are we trying an else or elif? else if(startswith(bufferString(desc)+i, "[else]")) { match = TRUE; i += 6; } else if(startswith(bufferString(desc)+i, "[elif ")) { // skip the elif and spaces i += 6; while(isspace(*(bufferString(desc)+i))) i++; // find our end int end = next_letter_in(bufferString(desc) + i, ']'); // make sure we have it if(end == -1) break; // copy everything between start and end, and format the code bufferClear(code); for(j = 0; j < end; j++) bprintf(code, "%c", *(bufferString(desc) + i + j)); bufferReplace(code, "\n", "", TRUE); // skip i up to and beyond the ] marker i = i + end + 1; // evaluate the code PyObject *retval = eval_script(dict, bufferString(code), locale); match = retval && PyObject_IsTrue(retval); // did we encounter an error? if(retval == NULL) break; } } // skip everything up to our closing [/if] while(*(bufferString(desc)+i) && !startswith(bufferString(desc)+i, "[/if]")) i++; if(startswith(bufferString(desc)+i, "[/if]")) i += 4; // put us at the closing ], not the end of the ending if block // garbage collection deleteBuffer(code); // return our expansion and move our i *pos = i; return new_desc; }