void FilterScriptDialog::openScript() { QString fileName = QFileDialog::getOpenFileName(this,tr("Open Filter Script File"),".", "*.mlx"); if (fileName.isEmpty()) return; scriptPtr->open(fileName); setScript(scriptPtr); }
void scriptCommand(rliteClient *c) { if (c->argc == 2 && !strcasecmp(c->argv[1],"flush")) { scriptingReset(); c->reply = createStatusObject(RLITE_STR_OK); } else if (c->argc >= 2 && !strcasecmp(c->argv[1],"exists")) { int j; c->reply = createArrayObject(c->argc - 2); for (j = 2; j < c->argc; j++) { c->reply->element[j - 2] = createLongLongObject(getScript(c, c->argv[j], NULL, NULL) == RL_OK ? 1 : 0); } } else if (c->argc == 3 && !strcasecmp(c->argv[1],"load")) { char sha[41]; sha1hex(sha,c->argv[2],c->argvlen[2]); setScript(c, c->argv[2], c->argvlen[2]); c->reply = createStringObject(sha,40); } else if (c->argc == 2 && !strcasecmp(c->argv[1],"kill")) { if (lua_caller == NULL) { c->reply = createCStringObject("NOTBUSY No scripts in execution right now.\r\n"); } else if (lua_write_dirty) { c->reply = createCStringObject("UNKILLABLE Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in a hard way using the SHUTDOWN NOSAVE command.\r\n"); } else { lua_kill = 1; c->reply = createStatusObject(RLITE_STR_OK); } } else { c->reply = createErrorObject("ERR Unknown SCRIPT subcommand or wrong # of args."); } }
void deleteOldSessions(t_request *clientRequest, char *username) { char request[1024]; char ret[512]; char *key; t_list *list; t_projects project; if (!clientRequest) return; project = clientRequest->_project; printf("\tChecking for old Sessions : \n"); setDatabase("dumbo"); snprintf(request, 1024, "DELETE FROM sessions WHERE username='******' AND project='%d';", username, clientRequest->_project); /* snprintf(request, 1024, */ /* "DELETE FROM sessions WHERE username='******' AND project='%d'; SELECT ROW_COUNT();", */ /* username, clientRequest->_project); */ setScript(request); if ((list = execRequest())) { if (list->content && list->next && list->next->content) { printf("\t\tNumber of rows deleted : %s", list->next->content); return; } } printf("\tNo old Session found, returning\n"); }
/* Define a lua function with the specified function name and body. * The function name musts be a 2 characters long string, since all the * functions we defined in the Lua context are in the form: * * f_<hex sha1 sum> * * On success RLITE_OK is returned, and nothing is left on the Lua stack. * On error RLITE_ERR is returned and an appropriate error is set in the * client context. */ int luaCreateFunction(rliteClient *c, lua_State *lua, char *funcname, char *body, size_t bodylen) { const char *f = "function "; const char *params = "() "; const char *end = " end"; size_t funcnamelen = 42; size_t funcdeflen = bodylen + funcnamelen + strlen(f) + strlen(params) + strlen(end) + 1; char *funcdef = malloc(sizeof(char) * funcdeflen); strcpy(funcdef, f); funcdeflen = strlen(f); memcpy(&funcdef[funcdeflen], funcname, funcnamelen); funcdeflen += funcnamelen; strcpy(&funcdef[funcdeflen], params); funcdeflen += strlen(params); memcpy(&funcdef[funcdeflen], body, bodylen); funcdeflen += bodylen; strcpy(&funcdef[funcdeflen], end); funcdeflen += strlen(end); funcdef[funcdeflen] = 0; if (luaL_loadbuffer(lua,funcdef,funcdeflen,"@user_script")) { char err[1024]; snprintf(err, 1024, "ERR Error compiling script (new function): %s", lua_tostring(lua,-1)); c->reply = createErrorObject(err); lua_pop(lua,1); free(funcdef); return RLITE_ERR; } free(funcdef); if (lua_pcall(lua,0,0,0)) { char err[1024]; snprintf(err, 1024, "ERR Error running script (new function): %s", lua_tostring(lua,-1)); c->reply = createErrorObject(err); lua_tostring(lua,-1); lua_pop(lua,1); return RLITE_ERR; } /* We also save a SHA1 -> Original script map in a dictionary * so that we can replicate / write in the AOF all the * EVALSHA commands as EVAL using the original script. */ { int retval = setScript(c, body, bodylen); if (retval != RL_OK) { return retval; } } return RLITE_OK; }
static int getDeclinaisons(t_product *product) { char request[1024]; t_list *ret; t_list *tmp; t_list *start; start = NULL; product->declinaisons = NULL; snprintf(request, 1024, "SELECT "\ "Nom, Attribut, Attribut2, CouleurPrimaire, DeclinaisonStock, DeclinaisonPrixTTC, " \ "DeclinaisonPrixHT, DeclinaisonReference "\ "FROM declinaisons WHERE LOWER(DeclinaisonReference) LIKE '%s%%';", product->id); setScript(request); if ((ret = execRequest()) && (tmp = ret) && (ret = ret->next) && ret->content) { while (ret && ret->content) { t_declinaison *current; printf("RET : '%s'\n", ret->content); if (!(current = malloc(sizeof(t_declinaison)))) { perror("malloc"); exit(FAILURE); } setRequestResult(ret->content); getNextResultValue(¤t->Nom); getNextResultValue(¤t->Attribut); getNextResultValue(¤t->Attribut2); getNextResultValue(¤t->CouleurPrimaire); getNextResultValue(¤t->DeclinaisonStock); getNextResultValue(¤t->DeclinaisonPrixTTC); getNextResultValue(¤t->DeclinaisonPrixHT); getNextResultValue(¤t->DeclinaisonReference); setRequestResult(NULL); product->declinaisons = addToList(product->declinaisons, current); if (!start) start = product->declinaisons; ret = ret->next; } product->declinaisons = start; destroyList(tmp, TRUE); return 0; } return FAILURE; }
ScriptDialog::ScriptDialog(const QString &fn, QWidget *parent) : QDialog(parent) { m_fn = fn; QPushButton *okButton = new QPushButton(tr("OK")); QPushButton *applyButton = new QPushButton(tr("Apply")); QPushButton *cancelButton = new QPushButton(tr("Cancel")); cancelButton->setDefault(true); connect(okButton, SIGNAL(clicked()), this, SLOT(saveScript())); connect(applyButton, SIGNAL(clicked()), this, SLOT(applyScript())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *buttonsLayout = new QHBoxLayout; buttonsLayout->addStretch(1); buttonsLayout->addWidget(okButton); buttonsLayout->addWidget(applyButton); buttonsLayout->addWidget(cancelButton); m_pSeqEdit = new QLineEdit; m_pStepsEdit = new QComboBox; connect( m_pSeqEdit, SIGNAL(editingFinished()), this, SLOT(onSeqChanged()) ); connect( m_pStepsEdit, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(onStepChanged(const QString &)) ); QHBoxLayout *hbLayout = new QHBoxLayout; hbLayout->addWidget(m_pSeqEdit); hbLayout->addWidget(m_pStepsEdit); m_pEditor = new CodeEditor; m_pEditor->setTabStopWidth(40); m_pCondEditor = new CodeEditor; m_pCondEditor->setTabStopWidth(40); QHBoxLayout *editorLayout = new QHBoxLayout; editorLayout->addWidget(m_pEditor, 2); editorLayout->addWidget(m_pCondEditor, 1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(hbLayout); mainLayout->addLayout(editorLayout, 1); mainLayout->addStretch(); mainLayout->addLayout(buttonsLayout); setLayout(mainLayout); setWindowTitle(tr("Script Dialog")); if(!m_fn.isEmpty()){ setScript(m_fn); } resize(1024, 600); }
int QDeclarativeStateChangeScript::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDeclarativeStateOperation::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QDeclarativeScriptString*>(_v) = script(); break; case 1: *reinterpret_cast< QString*>(_v) = name(); break; } _id -= 2; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setScript(*reinterpret_cast< QDeclarativeScriptString*>(_v)); break; case 1: setName(*reinterpret_cast< QString*>(_v)); break; } _id -= 2; } else if (_c == QMetaObject::ResetProperty) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 2; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 2; } #endif // QT_NO_PROPERTIES return _id; }
t_bool destroySession(t_request *clientRequest, char*cookieName, char*cookieUser) { t_projects project; t_parameters *cookieJar; t_list *list; char *sessionID; char *username; char request[1024]; project = clientRequest->_project; cookieJar = clientRequest->_cookieJar; printf("\tDeleting existing Session :\n"); if (!(sessionID = getCookie(clientRequest, cookieName))) return FALSE; if (!(username = getCookie(clientRequest, cookieUser))) return FALSE; printf("\t\tCookie found '%s' = '%s'\n", cookieName, sessionID); printf("\t\tCookie found '%s' = '%s'\n", cookieUser, username); setDatabase("dumbo"); snprintf(request, 1024, "DELETE FROM sessions WHERE "\ "username='******' AND project='%d' AND sessionID='%s'; SELECT ROW_COUNT()", username, clientRequest->_project, sessionID); setScript(request); printf("\t\tGoing delete existing session :\n"); if ((list = execRequest())) { list = list->next; if (list->content && strncmp(list->content, "0", 1)) { printf("\tSession Found and deleted.\n"); return TRUE; } destroyList(list, TRUE); } printf("\tSession NOT Found. No Deletion\n"); return FALSE; }
void Opcode80DEHandler::_run() { Logger::debug("SCRIPT") << "[80DE] [*] void start_gdialog(int msgFileID, GameCritterObject* critter, int mood, int headID, int backgroundID)" << std::endl; int backgroundID = _vm->dataStack()->popInteger(); int headID = _vm->dataStack()->popInteger(); int mood = _vm->dataStack()->popInteger(); auto critter = dynamic_cast<Game::CritterObject*>(_vm->dataStack()->popObject()); if (!critter) _error("start_gdialog - wrong critter pointer"); int msgFileID = _vm->dataStack()->popInteger(); auto interact = new State::CritterInteract(); interact->setBackgroundID(backgroundID); interact->setHeadID(headID); interact->setMood(mood); interact->setCritter(critter); interact->setMsgFileID(msgFileID); interact->setScript(_vm); Game::getInstance()->pushState(interact); }
void Opcode80B7::_run() { Logger::debug("SCRIPT") << "[80B7] [+] GameObject* create_object_sid(int PID, int position, int elevation, int SID)" << std::endl; auto SID = _script->dataStack()->popInteger(); auto elevation = _script->dataStack()->popInteger(); auto position = _script->dataStack()->popInteger(); auto PID = _script->dataStack()->popInteger(); auto object = Game::getInstance()->locationState()->addObject(PID, position, elevation); if (SID > 0) { auto intFile = ResourceManager::getInstance()->intFileType(SID); if (intFile) { object->setScript(new VM::Script(intFile, object)); } } if (object->script()) { object->script()->initialize(); } _script->dataStack()->push(object); }
t_bool checkForExistingSession(t_request *clientRequest, char*cookieName, char*cookieUser) { t_projects project; t_parameters *cookieJar; t_list *list; char *sessionID; char *username; char request[1024]; project = clientRequest->_project; cookieJar = clientRequest->_cookieJar; printf("\tChecking for existing Session :\n"); if (!(sessionID = getCookie(clientRequest, cookieName))) return FALSE; if (!(username = getCookie(clientRequest, cookieUser))) return FALSE; printf("\t\tCookie found '%s' = '%s'\n", cookieName, sessionID); printf("\t\tCookie found '%s' = '%s'\n", cookieUser, username); setDatabase("dumbo"); snprintf(request, 1024, "SELECT sessionID FROM sessions WHERE "\ "username='******' AND project='%d' AND sessionID='%s';", username, clientRequest->_project, sessionID); setScript(request); printf("\t\tGoing to check into database for session :\n"); if ((list = execRequest())) { destroyList(list, TRUE); printf("\tSession Found.\n"); return TRUE; } printf("\tSession NOT Found.\n"); return FALSE; }
static t_list *printProductName(t_list **script, t_socket *client) { t_list *list; char request[1024]; t_list *ret; t_list *tmp; char *id; list = NULL; if (!script || !*script) return NULL; printf("\tprintProductName :: \n"); if (!(id = getParameter(client, "id"))) { printf("Missing id parameter\n"); list = addToList(list, ""); return commitResult(list, script); } snprintf(request, 1024, "SELECT ProduitNom FROM produits WHERE ProduitReference='%s' LIMIT 1;", id); setDatabase("lapothicaire"); setScript(request); if ((ret = execRequest()) && (tmp = ret) && (ret = ret->next) && ret->content) { printf("Name was found: %s\n", ret->content); list = addToList(list, strdup(ret->content)); destroyList(tmp, TRUE); } else list = addToList(list, ""); return commitResult(list, script); }
static t_list *getComposition(t_list *list, t_product *product) { char request[1024]; char buffer[1024]; t_list *ret; t_list *tmp; t_list *start; t_composition *current; start = NULL; product->composition = NULL; snprintf(request, 1024, "SELECT "\ "ComposeQuantite, ComposeReference " \ "FROM compositions WHERE ProduitReference='%s';", product->id); setScript(request); if ((ret = execRequest()) && (tmp = ret) && (ret = ret->next) && ret->content) { while (ret && ret->content) { /* printf("RET : '%s'\n", ret->content); */ if (!(current = malloc(sizeof(t_composition)))) { perror("malloc"); exit(FAILURE); } setRequestResult(ret->content); getNextResultValue(¤t->ComposeQuantite); getNextResultValue(¤t->ComposeReference); setRequestResult(NULL); product->composition = addToList(product->composition, current); ret = ret->next; } list = addToList(list, "<h3>Composition : </h3><br/>\n"); start = product->composition; list = addToList(list, "<ul class=\"composition\">\n"); while (start && start->content) { current = start->content; if (current->ComposeReference) { char *name; *request = '\0'; snprintf(request, 1024, "SELECT ProduitNom FROM produits WHERE ProduitReference='%s';", current->ComposeReference); setScript(request); name = execRequestGetValue(); *buffer = '\0'; snprintf(buffer, 1024, "<li><a href='/produit?id=%s'>%s</a> (x%s)</li>\n", current->ComposeReference, name, current->ComposeQuantite); list = addToList(list, strdup(buffer)); } start = start->next; } list = addToList(list, "</ul>\n"); destroyList(tmp, TRUE); } return list; }
ScriptNode::ScriptNode(std::string n, std::string s, Graph* root) : Node(n, root, false), script(this) { setScript(s); init(); }
static t_list *productPage(t_list **script, t_socket *client) { t_list *list; char request[1024]; t_list *ret; t_list *tmp; char *id; char *amount; list = NULL; if (!script || !*script || !client || !client->request) return NULL; printf("\tProductPage :: \n"); if (!(id = getParameter(client, "id"))) { printf("Missing id parameter\n"); list = addToList(list, ""); return commitResult(list, script); } // PARAMS WERE FILLED if ((amount = getParameter(client, "hiddenAmount"))) list = addProductToCart(list, client, id, amount); /* DISPLAY */ snprintf(request, 1024, "SELECT "\ "MarqueId, CategorieId, TVAId, ProduitStockStatut, "\ "ProduitNom, ProduitDescription, ProduitPrixHT, ProduitPrixTTC "\ "FROM produits WHERE ProduitReference='%s' LIMIT 1;", id); setDatabase("lapothicaire"); setScript(request); if ((ret = execRequest()) && (tmp = ret) && (ret = ret->next) && ret->content) { char *content; char *marqueId; char *categorieId; char *TVAId; t_product product; t_list *tmp2; product.id = id; setRequestResult(ret->content); getNextResultValue(&marqueId); getNextResultValue(&categorieId); getNextResultValue(&TVAId); getNextResultValue(&product.ProduitStockStatut); getNextResultValue(&product.ProduitNom); getNextResultValue(&product.ProduitDescription); getNextResultValue(&product.ProduitPrixHT); getNextResultValue(&product.ProduitPrixTTC); setRequestResult(NULL); snprintf(request, 1024, "SELECT CategorieNom FROM categories WHERE CategorieId='%s' LIMIT 1;", categorieId); product.categorie = execRequestGetValue(); snprintf(request, 1024, "SELECT MarqueNom FROM marques WHERE MarqueId='%s' LIMIT 1;", marqueId); product.marque = execRequestGetValue(); snprintf(request, 1024, "SELECT TVAValeur FROM tva WHERE TVAId='%s' LIMIT 1;", TVAId); product.TVA = execRequestGetValue(); destroyList(tmp, FALSE); getDeclinaisons(&product); printf("\tCatégorie : '%s'\n", product.categorie); printf("\tMarque : '%s'\n", product.marque); printf("\tTVA : '%s'\n", product.TVA); printf("\tNom : '%s'\n", product.ProduitNom); printf("\tDescription : '%s'\n", product.ProduitDescription); printf("\tHT : '%s'\n", product.ProduitPrixHT); printf("\tTTC : '%s'\n", product.ProduitPrixTTC); list = displayProduct(list, &product); } else list = addToList(list, "<p>Pas de résultat pour ce produit.</p>"); return commitResult(list, script); }
char *createNewSession(char *username, t_request *clientRequest, char*cookieName, char *cookieUser, t_socket *client) { char request[1024]; char ret[512]; char *key; t_list *list; t_projects project; char *host; t_parameters *cookieJar; char *cookieValue; if (!clientRequest) return NULL; project = clientRequest->_project; /* if (access("./dev", F_OK) != FAILURE) */ host = clientRequest->_host; /* else */ /* host = "localhost"; */ cookieJar = clientRequest->_cookieJar; /* if (checkForExistingSession(username, clientRequest, cookieName) == TRUE) */ /* { */ /* printf("\tWorking session existing. Authentification success.\n"); */ /* return "\r\n"; */ /* } */ if (!(key = getUniqueId())) return NULL; printf("\t\tCreating new session for username='******', project=%d, host='%s'\nKey : %s\n", username, project, host, key); setDatabase("dumbo"); deleteOldSessions(clientRequest, username); snprintf(request, 1024, "INSERT INTO sessions (username, sessionID, project, created, expires)" \ "VALUES ('%s', '%s', '%d', %s, %s); SELECT ROW_COUNT();", username, key, project, "NOW()", "NOW()"); setScript(request); // Checking request result, row_count() must be 1, the inserted row if ((list = execRequest()) && (list && list->content && list->next && list->next->content) && (!strncmp(list->content, "ROW_COUNT()\n", strlen(list->content)) && !strncmp(list->next->content, "1\n", strlen(list->next->content)))) { destroyList(list, TRUE); addParameter(clientRequest, cookieName, key, COOKIE); addParameter(clientRequest, cookieUser, username, COOKIE); // Sending cookies snprintf(ret, 512, "Set-cookie:%s=%s; domain=%s; path=/\r\n"\ "Set-cookie:%s=%s; domain=%s; path=/\r\n\r\n", cookieName, key, host, cookieUser, username, host); if (!(cookieValue = strdup(ret))) return NULL; addCookie(client, cookieName, key); addCookie(client, cookieUser, username); printf("\t\tGenerated Cookies : \n%s\n", cookieValue); return cookieValue; } else printf("\tCould not add session to database\n"); return NULL; }
t_bool authentification(t_list **script, t_socket *client) { t_list *list; char *result; char *host; char *tmp; char cmd[1024]; char buffer[1024]; FILE *fp; char request[1024]; int session; char *database; char *sessionUsername; char *username; char *password; printf("\t\tAuth() -> Starting Execution\n"); t_list *tmpList; t_list *httpHeader; httpHeader = NULL; tmpList = *script; while (tmpList && !httpHeader) { /* printf("ALL :: %s\n", tmpList->content); */ if (tmpList->content && !strncmp(tmpList->content, "HTTP/1.1 ", strlen("HTTP/1.1 "))) httpHeader = tmpList; tmpList = tmpList->prev; } /* if (!httpHeader) */ /* { */ /* printf("\t\tCould not find httpHeader; Returning\n"); */ /* return FALSE; */ /* } */ database = setDatabase(NULL); if (!client) { if (httpHeader) httpHeader->content = HTTP_403; return FALSE; } // Is session already running ? if (checkForExistingSession(client->request, cookie_sessionID, cookie_sessionUsername)) { /* httpHeader->content = HTTP_OK; */ /* list = addToList(NULL, HTTP_OK); */ /* list = addToList(list, "\r\n"); */ printf("\t\tAthentification success; Session already running\n"); return TRUE; } // Session not running but user is trying to auth else if ((username = getParameter(client, "username")) && (password = getParameter(client, "password"))) { // Getting Parameter printf("\t\tParamaters recieved :\n"); printf("\t\t\tUsername = '******' \n", username); printf("\t\t\tPassword = '******' \n", password); setDatabase(database); snprintf(request, 1024, "SELECT * FROM users WHERE username='******'AND password='******';", username, password); setScript(request); if (!(execRequest())) { printf("\t\tAthentification failed; Returning 403\n"); /* (*script)->content = NULL; */ if (httpHeader) httpHeader->content = HTTP_403; getAuthErrorCode(403); return FALSE; } else { if (!(tmp = createNewSession(username, client->request, cookie_sessionID, cookie_sessionUsername, client))) { /* (*script)->content = NULL; */ /* (*script)->content = HTTP_403; */ if (httpHeader) httpHeader->content = HTTP_403; printf("\t\tCould not create session; Returning 403\n"); return FALSE; } else { /* t_list *next; */ /* char buffer[1024]; */ /* *buffer = '\0'; */ /* if (httpHeader) */ /* httpHeader->content = HTTP_OK; */ /* if (!(tmpList = addToList(NULL, tmp))) */ /* { */ /* perror("malloc"); */ /* exit(FAILURE); */ /* } */ /* if (httpHeader) */ /* { */ /* next = httpHeader->next; */ /* printf("next : %s\n", next->content); */ /* tmpList->prev = httpHeader; */ /* tmpList->next = next; */ /* httpHeader->next = tmpList; */ /* } */ /* else */ /* { */ /* printf("DOESN'T HAVE A HTTP HEADER\n"); */ /* insertCookie(tmp); */ /* } */ /* list = addToList(NULL, HTTP_OK); */ /* list = addToList(list, tmp); */ free(tmp); printf("\t\tAthentification success; New Session created\n"); return TRUE; } } } // session not running and missing password and or username... else { printf("\t\tAthentification failed : No session running + No auth parameters; Returning 403\n"); /* (*script)->content = NULL; */ /* (*script)->content = HTTP_403; */ if (httpHeader) httpHeader->content = HTTP_403; return FALSE; } return FALSE; /* return commitResult(list, script); */ }