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
11 ** VERSION NUMBER : $Revision: 1.1 $
13 ** DESCRIPTION : Transform a list of packages into a Gnucomo XML document
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
25 **************************************************************************/
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.
36 *****************************/
38 /* static const char *RCSID = "$Id: rpm_filter.cpp,v 1.1 2003-12-04 10:38:09 arjen Exp $"; */
42 #include "rpm_filter.h"
44 /*=========================================================================
45 ** NAME : constructXML
46 ** SYNOPSIS : int constructXML(message_buffer &in, strstream &xml)
48 ** RETURN VALUE : Create an XML document from a list of RPMs
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".
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.
67 ** LAST MODIFIED : Nov 27, 2003
68 **=========================================================================
71 void rpm_filter::construct_XML(message_buffer &in, std::strstream &xml)
75 scan_email_header(in);
76 construct_header(xml);
78 xml << " <gcmt:data>\n";
79 xml << " <gcmt:parameters class='package'>\n";
83 int version_start, next_version_start;
86 // Separate the package name from the version number
90 next_version_start = i;
94 while (i < ~line - 1 && !(line[i] == '-' && isdigit(line[i + 1])))
100 version_start = next_version_start;
101 next_version_start = i;
106 if (!isdigit(line[version_start + 1]))
108 version_start = next_version_start;
110 String package(line(0,version_start));
111 String version(line(version_start + 1, ~line));
113 // Create the XML element.
115 xml << " <gcmt:parameter name='" << package << "'>\n";
116 xml << " <gcmt:property name='version'>" << version << "</gcmt:property>\n";
117 xml << " </gcmt:parameter>\n";
119 xml << " </gcmt:parameters>\n";
120 xml << " </gcmt:data>\n";
121 xml << "</gcmt:message>\n";
124 static const regex re_rpm("[[:alnum:]+-]+-[0-9][[:alnum:].-]");
126 bool rpm_cooker::check_pattern(String logline)
128 return logline == re_rpm;
131 bool rpm_cooker::cook_this(String logline, UTC arrival)