Major redesign. All input is handled through XML. Raw input data is first
[gnucomo.git] / src / gcm_input / rpm_filter.cpp
1
2 /**************************************************************************
3 **  (c) Copyright 2003, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 **      FILE NAME      : rpm_filter.cpp
10 **      SYSTEM NAME    : 
11 **      VERSION NUMBER : $Revision: 1.1 $
12 **
13 **  DESCRIPTION      :  Transform a list of packages into a Gnucomo XML document
14 **
15 **  EXPORTED OBJECTS : 
16 **  LOCAL    OBJECTS : 
17 **  MODULES  USED    :
18 ***************************************************************************
19 **  ADMINISTRATIVE INFORMATION *
20 ********************************
21 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 **      CREATION DATE   : Nov 27, 2003
23 **      LAST UPDATE     : Nov 27, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: rpm_filter.cpp,v $
29    Revision 1.1  2003-12-04 10:38:09  arjen
30    Major redesign. All input is handled through XML. Raw input data is first
31    transformed into an XML document for further processing.
32    A collection of polymorphic classes handle the transformation of various
33    input formats into XML.
34    Classifying input data is done with a finite improbability calculation.
35
36 *****************************/
37
38 /* static const char *RCSID = "$Id: rpm_filter.cpp,v 1.1 2003-12-04 10:38:09 arjen Exp $"; */
39
40 #include <ctype.h>
41
42 #include "rpm_filter.h"
43
44 /*=========================================================================
45 **  NAME           : constructXML
46 **  SYNOPSIS       : int constructXML(message_buffer &in, strstream &xml)
47 **  PARAMETERS     : 
48 **  RETURN VALUE   : Create an XML document from a list of RPMs
49 **
50 **  DESCRIPTION    : 
51 **                   Scan a list of packages and versions from "rpm -a".
52 **                   A similar listing can be created on IRIX 6.5 by using the
53 **                   command "showprods -3 -n|awk '{printf "%s-%s\n",$2,$3}'|grep -v '^[-=]' \
54 **                             |grep -v Version-Description".
55 **                 
56 **                   We have to separate the package name and the version.
57 **                   The separation is marked by a '-', followed by a digit.
58 **                   However, there may be other sequences of '-'digit in the package name,
59 **                   do we have to scan ahead until there is at most one such sequence
60 **                   left in the version string. The '-'digit seqeunce inside the
61 **                   version usually separates the version and the release number.
62 **
63 **  VARS USED      :
64 **  VARS CHANGED   :
65 **  FUNCTIONS USED :
66 **  SEE ALSO       :
67 **  LAST MODIFIED  : Nov 27, 2003
68 **=========================================================================
69 */
70
71 void rpm_filter::construct_XML(message_buffer &in, std::strstream &xml)
72 {
73    String line;
74
75    scan_email_header(in);
76    construct_header(xml);
77
78    xml << "  <gcmt:data>\n";
79    xml << "    <gcmt:parameters class='package'>\n";
80
81    while (in >> line)
82    { 
83       int  version_start, next_version_start;
84       int  i;
85
86       //   Separate the package name from the version number
87  
88       i = line.index('-');
89       version_start = i;
90       next_version_start = i;
91
92       while (i < ~line - 1)
93       {
94          while (i < ~line - 1 && !(line[i] == '-' && isdigit(line[i + 1])))
95          {
96             i++;
97          }
98          if (i < ~line - 1)
99          {
100             version_start = next_version_start;
101             next_version_start = i;
102          }
103          i++;
104       }
105       
106       if (!isdigit(line[version_start + 1]))
107       {
108          version_start = next_version_start;
109       }
110       String package(line(0,version_start));
111       String version(line(version_start + 1, ~line));
112
113       //   Create the XML element.
114
115       xml << "    <gcmt:parameter name='" << package << "'>\n";
116       xml << "      <gcmt:property name='version'>" << version << "</gcmt:property>\n";
117       xml << "    </gcmt:parameter>\n";
118    }
119    xml << "    </gcmt:parameters>\n";
120    xml << "  </gcmt:data>\n";
121    xml << "</gcmt:message>\n";
122 }
123
124 static const regex re_rpm("[[:alnum:]+-]+-[0-9][[:alnum:].-]");
125
126 bool rpm_cooker::check_pattern(String logline)
127 {
128    return logline == re_rpm;
129 }
130
131 bool rpm_cooker::cook_this(String logline, UTC arrival)
132 {
133    return true;
134 }