Author: dfiser
Date: Fri Oct 19 12:50:27 2007
New Revision: 41482
URL: http://svn.opensuse.org/viewcvs/yast?rev=41482&view=rev
Log:
- Created new SCR agent for squid.conf file.
Added:
trunk/squid/agents/config/
trunk/squid/agents/config/Makefile.am
trunk/squid/agents/config/squid.scr
trunk/squid/agents/src/
trunk/squid/agents/src/Makefile.am
trunk/squid/agents/src/Y2CCSquidAgent.cc
trunk/squid/agents/src/debug.h
trunk/squid/agents/src/main.cpp
trunk/squid/agents/src/squid_agent.cpp
trunk/squid/agents/src/squid_agent.h
trunk/squid/agents/src/squid_file.cpp
trunk/squid/agents/src/squid_file.h
trunk/squid/agents/src/squid_parser.cpp
trunk/squid/agents/src/squid_parser.h
Removed:
trunk/squid/agents/squid.scr
Modified:
trunk/squid/agents/Makefile.am
trunk/squid/configure.in.in
trunk/squid/src/Squid.ycp
trunk/squid/yast2-squid.spec.in
Modified: trunk/squid/agents/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/Makefile.am?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- trunk/squid/agents/Makefile.am (original)
+++ trunk/squid/agents/Makefile.am Fri Oct 19 12:50:27 2007
@@ -1,7 +1,3 @@
# Makefile.am for squid/agents
+SUBDIRS = src config
-agent_SCRIPTS =
-
-scrconf_DATA = squid.scr
-
-EXTRA_DIST = $(agent_SCRIPTS) $(scrconf_DATA)
Added: trunk/squid/agents/config/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/config/Makefile.am?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/config/Makefile.am (added)
+++ trunk/squid/agents/config/Makefile.am Fri Oct 19 12:50:27 2007
@@ -0,0 +1,5 @@
+# Makefile.am for squid/agents
+
+scrconf_DATA = squid.scr
+
+EXTRA_DIST = $(scrconf_DATA)
Added: trunk/squid/agents/config/squid.scr
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/config/squid.scr?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/config/squid.scr (added)
+++ trunk/squid/agents/config/squid.scr Fri Oct 19 12:50:27 2007
@@ -0,0 +1,35 @@
+/**
+ * File: squid.scr
+ * Summary:
+ * SCR agent for reading/writing /etc/squid/squid.conf using
+ * ini-agent
+ * Access: read/write
+ * Authors: Daniel Fiser
+ * Example:
+ * `Dir(.squid)
+ * (["http_port", "hierarchy_stoplist", "acl", "cache", "acl", ... ])
+ *
+ * `Read(.squid.http_port)
+ * (["3128 transparent"])
+ *
+ * `Write(.squid.http_port,"3128 accel")
+ * true
+ *
+ * .etc.squid
+ *
+ * `ag_ini(
+ * `IniAgent("/etc/squid/squid.conf",
+ * $["params" : [
+ * $["match" : ["^[ \t]*([^ \t]+)[ \t]+(.+)[ \t]*$", "%s %s"]]
+ * ],
+ * "comments" : ["#.*$", "^[ \t]*$"],
+ * "options" : ["flat", "repeat_names", "global_values"]
+ * ]
+ * )
+ * )
+ */
+.etc.squid
+
+`ag_squid(
+ `SquidAgent("/etc/squid/squid.conf")
+)
Added: trunk/squid/agents/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/Makefile.am?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/Makefile.am (added)
+++ trunk/squid/agents/src/Makefile.am Fri Oct 19 12:50:27 2007
@@ -0,0 +1,28 @@
+#
+# Makefile.am for core/agent-ini/src
+#
+
+AM_CXXFLAGS = -DY2LOG=\"agent-squid\" -Wall -DNDEBUG
+
+plugin_LTLIBRARIES = libpy2ag_squid.la
+noinst_LTLIBRARIES = liby2ag_squid.la
+
+liby2ag_squid_la_SOURCES = \
+ squid_agent.cpp squid_agent.h \
+ squid_parser.cpp squid_parser.h \
+ squid_file.cpp squid_file.h
+
+liby2ag_squid_la_LDFLAGS = -version-info 2:0
+liby2ag_squid_la_LIBADD = @AGENT_LIBADD@
+
+libpy2ag_squid_la_SOURCES = \
+ $(liby2ag_squid_la_SOURCES) \
+ Y2CCSquidAgent.cc
+
+libpy2ag_squid_la_LDFLAGS = -version-info 2:0 \
+ -lboost_regex
+libpy2ag_squid_la_LIBADD = \
+ @AGENT_LIBADD@ \
+ ${Y2UTIL_LIBS}
+
+INCLUDES = -I$(includedir)
Added: trunk/squid/agents/src/Y2CCSquidAgent.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/Y2CCSquidAgent.cc?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/Y2CCSquidAgent.cc (added)
+++ trunk/squid/agents/src/Y2CCSquidAgent.cc Fri Oct 19 12:50:27 2007
@@ -0,0 +1,14 @@
+#undef Y2LOG
+#define Y2LOG "scr"
+#include
+#include
+#undef Y2LOG
+#define Y2LOG "agent-squid"
+
+#include "squid_agent.h"
+
+
+typedef Y2AgentComp <SquidAgent> Y2SquidAgentComp;
+
+Y2CCAgentComp <Y2SquidAgentComp> g_y2ccag_squid ("ag_squid");
+
Added: trunk/squid/agents/src/debug.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/debug.h?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/debug.h (added)
+++ trunk/squid/agents/src/debug.h Fri Oct 19 12:50:27 2007
@@ -0,0 +1,16 @@
+#ifndef _DEBUG_H_
+#define _DEBUG_H_
+
+#ifndef NDEBUG
+#include <iostream>
+#define DBG(exp) \
+ std::cerr << exp << std::endl; \
+ std::cerr.flush()
+#define DBG2(exp) \
+ std::cerr << exp; \
+ std::cerr.flush()
+#else
+#define DBG(exp)
+#endif
+
+#endif
Added: trunk/squid/agents/src/main.cpp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/main.cpp?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/main.cpp (added)
+++ trunk/squid/agents/src/main.cpp Fri Oct 19 12:50:27 2007
@@ -0,0 +1,10 @@
+#include "squid_parser.h"
+
+
+
+int main(int argc, char *argv[])
+{
+ SquidParser parser("/etc/squid/squid.conf");
+ parser.parse();
+ return 0;
+}
Added: trunk/squid/agents/src/squid_agent.cpp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/squid_agent.cpp?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/squid_agent.cpp (added)
+++ trunk/squid/agents/src/squid_agent.cpp Fri Oct 19 12:50:27 2007
@@ -0,0 +1,159 @@
+#include "squid_agent.h"
+using std::string;
+
+SquidAgent::~SquidAgent()
+{
+ if (_parser != NULL)
+ delete _parser;
+}
+
+YCPValue SquidAgent::Read(const YCPPath &path, const YCPValue& arg, const YCPValue& optarg)
+{
+ if (_parser == NULL){
+ y2warning("Can't execute Dir before being mounted.");
+ return YCPNull();
+ }
+
+ YCPList ret;
+ vector *params;
+ int len, len2;
+ string option_name;
+
+ if (path->length() == 1){
+ option_name = path->component_str(0);
+ params = _parser->file.paramsOfOption(option_name);
+ len = params->size();
+
+ for (int i=0; i < len; i++){
+ YCPList sublist;
+ len2 = (*params)[i].size();
+
+ for (int j=0; j < len2; j++){
+ sublist.add(YCPString((*params)[i][j]));
+ }
+ ret.add(sublist);
+ }
+
+ delete params;
+ }
+
+ return ret;
+}
+
+/**
+ * Helper function.
+ */
+static bool convertYCPListOfListOfStringToStd(const YCPList &value, vector &std)
+{
+ int len = value->size();
+ int len2;
+ YCPValue val, val2;
+
+ DBG("len: " << len);
+ for (int i=0; i < len; i++){
+ val = value->value(i);
+ if (val->isList()){
+ vector<string> vec;
+
+ len2 = val->asList()->size();
+
+ for (int j=0; j < len2; j++){
+ val2 = val->asList()->value(j);
+ if (val2->isString()){
+ vec.push_back(val2->asString()->value());
+ }else{
+ return false;
+ }
+ }
+
+ std.push_back(vec);
+ }else{
+ return false;
+ }
+ }
+
+ return true;
+}
+
+YCPBoolean SquidAgent::Write(const YCPPath &path, const YCPValue& value, const YCPValue& arg)
+{
+ if (_parser == NULL){
+ y2warning("Can't execute Dir before being mounted.");
+ return YCPBoolean(false);
+ }
+
+ if (path->length() == 0){ // .
+ DBG("`Write command called with path length 0.");
+ return YCPBoolean(_parser->file.write());
+ }else if (path->length() == 1 && value->isList()){ // .option
+ vector std_value;
+
+ if (convertYCPListOfListOfStringToStd(value->asList(), std_value)){
+ _parser->file.changeOption(path->component_str(0), std_value);
+ return YCPBoolean(true);
+ }
+
+ return YCPBoolean(false);
+ }else if (path->length() == 1 && value->isVoid()){
+ vector std_value;
+
+ _parser->file.changeOption(path->component_str(0), std_value);
+ return YCPBoolean(true);
+ }
+
+ return YCPBoolean(false);
+}
+
+YCPList SquidAgent::Dir(const YCPPath& path)
+{
+ if (_parser == NULL){
+ y2warning("Can't execute Dir before being mounted.");
+ return YCPNull();
+ }
+
+ YCPList ret;
+ vector<string> *options;
+ int len;
+
+ if (path->isRoot() || path->toString() == ".all_options"){
+ if (path->isRoot()){
+ options = _parser->file.options();
+ }else{ // path->toString() == ".all_options"
+ options = _parser->file.allOptions();
+ }
+
+ len = options->size();
+ for (int i=0; i < len; i++){
+ ret.add(YCPString((*options)[i]));
+ }
+
+ delete options;
+ }
+
+ return ret;
+}
+
+YCPValue SquidAgent::otherCommand(const YCPTerm& term)
+{
+ string sym = term->name();
+
+ if (sym == "SquidAgent"){
+ if (term->size() == 1){
+ if (!term->value(0)->isString()){
+ return YCPError("Bad initialization of SquidFile(): agrument must be string.");
+ }
+
+ if (_parser != NULL)
+ delete _parser;
+
+ _parser = new SquidParser(term->value(0)->asString()->value());
+ _parser->parse();
+
+ return YCPVoid();
+ }else{
+ return YCPError("Bad initialization of SquidFile(): 1 argument expected.");
+ }
+ }
+
+ return YCPNull();
+}
Added: trunk/squid/agents/src/squid_agent.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/squid_agent.h?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/squid_agent.h (added)
+++ trunk/squid/agents/src/squid_agent.h Fri Oct 19 12:50:27 2007
@@ -0,0 +1,65 @@
+#ifndef _SQUID_AGENT_H_
+#define _SQUID_AGENT_H_
+
+#include
+#include
+
+#include "squid_parser.h"
+
+/**
+ * This class provides SCR functionality.
+ * Only this class creates YCP values (not SquidParser even SquidFile).
+ */
+class SquidAgent : public SCRAgent{
+ private:
+ SquidParser *_parser;
+
+ public:
+ SquidAgent() : _parser(NULL){}
+ ~SquidAgent();
+
+ /**
+ * Provides SCR Read ().
+ * Returns list where each item refers to one line in conf file. Each item
+ * is list of parameters.
+ * For example:
+ * conf file:
+ * acl QUERY urlpath_regex cgi-bin \?
+ * acl apache rep_header Server ^Apache
+ * SCR::Read:
+ * [ ["QUERY", "urlpath_regex", "cgi-bin", "\?" ],
+ * ["apache", "rep_header", "Server", "^Apache"]
+ * ]
+ *
+ * @param path Path that should be read.
+ * @param arg Additional parameter.
+ */
+ YCPValue Read(const YCPPath &path, const YCPValue& arg = YCPNull(), const YCPValue& optarg = YCPNull() );
+
+ /**
+ * Provides SCR Write ().
+ */
+ YCPBoolean Write(const YCPPath &path, const YCPValue& value, const YCPValue& arg = YCPNull());
+
+ /**
+ * Provides SCR Dir().
+ * If path is '.', than it returns list of available options (defined
+ * in conf file).
+ * If path is '.all_options' it returns list of all options found in
+ * conf file (even not defined - commented...).
+ * Otherwise returns empty list.
+ */
+ YCPList Dir(const YCPPath& path);
+
+ /**
+ * Used for mounting the agent.
+ * .scr file should look like:
+ * .etc.squid
+ * `ag_squid(
+ * `SquidAgent("/path/to/conf/file")
+ * )
+ */
+ YCPValue otherCommand(const YCPTerm& term);
+};
+
+#endif
Added: trunk/squid/agents/src/squid_file.cpp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/squid_file.cpp?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/squid_file.cpp (added)
+++ trunk/squid/agents/src/squid_file.cpp Fri Oct 19 12:50:27 2007
@@ -0,0 +1,261 @@
+#include <algorithm>
+
+#include "squid_file.h"
+using std::string;
+using std::vector;
+using std::map;
+using std::ofstream;
+using std::endl;
+using std::find;
+
+// public:
+SquidFile::SquidFile(std::string filename) : _filename(filename)
+{
+ _options_order.push_back("acl");
+
+ _options_order.push_back("cache");
+ _options_order.push_back("broken_vary_encoding");
+ _options_order.push_back("access_log");
+ _options_order.push_back("follow_x_forwarder_for");
+
+ _options_order.push_back("http_access");
+ _options_order.push_back("http_reply_access");
+ _options_order.push_back("icp_access");
+ _options_order.push_back("htcp_access");
+ _options_order.push_back("htcp_clr_access");
+ _options_order.push_back("miss_access");
+ _options_order.push_back("cache_peer_access");
+ _options_order.push_back("ident_lookup_access");
+ _options_order.push_back("tcp_outgoing_tos");
+ _options_order.push_back("tcp_outgoing_address");
+ _options_order.push_back("reply_body_max_size");
+ _options_order.push_back("log_access");
+ _options_order.push_back("deny_info");
+ _options_order.push_back("always_direct");
+ _options_order.push_back("never_direct");
+ _options_order.push_back("header_access");
+ _options_order.push_back("snmp_access");
+ _options_order.push_back("broken_posts");
+}
+
+SquidFile::~SquidFile()
+{
+ int len = _options.size();
+ for (int i=0; i < len; i++){
+ delete _options[i];
+ }
+}
+
+bool SquidFile::write()
+{
+ DBG("Writing squid conf file.");
+/*
+#ifndef NDEBUG
+ int len2 = _options.size();
+ for (int i=0; i < len2; i++){
+ DBG("");
+ DBG("Option name: \"" << _options[i]->name << "\"");
+ DBG("Comments:");
+ for (unsigned int j=0; j < _options[i]->comments.size(); j++){
+ for (unsigned int k=0; k < _options[i]->comments[j].size(); k++){
+ DBG(" " << _options[i]->comments[j][k]);
+ }
+ DBG("");
+ }
+
+ DBG("Values:");
+ for (unsigned int j=0; j < _options[i]->options.size(); j++){
+ DBG2(" ");
+ for (unsigned int k=0; k < _options[i]->options[j].size(); k++){
+ DBG2(_options[i]->options[j][k] << " ");
+ }
+ DBG("");
+ }
+ }
+#endif
+*/
+
+ int len;
+ ofstream fout(_filename.c_str());
+ if (!fout)
+ return false;
+
+ len = _options.size();
+ for (int i=0; i < len; i++){
+ _writeComments(_options[i]->comments, fout);
+ _writeOptions(_options[i]->name, _options[i]->options, fout);
+ fout << endl;
+ }
+
+ return true;
+}
+
+void SquidFile::addComments(string option_name, vector<string> &comments)
+{
+ if (option_name.size() == 0){
+ option_block_t *new_block = new option_block_t;
+ new_block->comments.push_back(comments);
+ _options.push_back(new_block);
+
+ return;
+ }
+
+ int pos = _posInOptions(option_name);
+ if (pos == -1){
+ option_block_t *new_block = new option_block_t;
+ vector::iterator it = _findProperPlace(option_name);
+
+ new_block->name = option_name;
+ new_block->comments.push_back(comments);
+ _options.insert(it, new_block);
+ return;
+ }
+
+ _options[pos]->comments.push_back(comments);
+}
+
+
+void SquidFile::addConfigOption(string option_name, vector<string> &options)
+{
+ if (option_name.size() == 0){
+ DBG("Can't add option value withou option_name.");
+ return;
+ }
+
+ int pos = _posInOptions(option_name);
+ if (pos == -1){
+ option_block_t *new_block = new option_block_t;
+ vector::iterator it = _findProperPlace(option_name);
+
+ new_block->name = option_name;
+ new_block->options.push_back(options);
+ _options.insert(it, new_block);
+ return;
+ }
+
+ _options[pos]->options.push_back(options);
+}
+
+
+vector<string> *SquidFile::options()
+{
+ vector<string> *ret = new vector<string>();
+ int len = _options.size();
+
+ for (int i=0; i < len; i++){
+ if (_options[i]->name.size() > 0 && _options[i]->options.size() > 0)
+ ret->push_back(_options[i]->name);
+ }
+
+ return ret;
+}
+
+vector<string> *SquidFile::allOptions()
+{
+ vector<string> *ret = new vector<string>();
+ int len = _options.size();
+
+ for (int i=0; i < len; i++){
+ if (_options[i]->name.size() > 0)
+ ret->push_back(_options[i]->name);
+ }
+
+ return ret;
+}
+
+vector *SquidFile::paramsOfOption(std::string option_name)
+{
+ vector *ret = new vector();;
+ int len;
+ int pos = _posInOptions(option_name);
+
+ if (pos != -1){
+ len = _options[pos]->options.size();
+ for (int i=0; i < len; i++){
+ ret->push_back(_options[pos]->options[i]);
+ }
+ }
+
+ return ret;
+}
+
+
+void SquidFile::changeOption(string option_name,
+ vector ¶ms)
+{
+ int pos = _posInOptions(option_name);
+ if (pos == -1){
+ int len = params.size();
+ for (int i=0; i < len; i++){
+ addConfigOption(option_name, params[i]);
+ }
+ }else{
+ _options[pos]->options = params;
+ }
+}
+
+// private:
+int SquidFile::_posInOptions(std::string &name) const
+{
+ int len = _options.size();
+ for (int i=0; i < len; i++){
+ if (_options[i]->name == name)
+ return i;
+ }
+ return -1;
+}
+
+void SquidFile::_writeComments(vector &comments,
+ ofstream &fout) const
+{
+ int len, len2;
+ len = comments.size();
+
+ for (int i=0; i < len; i++){
+ len2 = comments[i].size();
+ for (int j=0; j < len2; j++){
+ fout << comments[i][j] << endl;
+ }
+ }
+}
+
+void SquidFile::_writeOptions(string &option_name,
+ vector &options, ofstream &fout) const
+{
+ int len, len2;
+ len = options.size();
+
+ for (int i=0; i < len; i++){
+ fout << option_name;
+
+ len2 = options[i].size();
+ for (int j=0; j < len2; j++){
+ fout << " " << options[i][j];
+ }
+
+ fout << endl;
+ }
+}
+
+
+vector::iterator SquidFile::_findProperPlace(string &option_name)
+{
+ vector::iterator it;
+ vector::iterator it_end;
+ vector<string>::iterator it_order =
+ find(_options_order.begin(), _options_order.end(), option_name);
+
+ if (it_order == _options_order.end() ||
+ it_order+1 == _options_order.end())
+ return _options.end();
+
+ it_order++;
+ it = _options.begin();
+ it_end = _options.end();
+ for (; it != it_end; it++){
+ if (find(it_order, _options_order.end(), (*it)->name) != _options_order.end())
+ break;
+ }
+
+ return it;
+}
Added: trunk/squid/agents/src/squid_file.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/squid_file.h?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/squid_file.h (added)
+++ trunk/squid/agents/src/squid_file.h Fri Oct 19 12:50:27 2007
@@ -0,0 +1,119 @@
+#ifndef _SQUID_FILE_H_
+#define _SQUID_FILE_H_
+
+#include <string>
+#include <vector>
+#include <map>
+#include <fstream>
+#include <iostream>
+
+#include "debug.h"
+
+
+/**
+ * Class representing configuration file read by parser.
+ */
+class SquidFile{
+ private:
+ /**
+ * Struct which defines block of conf file corresponding with one option.
+ */
+ struct option_block_t{
+ std::string name; /*! name of the option */
+ /*! list of comments. Each comment is list of lines from which
+ * the comment consists of. */
+ std::vectorstd::string > comments;
+ /*! List of options. Each option is list of parameters. */
+ std::vectorstd::string > options;
+ };
+
+ /**
+ * Return position of option with name option_name in vector
+ * _options.
+ * If option_name is not in vector return -1.
+ */
+ int _posInOptions(std::string &name) const;
+
+ /**
+ * Write given comments to fout.
+ */
+ void _writeComments(std::vectorstd::string > &comments,
+ std::ofstream &fout) const;
+ /**
+ * Write given options to fout.
+ */
+ void _writeOptions(std::string &option_name,
+ std::vectorstd::string > &options,
+ std::ofstream &fout) const;
+
+ /**
+ * Find proper place where to push comments or options with name
+ * option_name. This method find the place according to contents
+ * of variable _options_order.
+ */
+ std::vector::iterator
+ _findProperPlace(std::string &option_name);
+
+
+ /**
+ * File where will be written settings.
+ */
+ std::string _filename;
+
+ /**
+ * List of read blocks of options.
+ */
+ std::vector _options;
+
+ /**
+ * Ordered list that defines in which order has to be options.
+ * (Some options must be defined before others)
+ * This list must be filled in constructor.
+ */
+ std::vectorstd::string _options_order;
+ public:
+ SquidFile(std::string filename);
+ ~SquidFile();
+
+ /**
+ * Write settings.
+ */
+ bool write();
+
+ /**
+ * Add comments to the list.
+ */
+ void addComments(std::string option_name, std::vectorstd::string &comments);
+
+ /**
+ * Add configuration option to the list.
+ */
+ void addConfigOption(std::string option_name, std::vectorstd::string &options);
+
+
+ /**
+ * Returns list of all available options.
+ * Memory pointed by returned pointer must be freed!
+ */
+ std::vectorstd::string *options();
+
+ /**
+ * Returns list of all options listed in conf file (even commented).
+ * Memory pointed by returned pointer must be freed!
+ */
+ std::vectorstd::string *allOptions();
+
+ /**
+ * Returns list of parameters of option identified by option_name.
+ * Memory pointed by returned pointer must be freed!
+ */
+ std::vectorstd::string > *paramsOfOption(std::string option_name);
+
+
+ /**
+ * Assign to option with name option_name list of parameters params.
+ */
+ void changeOption(std::string option_name,
+ std::vectorstd::string > ¶ms);
+};
+#endif
Added: trunk/squid/agents/src/squid_parser.cpp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/squid_parser.cpp?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/squid_parser.cpp (added)
+++ trunk/squid/agents/src/squid_parser.cpp Fri Oct 19 12:50:27 2007
@@ -0,0 +1,247 @@
+#include "squid_parser.h"
+#include <string>
+#include <vector>
+#include
+
+using std::string;
+using std::istream;
+using std::vector;
+
+// private:
+void SquidParser::_readNextLine()
+{
+ std::getline(_in, _current_line);
+}
+
+void SquidParser::_changeState(SquidParser::states_t new_state)
+{
+ _current_state = new_state;
+}
+
+SquidParser::regexps_t SquidParser::_matchCurrentLine()
+{
+ if (boost::regex_search(_current_line, _matched, _regexps[R_BLANK_LINE])){
+ return R_BLANK_LINE;
+ }else if (boost::regex_search(_current_line, _matched, _regexps[R_TAGGED_COMMENT])){
+ return R_TAGGED_COMMENT;
+ }else if (boost::regex_search(_current_line, _matched, _regexps[R_COMMENT])){
+ return R_COMMENT;
+ }else if (boost::regex_search(_current_line, _matched, _regexps[R_CONFIG_OPTION])){
+ return R_CONFIG_OPTION;
+ }
+
+ return R_NONE;
+}
+
+void SquidParser::_addCurrentLineToComments()
+{
+ _comments.push_back(_current_line);
+ _readNextLine();
+}
+
+void SquidParser::_setCommentsAsTagged(boost::smatch matched_tag)
+{
+ DBG("_setCommentsAsTagged() - matched_tag: " << matched_tag[1]);
+ _comments_tag = matched_tag[1];
+}
+
+void SquidParser::_setCommentsAsTaggedFromConfigOption(boost::smatch matched_tag)
+{
+ DBG("_setCommentsAsTaggedFromConfigOption() - matched_tag: " << matched_tag[1]);
+
+ string str = matched_tag[1];
+ string::size_type lastPos = str.find_first_not_of(" \t", 0);
+ string::size_type pos = str.find_first_of(" \t", lastPos);
+ _comments_tag = str.substr(lastPos, pos - lastPos);
+}
+
+
+void SquidParser::_saveComments()
+{
+#ifndef NDEBUG
+ DBG("");
+ if (_comments_tag.size() > 0){
+ DBG("===== DUMP TAGGED COMMENTS (tag: " << _comments_tag << ") =====");
+ }else{
+ DBG("===== DUMP COMMENTS =====");
+ }
+ int size = _comments.size();
+ for (int i=0; i < size; i++){
+ DBG(_comments[i]);
+ }
+ DBG("===== DUMP COMMENTS END =====");
+ DBG("");
+#endif
+
+ file.addComments(_comments_tag, _comments);
+
+ _comments.clear();
+ _comments_tag.clear();
+}
+
+
+void SquidParser::_saveConfigOption(boost::smatch matched_option)
+{
+ DBG("_saveConfigOption: " << matched_option[1]);
+ DBG("_saveConfigOption: matched_option.size(): " << matched_option.size());
+ DBG("_saveConfigOption matched_option[2]: " << matched_option[2]);
+
+ string str = matched_option[1];
+ string option_name;
+ vector<string> options;
+
+ string::size_type lastPos = str.find_first_not_of(" \t", 0);
+ string::size_type pos = str.find_first_of(" \t", lastPos);
+
+ option_name = str.substr(lastPos, pos - lastPos);
+
+ lastPos = str.find_first_not_of(" \t", pos);
+ pos = str.find_first_of(" \t", lastPos);
+ while (string::npos != pos || string::npos != lastPos)
+ {
+ options.push_back(str.substr(lastPos, pos - lastPos));
+
+ lastPos = str.find_first_not_of(" \t", pos);
+ pos = str.find_first_of(" \t", lastPos);
+ }
+
+ file.addConfigOption(option_name, options);
+
+ if (matched_option.size() > 2 && ((string)matched_option[2]).size() > 0){
+ vector<string> comments;
+ comments.push_back(matched_option[2]);
+ file.addComments(option_name, comments);
+ }
+}
+
+
+
+void SquidParser::_noinfo()
+{
+ DBG("Entering _noinfo()");
+
+ switch (_matchCurrentLine()){
+ case R_COMMENT:
+ _changeState(S_COMMENT);
+ break;
+ case R_TAGGED_COMMENT:
+ _setCommentsAsTagged(_matched);
+ _changeState(S_TAGGED_COMMENT);
+ break;
+ case R_CONFIG_OPTION:
+ _changeState(S_CONFIG);
+ break;
+ case R_NONE:
+ _changeState(S_ERROR);
+ break;
+ case R_BLANK_LINE:
+ // skip blank lines
+ DBG("skipping blank line");
+ _readNextLine();
+ break;
+ }
+}
+
+void SquidParser::_config()
+{
+ DBG("Entering _config()");
+
+ _saveConfigOption(_matched);
+ _readNextLine();
+ _changeState(S_NOINFO);
+}
+
+void SquidParser::_taggedComment()
+{
+ DBG("Entering _taggedComment()");
+
+ _addCurrentLineToComments();
+
+ switch (_matchCurrentLine()){
+ case R_COMMENT:
+ case R_TAGGED_COMMENT:
+ break;
+ default:
+ _saveComments();
+ _changeState(S_NOINFO);
+ break;
+ }
+}
+
+void SquidParser::_comment()
+{
+ DBG("Entering _comment()");
+
+ _addCurrentLineToComments();
+
+ switch (_matchCurrentLine()){
+ case R_COMMENT:
+ break;
+ case R_TAGGED_COMMENT:
+ _setCommentsAsTagged(_matched);
+ _changeState(S_TAGGED_COMMENT);
+ break;
+ case R_CONFIG_OPTION:
+ _setCommentsAsTaggedFromConfigOption(_matched);
+ _saveComments();
+ _changeState(S_CONFIG);
+ break;
+ default:
+ _saveComments();
+ _changeState(S_NOINFO);
+ break;
+ }
+}
+
+void SquidParser::_error()
+{
+ DBG("Entering _error()");
+ DBG("Some error occured: skipping current line (" << _current_line << ")");
+ _readNextLine(); // ignore this line
+ _changeState(S_NOINFO);
+}
+
+
+
+
+// public:
+SquidParser::SquidParser(std::string filename) :
+ _current_state(S_NOINFO), file(filename)
+{
+ _initRegexps();
+ _in.open(filename.c_str());
+ if (!_in){
+ DBG("Can't open file \"" << filename << "\"");
+ }
+}
+
+
+void SquidParser::parse()
+{
+ DBG("start()");
+
+ _readNextLine();
+
+ while (_current_state != S_END && !_in.eof() && !_in.fail()){
+ switch (_current_state){
+ case S_NOINFO:
+ _noinfo();
+ break;
+ case S_CONFIG:
+ _config();
+ break;
+ case S_TAGGED_COMMENT:
+ _taggedComment();
+ break;
+ case S_COMMENT:
+ _comment();
+ break;
+ case S_ERROR:
+ _error();
+ break;
+ case S_END:
+ return;
+ }
+ }
+}
+
Added: trunk/squid/agents/src/squid_parser.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/agents/src/squid_parser.h?rev=41482&view=auto
==============================================================================
--- trunk/squid/agents/src/squid_parser.h (added)
+++ trunk/squid/agents/src/squid_parser.h Fri Oct 19 12:50:27 2007
@@ -0,0 +1,122 @@
+#ifndef _SQUID_PARSER_H_
+#define _SQUID_PARSER_H_
+
+#include <fstream>
+#include <iostream>
+#include <string>
+#include <vector>
+#include
+
+#include "squid_file.h"
+#include "debug.h"
+
+
+class SquidParser{
+ private:
+ /**
+ * Enumeration of states used by automat.
+ */
+ enum states_t {
+ S_NOINFO,
+ S_CONFIG,
+ S_TAGGED_COMMENT,
+ S_COMMENT,
+ S_ERROR,
+ S_END
+ };
+
+ /**
+ * Identificators of regexps.
+ */
+ typedef enum regexps_t {
+ R_COMMENT,
+ R_TAGGED_COMMENT,
+ R_CONFIG_OPTION,
+ R_BLANK_LINE,
+ R_NONE
+ };
+
+ /**
+ * Input stream.
+ */
+ std::ifstream _in;
+
+ /**
+ * Current line read from _in.
+ */
+ std::string _current_line;
+
+ /**
+ * List of comment lines read from _in.
+ */
+ std::vectorstd::string _comments;
+
+ /**
+ * Tag of read comments.
+ */
+ std::string _comments_tag;
+
+ /**
+ * Matched strings from regexps.
+ */
+ boost::smatch _matched;
+
+ /**
+ * List of regexps (see regexps_t).
+ */
+ boost::regex _regexps[R_NONE + 1];
+
+ /**
+ * Current state of automat.
+ */
+ states_t _current_state;
+
+ void _readNextLine();
+ void _changeState(states_t);
+
+ /**
+ * Match current line against _regexps and return identifier defined
+ * by regexps_t.
+ */
+ regexps_t _matchCurrentLine();
+
+ void _addCurrentLineToComments();
+
+ /**
+ * Set tag to current read comments.
+ */
+ void _setCommentsAsTagged(boost::smatch matched_tag);
+ void _setCommentsAsTaggedFromConfigOption(boost::smatch matched_tag);
+
+ void _saveComments();
+ void _saveConfigOption(boost::smatch matched_option);
+
+ /**
+ * Initialize regexps.
+ */
+ void _initRegexps()
+ {
+ _regexps[R_COMMENT] = "^#";
+ _regexps[R_TAGGED_COMMENT] = "^#.*TAG:[ \\t]*([^ \\t\\n]+)";
+ _regexps[R_CONFIG_OPTION] = "^[ \\t]*([^# \\t][^#]*[^# \\t])[ \\t]*(#.*){0,1}$";
+ _regexps[R_BLANK_LINE] = "^[ \\t]*$";
+ }
+
+
+ void _noinfo();
+ void _config();
+ void _taggedComment();
+ void _comment();
+ void _error();
+ public:
+ SquidFile file;
+
+ SquidParser(std::string filename);
+ ~SquidParser(){}
+
+ /**
+ * Start parsing of _in.
+ */
+ void parse();
+};
+#endif
Modified: trunk/squid/configure.in.in
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/configure.in.in?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- trunk/squid/configure.in.in (original)
+++ trunk/squid/configure.in.in Fri Oct 19 12:50:27 2007
@@ -2,10 +2,16 @@
## Initialize
@YAST2-INIT-COMMON@
+@YAST2-INIT-PROGRAM@
@YAST2-INIT-YCP@
+#PKG_CHECK_MODULES([Y2UTIL], [liby2util])
+# AC_SUBST(Y2UTIL_CFLAGS)
+# AC_SUBST(Y2UTIL_LIBS)
+
## some common checks
@YAST2-CHECKS-COMMON@
+@YAST2-CHECKS-PROGRAM@
@YAST2-CHECKS-YCP@
## and generate the output...
Modified: trunk/squid/src/Squid.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/src/Squid.ycp?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- trunk/squid/src/Squid.ycp (original)
+++ trunk/squid/src/Squid.ycp Fri Oct 19 12:50:27 2007
@@ -788,37 +788,33 @@
{
boolean ok = true;
list tmp = [];
- list tmp2 = [];
map tmp_http_port = $[];
http_ports = [];
- foreach (string value, (list<string>)SCR::Read(add(squid_path,"http_port")),
+ foreach (list<string> value, (list)SCR::Read(add(squid_path,"http_port")),
{
tmp_http_port = $[];
tmp = [];
- tmp2 = [];
-
- tmp = split(value," \t");
//can parse only 'http_port hostname:port [transparent]'
- if (size(tmp) < 1 || size(tmp) > 2){
+ if (size(value) < 1 || size(value) > 2){
ok = false;
return false;
}
// hostname and port
- tmp2 = split(tmp[0]:"",":");
- y2debug("readHttpPorts - tmp2: %1",tmp2);
- if (size(tmp2) == 1){
+ tmp = split(value[0]:"",":");
+ y2debug("readHttpPorts - tmp: %1",tmp);
+ if (size(tmp) == 1){
tmp_http_port["host"] = "";
- tmp_http_port["port"] = tmp2[0]:"";
+ tmp_http_port["port"] = tmp[0]:"";
}else{
- tmp_http_port["host"] = (string)tmp2[0]:"";
- tmp_http_port["port"] = tmp2[1]:"";
+ tmp_http_port["host"] = tmp[0]:"";
+ tmp_http_port["port"] = tmp[1]:"";
}
//transparent option
- if (size(tmp) == 2 && tmp[1]:"" == "transparent")
+ if (size(value) == 2 && value[1]:"" == "transparent")
tmp_http_port["transparent"] = true;
http_ports = add(http_ports, tmp_http_port);
@@ -836,23 +832,20 @@
boolean readHttpAccesses()
{
boolean ok = true;
- list tmp = [];
map tmp_http_access = $[];
http_accesses = [];
- foreach (string value, (list<string>)SCR::Read( add(squid_path,"http_access")),
+ foreach (list<string> value, (list)SCR::Read( add(squid_path,"http_access")),
{
tmp_http_access = $[];
- tmp = split(value, " \t");
-
- if (tmp[0]:"" != "allow" && tmp[0]:"" != "deny"){
+ if (value[0]:"" != "allow" && value[0]:"" != "deny"){
ok = false;
return false;
}
- tmp_http_access["allow"] = (tmp[0]:"" == "allow" ? true : false);
- tmp_http_access["acl"] = remove(tmp, 0);
+ tmp_http_access["allow"] = (value[0]:"" == "allow" ? true : false);
+ tmp_http_access["acl"] = remove(value, 0);
http_accesses = add(http_accesses, tmp_http_access);
});
@@ -869,33 +862,30 @@
boolean readRefreshPatterns()
{
boolean ok = true;
- list tmp = [];
map tmp_refresh_pattern = $[];
refresh_patterns = [];
- foreach (string value, (list<string>)SCR::Read( add(squid_path, "refresh_pattern")),
+ foreach (list<string> value, (list)SCR::Read( add(squid_path, "refresh_pattern")),
{
tmp_refresh_pattern = $[];
- tmp = split(value, " \t");
-
//case-insesitive
- if (tmp[0]:"" == "-i"){
+ if (value[0]:"" == "-i"){
tmp_refresh_pattern["case_sensitive"] = false;
- tmp = remove(tmp, 0);
+ value = remove(value, 0);
}else{
tmp_refresh_pattern["case_sensitive"] = true;
}
- if (size(tmp) < 4){
+ if (size(value) < 4){
ok = false;
return false;
}
- tmp_refresh_pattern["regexp"] = tmp[0]:"";
- tmp_refresh_pattern["min"] = tmp[1]:"";
- tmp_refresh_pattern["percent"] = deletechars(tmp[2]:"","%");
- tmp_refresh_pattern["max"] = tmp[3]:"";
+ tmp_refresh_pattern["regexp"] = value[0]:"";
+ tmp_refresh_pattern["min"] = value[1]:"";
+ tmp_refresh_pattern["percent"] = deletechars(value[2]:"","%");
+ tmp_refresh_pattern["max"] = value[3]:"";
refresh_patterns = add(refresh_patterns, tmp_refresh_pattern);
});
@@ -912,7 +902,6 @@
boolean readACLs()
{
boolean ok = true;
- list tmp = [];
map tmp_acl = $[];
//list of types which contains regular expression
@@ -925,20 +914,18 @@
];
acls = [];
- foreach (string value, (list<string>)SCR::Read( add(squid_path, "acl")),
+ foreach (list<string> value, (list)SCR::Read( add(squid_path, "acl")),
{
tmp_acl = $[];
- tmp = split(value, " \t");
-
- if (size(tmp) < 3){
+ if (size(value) < 3){
ok = false;
return false;
}
- tmp_acl["name"] = tmp[0]:"";
- tmp_acl["type"] = tmp[1]:"";
- tmp_acl["options"] = remove(remove(tmp,0),0);
+ tmp_acl["name"] = value[0]:"";
+ tmp_acl["type"] = value[1]:"";
+ tmp_acl["options"] = remove(remove(value,0),0);
// Special settings:
// concat list of regular expressions into one option
@@ -981,8 +968,9 @@
settings = $[];
foreach (string key, list value, parameters,
{
- tmp = (list <string>)SCR::Read( add(squid_path, key));
- tmp = split(tmp[0]:"", " \t");
+ tmp = (list)SCR::Read( add(squid_path, key));
+ //tmp = split(tmp[0]:"", " \t");
+ tmp = tmp[0]:[];
if (size(tmp) > 0){
settings[key] = tmp;
@@ -1100,15 +1088,19 @@
boolean writeHttpPorts()
{
boolean ok = true;
- list<string> scr = [];
- string tmp = "";
+ list scr = [];
+ list<string> tmp = [];
foreach (map value, http_ports,
{
- tmp = value["host"]:"";
- if (size(value["host"]:"") > 0) tmp = tmp + ":";
- tmp = tmp + value["port"]:"";
- if (value["transparent"]:false) tmp = tmp + " transparent";
+ tmp = [];
+
+ if (size(value["host"]:"") > 0){
+ tmp[0] = value["host"]:"" + ":" + value["port"]:"";
+ }else{
+ tmp[0] = value["port"]:"";
+ }
+ if (value["transparent"]:false) tmp[1] = "transparent";
scr = add(scr, tmp);
});
@@ -1123,14 +1115,16 @@
boolean writeACLs()
{
boolean ok = true;
- list<string> scr = [];
- string tmp = "";
+ list scr = [];
+ list<string> tmp = [];
foreach (map value, acls,
{
- tmp = value["name"]:"";
- tmp = tmp + " " + value["type"]:"";
- tmp = tmp + " " + mergestring(value["options"]:[], " ");
+ tmp = [];
+
+ tmp[0] = value["name"]:"";
+ tmp[1] = value["type"]:"";
+ tmp = (list<string>)merge(tmp, value["options"]:[]);
scr = add(scr, tmp);
});
@@ -1145,17 +1139,19 @@
boolean writeHttpAccesses()
{
boolean ok = true;
- list<string> scr = [];
- string tmp = "";
+ list scr = [];
+ list<string> tmp = [];
foreach (map value, http_accesses,
{
+ tmp = [];
+
if (value["allow"]:true){
- tmp = "allow";
+ tmp[0] = "allow";
}else{
- tmp = "deny";
+ tmp[0] = "deny";
}
- tmp = tmp + " " + mergestring(value["acl"]:[], " ");
+ tmp = (list<string>)merge(tmp, (list<string>)value["acl"]:[]);
scr = add(scr, tmp);
});
@@ -1170,17 +1166,18 @@
boolean writeRefreshPatterns()
{
boolean ok = true;
- list<string> scr = [];
- string tmp = "";
+ list scr = [];
+ list<string> tmp = [];
foreach (map value, refresh_patterns,
{
- tmp = "";
- if (!value["case_sensitive"]:false) tmp = "-i ";
- tmp = tmp + value["regexp"]:"";
- tmp = tmp + " " + value["min"]:"";
- tmp = tmp + " " + value["percent"]:"";
- tmp = tmp + " " + value["max"]:"";
+ tmp = [];
+
+ if (!value["case_sensitive"]:false) tmp[0] = "-i ";
+ tmp = add(tmp, value["regexp"]:"");
+ tmp = add(tmp, value["min"]:"");
+ tmp = add(tmp, value["percent"]:"");
+ tmp = add(tmp, value["max"]:"");
scr = add(scr, tmp);
});
@@ -1195,15 +1192,13 @@
boolean writeRestSetting()
{
boolean ok = true;
- string tmp = "";
list<string> setting = nil;
foreach (string key, list value, parameters,
{
- tmp = mergestring(settings[key]:[], " ");
- if (size(tmp) > 0){
- y2debug("Squid::Write - %1: %2", key, tmp);
- if (!SCR::Write(add(squid_path, key), [tmp])){
+ if (size(value) > 0){
+ y2debug("Squid::Write - %1: %2", key, value);
+ if (!SCR::Write(add(squid_path, key), [value])){
y2error("Squid::Write - cannot write %1 setting", key);
ok = false;
}
Modified: trunk/squid/yast2-squid.spec.in
URL: http://svn.opensuse.org/viewcvs/yast/trunk/squid/yast2-squid.spec.in?rev=41482&r1=41481&r2=41482&view=diff
==============================================================================
--- trunk/squid/yast2-squid.spec.in (original)
+++ trunk/squid/yast2-squid.spec.in Fri Oct 19 12:50:27 2007
@@ -2,7 +2,7 @@
@HEADER@
Requires: yast2 filesystem
-BuildRequires: perl-XML-Writer update-desktop-files yast2 yast2-devtools yast2-testsuite
+BuildRequires: perl-XML-Writer update-desktop-files yast2 yast2-devtools yast2-testsuite yast2-core-devel boost-devel
BuildArchitectures: noarch
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org