static void processLine(QString line) { if (line.isEmpty()) return; if (line[0] == '#') { if (line[1] == '#') qDebug("%s", line.toLatin1().constData()); return; } QString command; popArg(command, line); if (command.isEmpty()) return; if (command == "COOKIE") processCookie(line); else if (command == "CHECK") processCheck(line); else if (command == "CLEAR") processClear(line); else if (command == "CONFIG") processConfig(line); else if (command == "SAVE") saveCookies(); else FAIL(QString("Unknown command '%1'").arg(command)); }
static int processDoc(xmlDoc *doc, lpc2xml_context *ctx) { int ret = 0; xmlNs *xsi_ns; xmlNs *lpc_ns; xmlAttr *schemaLocation; xmlNode *root_node = xmlNewNode(NULL, (const xmlChar *)"config"); if(root_node == NULL) { lpc2xml_log(ctx, LPC2XML_ERROR, "Can't create \"config\" element"); return -1; } lpc_ns = xmlNewNs(root_node, (const xmlChar *)"http://www.linphone.org/xsds/lpconfig.xsd", NULL); if(lpc_ns == NULL) { lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create lpc namespace"); } else { xmlSetNs(root_node, lpc_ns); } xsi_ns = xmlNewNs(root_node, (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance", (const xmlChar *)"xsi"); if(lpc_ns == NULL) { lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create xsi namespace"); } schemaLocation = xmlNewNsProp(root_node, xsi_ns, (const xmlChar *)"schemaLocation", (const xmlChar *)"http://www.linphone.org/xsds/lpconfig.xsd lpconfig.xsd"); if(schemaLocation == NULL) { lpc2xml_log(ctx, LPC2XML_WARNING, "Can't create schemaLocation"); } ret = processConfig(root_node, ctx); xmlDocSetRootElement(doc, root_node); return ret; }
bool Parser::leerFichero(const std::string &strName, Globals *pGlobals) { m_pGlobals = pGlobals; // Inicializamos el puntero para rellenar los datos. m_fileEscena.open(strName.c_str()); // Abrimos el fichero. if(!m_fileEscena.is_open()) { m_nError = 7; return false; } if(!m_fileEscena.good()) { if(m_fileEscena.bad()) m_nError = 4; else if(m_fileEscena.fail()) m_nError = 5; else m_nError = 6; return false; } do { if(!ignorarChars()) { if(!m_bEOF) // No hemos llegado al fin de archivo. Error. return false; } else { std::string strEtiqueta; if(readToken(strEtiqueta)) { // Procesar las etiquetas encontradas. if(strEtiqueta == "config") { if(!processConfig()) return false; } else if(strEtiqueta == "scene") { if(!processScene()) return false; } else { m_nError = 0; // Etiqueta desconocida. return false; } } else { m_nError = 0; // Etiqueta desconocida. return false; } } } while(!m_bEOF); m_nError = 10; // Si llegamos hasta aquí, es que el fichero se ha leido return true; // bien y al completo. }
static int processDoc(xmlNode *node, xml2lpc_context *ctx) { dumpNode(node, ctx); if (node->type == XML_ELEMENT_NODE && strcmp((const char*)node->name, "config") == 0 ) { processConfig((xmlElement*)node, ctx); } else { xml2lpc_log(ctx, XML2LPC_WARNING, "root element is not \"config\", line:%d", xmlGetLineNo(node)); } return 0; }
void ConfigFile::loadConfig(const char* filepath) { char* sett_name = nullptr; char* sett_value = nullptr; char buffer[50]; char curr_char; size_t pos = 0; bool is_found_eq_sign = 0; FILE* fp; if ((fp = fopen(filepath, "r"))) { while ((curr_char = (char) fgetc(fp)) != EOF) { switch (curr_char) { case '=': { sett_name = strndup(buffer, pos); pos = 0; is_found_eq_sign = 1; break; } case '\n': { if (is_found_eq_sign == 1) { sett_value = strndup(buffer, pos); push(sett_name, sett_value); } else if (strndup(buffer, pos)[0] != '[') { fprintf(stderr, "[ERROR] Error parsing the config file: No '=' found in the current line.\n"); } pos = 0; is_found_eq_sign = 0; break; } default: { buffer[pos] = curr_char; pos++; } } } fclose(fp); processConfig(); } else { writeDefaultConfig(fp); } }
void JsonApiHandlerHttp::processApi(const string &data, const Params ¶msGET) { jsonParam.clear(); //parse the json data json_error_t jerr; json_t *jroot = json_loads(data.c_str(), 0, &jerr); if (!jroot || !json_is_object(jroot)) { cDebugDom("network") << "Error loading json : " << jerr.text << ". No JSON, trying with GET parameters."; jsonParam = paramsGET; if (jroot) { json_decref(jroot); jroot = nullptr; } } else { char *d = json_dumps(jroot, JSON_INDENT(4)); if (d) { cDebugDom("network") << d; free(d); } //decode the json root object into jsonParam jansson_decode_object(jroot, jsonParam); } //check for if username/password matches string user = Utils::get_config_option("calaos_user"); string pass = Utils::get_config_option("calaos_password"); if (Utils::get_config_option("cn_user") != "" && Utils::get_config_option("cn_pass") != "") { user = Utils::get_config_option("cn_user"); pass = Utils::get_config_option("cn_pass"); } if (user != jsonParam["cn_user"] || pass != jsonParam["cn_pass"]) { cDebugDom("network") << "Login failed!"; Params headers; headers.Add("Connection", "close"); headers.Add("Content-Type", "text/html"); string res = httpClient->buildHttpResponse(HTTP_400, headers, HTTP_400_BODY); sendData.emit(res); closeConnection.emit(0, string()); if (jroot) { json_decref(jroot); jroot = nullptr; } return; } //check action now if (jsonParam["action"] == "get_home") processGetHome(); else if (jsonParam["action"] == "get_state") processGetState(jroot); else if (jsonParam["action"] == "get_states") processGetStates(); else if (jsonParam["action"] == "query") processQuery(); else if (jsonParam["action"] == "get_param") processGetParam(); else if (jsonParam["action"] == "set_param") processSetParam(); else if (jsonParam["action"] == "del_param") processDelParam(); else if (jsonParam["action"] == "set_state") processSetState(); else if (jsonParam["action"] == "get_playlist") processGetPlaylist(); else if (jsonParam["action"] == "poll_listen") processPolling(); else if (jsonParam["action"] == "get_cover") processGetCover(); else if (jsonParam["action"] == "get_camera_pic") processGetCameraPic(); else if (jsonParam["action"] == "get_timerange") processGetTimerange(); else if (jsonParam["action"] == "camera") processCamera(); else { if (!jroot) { Params headers; headers.Add("Connection", "close"); headers.Add("Content-Type", "text/html"); string res = httpClient->buildHttpResponse(HTTP_400, headers, HTTP_400_BODY); sendData.emit(res); closeConnection.emit(0, string()); if (jroot) json_decref(jroot); return; } if (jsonParam["action"] == "config") processConfig(jroot); else if (jsonParam["action"] == "get_io") processGetIO(jroot); else if (jsonParam["action"] == "audio") processAudio(jroot); else if (jsonParam["action"] == "audio_db") processAudioDb(jroot); else if (jsonParam["action"] == "set_timerange") processSetTimerange(jroot); else if (jsonParam["action"] == "autoscenario") processAutoscenario(jroot); } if (jroot) json_decref(jroot); }