AREXPORT bool ArServerHandlerConfig::loadDefaultsFromFile(void) { bool ret = true; lockConfig(); if (myDefault != NULL) { delete myDefault; myDefault = NULL; } if (!myDefaultFile.empty()) { createDefaultConfig(myDefaultFileBaseDir.c_str()); myDefault->clearAllValueSet(); // now fill in that copy if (myDefault->parseFile(myDefaultFile.c_str())) { addDefaultServerCommands(); } else { ret = false; ArLog::log(ArLog::Normal, "Did not load default file '%s' successfully, not allowing getDefault", myDefaultFile.c_str()); delete myDefault; myDefault = NULL; } if (myDefault != NULL) myDefault->removeAllUnsetValues(); } unlockConfig(); ArNetPacket emptyPacket; myServer->broadcastPacketTcp(&emptyPacket, "configDefaultsUpdated"); return ret; }
AREXPORT bool ArServerHandlerConfig::loadDefaultsFromPacket( ArNetPacket *packet) { bool ret = true; lockConfig(); if (myDefault != NULL) { delete myDefault; myDefault = NULL; } createDefaultConfig(NULL); myDefault->clearAllValueSet(); // now fill in that copy if (internalSetConfig(NULL, packet)) { addDefaultServerCommands(); } else { ArLog::log(ArLog::Normal, "Did not load default from packet successfully, not allowing getDefault"); delete myDefault; myDefault = NULL; } if (myDefault != NULL) myDefault->removeAllUnsetValues(); unlockConfig(); ArNetPacket emptyPacket; myServer->broadcastPacketTcp(&emptyPacket, "configDefaultsUpdated"); return ret; }
AREXPORT void ArServerHandlerConfig::createEmptyConfigDefaults(void) { lockConfig(); if (myDefault != NULL) { delete myDefault; myDefault = NULL; } addDefaultServerCommands(); unlockConfig(); ArNetPacket emptyPacket; myServer->broadcastPacketTcp(&emptyPacket, "configDefaultsUpdated"); }
bool ArServerHandlerConfig::internalSetConfig(ArServerClient *client, ArNetPacket *packet) { char param[1024]; char argument[1024]; char errorBuffer[1024]; char firstError[1024]; ArNetPacket retPacket; ArConfig *config; bool ret = true; if (client != NULL) config = myConfig; else config = myDefault; if (client != NULL) lockConfig(); ArArgumentBuilder *builder = NULL; if (client != NULL) ArLog::log(ArLog::Normal, "Got new config from client %s", client->getIPString()); else ArLog::log(ArLog::Verbose, "New default config"); errorBuffer[0] = '\0'; firstError[0] = '\0'; while (packet->getDataReadLength() < packet->getDataLength()) { packet->bufToStr(param, sizeof(param)); packet->bufToStr(argument, sizeof(argument)); builder = new ArArgumentBuilder; builder->setExtraString(param); builder->add(argument); ArLog::log(ArLog::Verbose, "Config: %s %s", param, argument); // if the param name here is "Section" we need to parse sections, // otherwise we parse the argument if ((strcasecmp(param, "Section") == 0 && !config->parseSection(builder, errorBuffer, sizeof(errorBuffer))) || (strcasecmp(param, "Section") != 0 && !config->parseArgument(builder, errorBuffer, sizeof(errorBuffer)))) { if (firstError[0] == '\0') strcpy(firstError, errorBuffer); } delete builder; builder = NULL; } if (firstError[0] == '\0') { if (config->callProcessFileCallBacks(true, errorBuffer, sizeof(errorBuffer))) { if (client != NULL) ArLog::log(ArLog::Normal, "New config from client %s was fine.", client->getIPString()); else ArLog::log(ArLog::Verbose, "New default config was fine."); retPacket.strToBuf(""); writeConfig(); } else // error processing config callbacks { ret = false; if (firstError[0] == '\0') strcpy(firstError, errorBuffer); // if its still empty it means we didn't have anything good in the errorBuffer if (firstError[0] == '\0') strcpy(firstError, "Error processing"); if (client != NULL) ArLog::log(ArLog::Normal, "New config from client %s had errors processing ('%s').", client->getIPString(), firstError); else ArLog::log(ArLog::Normal, "New default config had errors processing ('%s').", firstError); retPacket.strToBuf(firstError); } } else { ret = false; if (client != NULL) ArLog::log(ArLog::Normal, "New config from client %s had at least this problem: %s", client->getIPString(), firstError); else ArLog::log(ArLog::Normal, "New default config had at least this problem: %s", firstError); retPacket.strToBuf(firstError); } //printf("Sending "); //retPacket.log(); if (client != NULL) client->sendPacketTcp(&retPacket); if (client != NULL) unlockConfig(); if (client != NULL) configUpdated(client); return ret; }
void Moto::slotUnlock() { unlockConfig(); }