<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tyszecki &#187; Debian</title>
	<atom:link href="http://tyszecki.org/lang/en-us/category/debian/feed/" rel="self" type="application/rss+xml" />
	<link>http://tyszecki.org</link>
	<description></description>
	<lastBuildDate>Thu, 09 Sep 2010 14:36:10 +0000</lastBuildDate>
	<language>en-us</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Models accepting elements not declared explicitly</title>
		<link>http://tyszecki.org/lang/en-us/2010/07/models-accepting-elements-not-declared-explicitly</link>
		<comments>http://tyszecki.org/lang/en-us/2010/07/models-accepting-elements-not-declared-explicitly#comments</comments>
		<pubDate>Sat, 17 Jul 2010 19:22:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[GSoC]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://tyszecki.org/?p=66</guid>
		<description><![CDATA[Some time ago, Dominique in one of his blog posts described an idea of models accepting unknown parameters. Instead of declaring each element separately, we could use such construct: 'Sshd::MatchElement' =&#62; &#123; accept =&#62; &#123; match_not =&#62; '/Match/i' , type =&#62; 'leaf', value_type =&#62; 'string' &#125; &#125; Since today morning, I was working on this [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago, Dominique <a href="http://ddumont.wordpress.com/2010/05/19/improve-config-upgrade-ep-02-minimal-model-for-opensshs-sshd_config/">in one of his blog posts</a> described an idea of models accepting unknown parameters. Instead of declaring each element separately, we could use such construct:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #ff0000;">'Sshd::MatchElement'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000066;">accept</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>
match_not <span style="color: #339933;">=&gt;</span>  <span style="color: #ff0000;">'/Match/i'</span> <span style="color: #339933;">,</span>
type <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
value_type <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'string'</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-66"></span><br />
Since today morning, I was working on this feature and it is now available for testing, in slightly modified version. With my modifications, you can write a model like this:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>
          <span style="color: #009900;">&#123;</span>
            <span style="color: #ff0000;">'read_config'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>
                               <span style="color: #009900;">&#123;</span>
                                 <span style="color: #ff0000;">'file'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'kismet.conf'</span><span style="color: #339933;">,</span>
                                 <span style="color: #ff0000;">'backend'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'ComplexIni'</span><span style="color: #339933;">,</span>
                                 <span style="color: #ff0000;">'config_dir'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'/home/krzych/configmodel/test'</span>
                               <span style="color: #009900;">&#125;</span>
                             <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Kismet'</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'accept'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>
                           <span style="color: #009900;">&#123;</span>
                            <span style="color: #ff0000;">'match'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'alert|defaultchannels'</span><span style="color: #339933;">,</span>
                            <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'list'</span><span style="color: #339933;">,</span>
                            <span style="color: #ff0000;">'cargo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>
                                          <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'string'</span><span style="color: #339933;">,</span>
                                          <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span>
                                     <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                            <span style="color: #009900;">&#123;</span>
                            <span style="color: #ff0000;">'match'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'.*'</span><span style="color: #339933;">,</span>
                            <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
                            <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'string'</span>
                        <span style="color: #009900;">&#125;</span>
                        <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'element'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>
                           <span style="color: #ff0000;">'version'</span><span style="color: #339933;">,</span>
                           <span style="color: #009900;">&#123;</span>
                             <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'uniline'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Version string'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'mandatory'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span>
                           <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                           <span style="color: #ff0000;">'servername'</span><span style="color: #339933;">,</span>
                           <span style="color: #009900;">&#123;</span>
                             <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'uniline'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Server name'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'mandatory'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Specifies the server name'</span>
                           <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                           <span style="color: #ff0000;">'networkmanagersleep'</span><span style="color: #339933;">,</span>
                           <span style="color: #009900;">&#123;</span>
                             <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'enum'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Try to put NM to sleep when launching Kismet'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'This feature requires  DBus support!'</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'choice'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>
                                           <span style="color: #ff0000;">'true'</span><span style="color: #339933;">,</span>
                                           <span style="color: #ff0000;">'false'</span>
                                         <span style="color: #009900;">&#93;</span>
                           <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                           <span style="color: #ff0000;">'source'</span><span style="color: #339933;">,</span>
                           <span style="color: #009900;">&#123;</span>
                             <span style="color: #ff0000;">'cargo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#123;</span>
                                          <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'string'</span><span style="color: #339933;">,</span>
                                          <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span>
                                        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
                             <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'list'</span>
                           <span style="color: #009900;">&#125;</span>
                         <span style="color: #009900;">&#93;</span>
          <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I decided to make <strong>accept</strong> parameter similar to <strong>element</strong> &#8211; so user can declare more than one rule. Also, the <strong>match</strong> field behaves in the same way like in <strong>element</strong> &#8211; instead of writing &#8216;/channel/&#8217; one has to write &#8216;channel&#8217;. This may be perceived as a limitation, but I wanted to be consistent with existing code.</p>
<p>In this example, there are two <strong>accept</strong> rules. The first defines that all elements with &#8216;alert&#8217; or &#8216;defaultchannels&#8217; in name will be treated as lists &#8211; second one specifies that all remaining elements are to be treated like strings. Notice, that the <strong>element</strong> parameter is still preset &#8211; it has precedence over <strong>accept</strong>. So, the model will parse all items defined in <strong>element</strong> and then try to load the rest using <strong>accept</strong>.</p>
<p>Now you can use this model to edit regular Kismet configuration file:</p>
<div id="attachment_69" class="wp-caption aligncenter" style="width: 160px"><a href="http://tyszecki.org/wp-content/uploads/2010/07/kismet_acc1.png"><img src="http://tyszecki.org/wp-content/uploads/2010/07/kismet_acc-150x150.png" alt="Editing kismet config file" title="kismet_acc" width="150" height="150" class="size-thumbnail wp-image-69" /></a><p class="wp-caption-text">Editing kismet config file</p></div>
<p>As you may see, this model has a small problem &#8211; there are config variables incorrectly recognized as lists (e.g. alertbacklog). It&#8217;s easy to fix, one only needs to modify regexp in <strong>accept</strong> declaration. I made this mistake on purpose &#8211; to show that one needs to define regexps carefully (or maybe it would be good idea to autodetect a type?)</p>
<h3>How it works?</h3>
<p>The most important part of this feature lies in Node.pm file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #666666; font-style: italic;">#Load elements matched by accept parameter</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">accept</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$acc</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">accept</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$mr</span> <span style="color: #339933;">=</span> <span style="color: #000066;">eval</span> <span style="color: #009900;">&#123;</span><span style="color: #000066;">qr</span><span style="color: #339933;">/</span><span style="color: #0000ff;">$acc</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>match<span style="color: #009900;">&#125;</span><span style="color: #339933;">/;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$nvh</span> <span style="color: #339933;">=</span> dclone <span style="color: #0000ff;">$acc</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">delete</span> <span style="color: #0000ff;">$nvh</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>match<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">#Now, $h contains all elements not yet parsed</span>
            <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$elt</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #0000ff;">%$h</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$elt</span> <span style="color: #339933;">=~</span> <span style="color: #0000ff;">$mr</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">#add element...</span>
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>element<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$nvh</span><span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">create_element</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">#add to element list...</span>
                    <span style="color: #000066;">push</span> <span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>element_list<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$elt</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>experience<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'beginner'</span><span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>summary<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>level<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'normal'</span><span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>description<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>status<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'standard'</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">#Setup 'original' values. These are extracted by reset_element_property.</span>
                    <span style="color: #666666; font-style: italic;">#Without these two lines, aforementioned method would set experience and level for</span>
                    <span style="color: #666666; font-style: italic;">#elements added here to 'undef' - rendering model uneditable.</span>
&nbsp;
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>config_model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">config_class_name</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>level<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'normal'</span><span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>config_model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>model<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">config_class_name</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span>experience<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'beginner'</span><span style="color: #339933;">;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">#load value</span>
                    <span style="color: #666666; font-style: italic;">#TODO: annotations</span>
                    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">fetch_element</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$elt</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'master'</span><span style="color: #339933;">,</span> <span style="color: #b1b100;">not</span> <span style="color: #0000ff;">$check</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
                    <span style="color: #0000ff;">$obj</span> <span style="color: #339933;">-&gt;</span><span style="color: #006600;">load_data</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">delete</span> <span style="color: #0000ff;">$h</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$elt</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As you can see, <strong>accept</strong> rules are parsed one by one &#8211; when a match is found, element is added to the model and data is then loaded. Since this is a fresh code written today, it may has a lot of problems, but is a good base to extend this feature.</p>
<p>P.S.  Dominique, I knew that I should make some testcases and then ask  you abut further work, but I couldn&#8217;t resist the urge to code <img src='http://tyszecki.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://tyszecki.org/lang/en-us/2010/07/models-accepting-elements-not-declared-explicitly/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Better INI backend for Config::Model</title>
		<link>http://tyszecki.org/lang/en-us/2010/07/better-ini-backend-for-configmodel</link>
		<comments>http://tyszecki.org/lang/en-us/2010/07/better-ini-backend-for-configmodel#comments</comments>
		<pubDate>Tue, 06 Jul 2010 14:45:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[GSoC]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://tyszecki.org/?p=51</guid>
		<description><![CDATA[Current ini_file backend built into Config::Model works pretty well, but not for all files. Config::Tiny module (used for reading INI files) makes assumption that a variable name cannot be repeated in one section. This statement is true only for about 99% of INI files. Look at the following fragment of valid Kismet config file: # [...]]]></description>
			<content:encoded><![CDATA[<p>Current <strong>ini_file</strong> backend built into Config::Model works pretty well, but not for all files. Config::Tiny module (used for reading INI files) makes assumption that a variable name cannot be repeated in one section. This statement is true only for about 99% of INI files. Look at the following fragment of valid Kismet config file:<br />
<span id="more-51"></span></p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># Sources are defined as:
# source<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">sourcetype,interface,name<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>,initialchannel<span style="">&#93;</span></span></span>
&nbsp;
<span style="color: #000099;">source</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> ipw2100,eth1,intel</span>
<span style="color: #000099;">source</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> madwifi,ath0,atheros</span></pre></div></div>

<p>As you can see, <strong>source</strong> variable is repeated &#8211; in this case, backend based on Config::Tiny will report only one occurrence of it.</p>
<h2>New backend</h2>
<p>I decided to write a new backend. Patching Config::Tiny is not a good idea in my humble opinion &#8211; modifying this module could break applications dependent on it. Dominique suggested that repeated variables should be handled as lists. I had some trouble with Config::Model docs, but with his help I managed to create a fully working backend today.</p>
<h3>Reading file</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;">    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$data</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$section</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$args</span><span style="color: #009900;">&#123;</span>io_handle<span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">getlines</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">next</span> <span style="color: #b1b100;">if</span> <span style="color: #009966; font-style: italic;">/^[;#]/</span> <span style="color: #339933;">;</span>
	<span style="color: #000066;">chomp</span> <span style="color: #339933;">;</span>
	<span style="color: #b1b100;">next</span> <span style="color: #b1b100;">if</span><span style="color: #339933;">/^</span>\<span style="color: #000066;">s</span><span style="color: #339933;">*</span><span style="color: #0000ff;">$/</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">#Update section name</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\[(.*)\]/</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">$section</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$1</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">next</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$name</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\s*=\s*/</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">#Get the 'right' ref</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$r</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$data</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span> <span style="color: #0000ff;">$section</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$section</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">if</span> <span style="color: #b1b100;">not</span> <span style="color: #000066;">defined</span> <span style="color: #0000ff;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$section</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #0000ff;">$r</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$section</span><span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span> <span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">if</span> <span style="color: #000066;">ref</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">ne</span> <span style="color: #ff0000;">'ARRAY'</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">push</span> <span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$val</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #0000ff;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$name</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$val</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">node</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">load_data</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This simple loop goes through all of the lines of a config file and builds a Perl data structure of it. All values are initially stored as strings. When a variable name appears for the second time, it&#8217;s converted to an array of values. Finally, data is loaded into a model using load_data method.</p>
<h4>Problems</h4>
<p>This approach solves only one problem of Config::Tiny &#8211; comments in the file are still lost. However, this can be easily solved &#8211; all I need to do is store comments separately (like in ShellVar backend). Some basic file validation would be good too.</p>
<h3>Files</h3>
<p><a href='http://tyszecki.org/wp-content/uploads/2010/07/ComplexIni.pm'>New backend</a><br />
<a href='http://tyszecki.org/wp-content/uploads/2010/07/Kismet.pl'>Modified Kismet model (source parameter as list)</a></p>
<p>P.S.<br />
I promised to post some notes about Config::Model docs, but I&#8217;ll do it after some more investigation.</p>
]]></content:encoded>
			<wfw:commentRss>http://tyszecki.org/lang/en-us/2010/07/better-ini-backend-for-configmodel/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating configuration model for Kismet</title>
		<link>http://tyszecki.org/lang/en-us/2010/06/creating-configuration-model-for-kismet</link>
		<comments>http://tyszecki.org/lang/en-us/2010/06/creating-configuration-model-for-kismet#comments</comments>
		<pubDate>Thu, 03 Jun 2010 20:46:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[GSoC]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://tyszecki.org/?p=37</guid>
		<description><![CDATA[Introduction Hi everybody! I&#8217;m happy to announce that I have been chosen as a student working on GSoC &#8220;Improve Config file Upgrades&#8221; project for Debian (mentored by Dominique Dumont). Since it&#8217;s my first blog post, it&#8217;s time to introduce myself: My name is Krzysztof Tyszecki and I&#8217;m third year CS student at Wroclaw University of [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Hi everybody!</p>
<p>I&#8217;m happy to announce that I have been chosen as a student working on GSoC &#8220;Improve Config file Upgrades&#8221; project for Debian (mentored by Dominique Dumont). Since it&#8217;s my first blog post, it&#8217;s time to introduce myself:</p>
<p>My name is Krzysztof Tyszecki and I&#8217;m third year CS student at <a href="http://www.portal.pwr.wroc.pl/index,242.dhtml">Wroclaw University of Technology</a> (faculty of Fundamental Problems of Technology). I&#8217;m using GNU/Linux since about 5 years (Gentoo Linux for about ~4 years, now Debian and Arch).</p>
<p>If after a few months you will simply forget about manually editing configuration files after upgrades, that will mean that this project had succeeded. Dominique nicely described some technical details in <a href="http://ddumont.wordpress.com/2010/05/02/improve-config-file-upgrades-ep-01/">post at his blog</a>.<br />
<span id="more-47"></span></p>
<h2>The model</h2>
<p>Since the project will use Config::Model, I was asked to create a simple model to familiarize myself with this tool. I decided to create one for my favorite wireless tool &#8211; <a href="http://kismetwireless.net">Kismet</a>. Kismet config file has the INI structure, as you may see on the snippet below:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># Version of Kismet config
<span style="color: #000099;">version</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">2007.09.R1</span>
&nbsp;
# Name of server <span style="">&#40;</span>Purely for organizational purposes<span style="">&#41;</span>
<span style="color: #000099;">servername</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">Kismet</span>
&nbsp;
# User to setid to <span style="">&#40;</span>should be your normal user<span style="">&#41;</span>
#suiduser<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">your_user_here</span>
&nbsp;
# Do we try to put networkmanager to sleep?  If you use NM, this is probably
# what you want to do, so that it will leave the interfaces alone while
# Kismet is using them.  This requires DBus support!
<span style="color: #000099;">networkmanagersleep</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">true</span>
&nbsp;
# Sources are defined as:
# source<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">sourcetype,interface,name<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>,initialchannel<span style="">&#93;</span></span></span>
# Source types and required drivers are listed in the README under the
# CAPTURE SOURCES section.
# The initial channel is optional, if hopping is not enabled it can be used
# to set the channel the interface listens on.
# YOU MUST CHANGE THIS TO BE THE SOURCE YOU WANT TO USE
<span style="color: #000099;">source</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">none,none,addme</span>
&nbsp;
# Users outside the US might want to use this list:
# defaultchannels<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">IEEE80211b:1,7,13,2,8,3,14,9,4,10,5,11,6,12</span>
<span style="color: #000099;">defaultchannels</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">IEEE80211b:1,6,11,2,7,3,8,4,9,5,10</span>
&nbsp;
# 802.11g uses the same channels as 802.11b...
<span style="color: #000099;">defaultchannels</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">IEEE80211g:1,6,11,2,7,3,8,4,9,5,10</span></pre></div></div>

<p>Of course, it&#8217;s only a small part of the file. Since I didn&#8217;t manage to create a model using config-model-edit, I used Vim, after all a model is just a nice Perl data structure. Part of the results of my work are below:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>
  <span style="color: #009900;">&#123;</span>
     <span style="color: #ff0000;">'read_config'</span> <span style="color: #339933;">=&gt;</span>  <span style="color: #009900;">&#91;</span>
                 <span style="color: #009900;">&#123;</span>
                  <span style="color: #ff0000;">'file'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'kismet.conf'</span><span style="color: #339933;">,</span>
                  <span style="color: #ff0000;">'backend'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'ini_file'</span><span style="color: #339933;">,</span>
                  <span style="color: #ff0000;">'config_dir'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'/etc/kismet'</span>
                <span style="color: #009900;">&#125;</span>
              <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    <span style="color: #ff0000;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Kismet'</span><span style="color: #339933;">,</span>
    <span style="color: #ff0000;">'element'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span>
            <span style="color: #ff0000;">'version'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#123;</span>
              <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'uniline'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Version string'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'servername'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#123;</span>
              <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'uniline'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Server name'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Specifies the server name'</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'suiduser'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#123;</span>
              <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'uniline'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'User to setid to'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'networkmanagersleep'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#123;</span>
              <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'enum'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'choice'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span> <span style="color: #000066;">qw</span><span style="color: #339933;">/</span>true false<span style="color: #339933;">/</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'summary'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'Try to put NM to sleep when launching Kismet'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'This feature requires  DBus support!'</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'source'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#123;</span>
              <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'uniline'</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            <span style="color: #ff0000;">'configchannels'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#123;</span>
              <span style="color: #ff0000;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'leaf'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'value_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'uniline'</span><span style="color: #339933;">,</span>
              <span style="color: #ff0000;">'match'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'IEEE80211(a|ab|b|g):(\d,)*\d'</span>
            <span style="color: #009900;">&#125;</span>
          <span style="color: #009900;">&#93;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The model is far from being complete, but from now, code for other variables can be easily added. Some variables should be also labeled as mandatory.</p>
<h2>The problems</h2>
<p>The biggest problem is that, as you may probably see, my model allows only one &#8220;source&#8221; and &#8220;configchannels&#8221; variable. It&#8217;s because the INI file backend doesn&#8217;t support repeated variables. If you run the following Perl code, you will see that Config::Tiny module used for INI parsing reports only one (last) instance of repeated variable:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #000000; font-weight: bold;">use</span> Config<span style="color: #339933;">::</span><span style="color: #006600;">Tiny</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Data<span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> Dumper<span style="color: #009900;">&#40;</span>Config<span style="color: #339933;">::</span><span style="color: #006600;">Tiny</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">read</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/etc/kismet/kismet.conf'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Besides that, I didn&#8217;t found a way to check the correctness of the value other than regular expression yet. While regexps are powerful and it&#8217;s entirely possible to define constraints using only regexps &#8211; sometimes they&#8217;re just not the best choice. Ability to define a function that would perform the check would be great.</p>
<h2>The GUI Editor</h2>
<p>Dominique asked me for some feedback on config-model-edit, since I had a hard time using it. After loading a model created by hand, it&#8217;s easy to edit it using aforementioned tool, but creating one from scratch may be a hard task, especially if somebody is using config-model-edit for the first time.</p>
<p>After issuing command &#8220;config-model-edit -model Test&#8221; and clicking on the root node, user is presented with such screen:</p>
<p style="text-align: center;">
<div id="attachment_40" class="wp-caption aligncenter" style="width: 310px"><a href="http://tyszecki.org/wp-content/uploads/2010/06/start1.png"><img class="size-medium wp-image-40 " title="config-model-edit main window" src="http://tyszecki.org/wp-content/uploads/2010/06/start-300x161.png" alt="conf-model-edit main window" width="300" height="161" /></a><p class="wp-caption-text">config-model-edit main window</p></div>
<p>User can switch between &#8216;Edit&#8217; and &#8216;View&#8217; modes using right and left mouse buttons, respectively. This is a nice shortcut, but I think that having a button in UI for that would be a nice usability improvement. Well, after switching to edit mode, situation looks like this:</p>
<div id="attachment_42" class="wp-caption aligncenter" style="width: 310px"><a href="http://tyszecki.org/wp-content/uploads/2010/06/edit1.png"><img class="size-medium wp-image-42" title="Editing a model" src="http://tyszecki.org/wp-content/uploads/2010/06/edit-300x161.png" alt="Editing a model" width="300" height="161" /></a><p class="wp-caption-text">Editing a model</p></div>
<p>Color overlays are added by me. Let&#8217;s suppose that the user wants to add a configuration class. He clicks the &#8220;Add&#8221; button and sees an error message with random text:</p>
<div id="attachment_44" class="wp-caption aligncenter" style="width: 310px"><a href="http://tyszecki.org/wp-content/uploads/2010/06/obvious1.png"><img class="size-medium wp-image-44 " title="Everything is obvious now! ;)" src="http://tyszecki.org/wp-content/uploads/2010/06/obvious-300x233.png" alt="Everything is obvious now!" width="300" height="233" /></a><p class="wp-caption-text">Error message</p></div>
<p>It turns out, that he needs to enter the text in edit field and then hit &#8220;Add&#8221; (this button should be disabled if there&#8217;s nothing in the edit field). This is the biggest usability problem and this was the moment when I thought &#8220;Well, I&#8217;ll just use plain, old Vim&#8221;. Other problems, as seen by me:</p>
<ul>
<li>&#8220;Move&#8221; and &#8220;Copy&#8221; (green overlay) buttons are related more to the list box than to the edit field. These buttons could be in a context menu for the list item.</li>
<li>If &#8220;Move&#8221; would be placed in the context menu, instead of renaming highlighted item to the contents of the edit field, it could turn on in-line editing for the list item (I&#8217;m not sure if Tk allows this).</li>
<li>In my humble opinion, &#8220;Rename&#8221; is a more suitable name for &#8220;Move&#8221; button.</li>
<li>&#8220;Copy&#8221; could make a copy of selected item, naming it &#8220;Copy #n of _item_&#8221; and turn on in-line editing on the newly added item.</li>
<li>&#8220;Delete selected&#8221; and &#8220;Remove All&#8221; (red) could be placed below the list box or in the context menu.</li>
<li>&#8220;Are you sure you want to delete all of the items&#8221; confirmation box after clicking &#8220;Remove All&#8221; would be nice.</li>
<li>In this case, &#8220;Info&#8221; box (yellow) takes a lot of space, and it&#8217;s contents are not essential.</li>
<li>The &#8220;keep&#8221; checkbox could be a part of the context menu for the edit field.</li>
</ul>
<p>Of course, current UI may be good once you get used to it and may speedup the process of creating a model. But for a lot of people it can be unnatural and obnoxious. I&#8217;m aware that Tk may not be capable of some of proposed changes. Here&#8217;s the mockup of the interface as I would seen it (created using Qt Designer):</p>
<div id="attachment_46" class="wp-caption aligncenter" style="width: 310px"><a href="http://tyszecki.org/wp-content/uploads/2010/06/mockup1.png"><img class="size-medium wp-image-46" title="Quick and dirty mockup" src="http://tyszecki.org/wp-content/uploads/2010/06/mockup-300x176.png" alt="Quick and dirty mockup" width="300" height="176" /></a><p class="wp-caption-text">Quick and dirty mockup</p></div>
<p>If Tk is limiting the GUI then maybe it would be a good idea to create GTK2 based one, since there are Perl bindings available?</p>
<ul></ul>
]]></content:encoded>
			<wfw:commentRss>http://tyszecki.org/lang/en-us/2010/06/creating-configuration-model-for-kismet/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

