1 /* @source embossupdate application
2 **
3 ** Checks for more recent updates to EMBOSS
4 **
5 ** @author Copyright (C) Peter Rice (ricepeterm@yahoo.co.uk)
6 ** @@
7 **
8 ** This program is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License
10 ** as published by the Free Software Foundation; either version 2
11 ** of the License, or (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 ******************************************************************************/
22 
23 #include "emboss.h"
24 #include "expat.h"
25 #include "zlib.h"
26 
27 
28 
29 
30 /* @prog embossupdate *********************************************************
31 **
32 ** Checks for more recent updates to EMBOSS
33 **
34 ******************************************************************************/
35 
main(int argc,char ** argv)36 int main(int argc, char **argv)
37 {
38     AjPFile outfile = NULL;
39     AjPStr tmpstr = NULL;
40     char tmpver[512] = {'\0'};
41 
42     AjPStr host  = NULL;
43     AjPStr path  = NULL;
44 
45     ajint port = 80;
46 
47     AjPStr updateurl = NULL;
48     AjPStr packagename = NULL;
49     AjPStr updatedbname = NULL;
50 
51     AjPFilebuff updatefile = NULL;
52     AjPStr rdline = NULL;
53     AjPStr updatemsg = NULL;
54     AjPStr initversion = NULL;
55     AjPStr fixversion = NULL;
56     AjPStr embossversion = NULL;
57     AjPStr embosssystem = NULL;
58 
59     ajuint lastfix = 0;
60     ajuint v1 = 0;
61     ajuint v2 = 0;
62     ajuint v3 = 0;
63     ajuint v4 = 0;
64     AjBool updates = ajFalse;
65     AjBool doheader = ajFalse;
66 
67     embInit("embossupdate", argc, argv);
68 
69     outfile = ajAcdGetOutfile("outfile");
70 
71     ajStrAssignS(&packagename, ajNamValuePackage());
72     if (!ajStrGetLen(packagename))
73         ajStrAssignC(&packagename, "EMBOSS");
74 
75     ajStrAssignS(&embossversion, ajNamValueVersion());
76     if (!ajStrGetLen(embossversion))
77         ajStrAssignC(&embossversion, "0.0.0.0");
78 
79     ajFmtScanS(embossversion, "%u.%u.%u.%u", &v1, &v2, &v3, &v4);
80 
81     ajStrAssignS(&embosssystem, ajNamValueSystem());
82     if (!ajStrGetLen(embosssystem))
83         ajStrAssignC(&embosssystem, "(unknown)");
84 
85     ajDebug("package '%S' version '%S' system '%S'\n",
86             packagename, embossversion, embosssystem);
87 
88     updatedbname = ajStrNewC("EMBOSSupdates");
89 
90     if(ajStrMatchC(embosssystem, "windows"))
91         ajFmtPrintS(&updateurl,
92                     "http://emboss.open-bio.org/updates/m%S.fixes",
93                     packagename);
94     else
95         ajFmtPrintS(&updateurl,
96                     "http://emboss.open-bio.org/updates/%S.fixes",
97                     packagename);
98 
99     ajHttpUrlDeconstruct(updateurl, &port, &host, &path);
100 
101     ajDebug("updateurl '%S' host '%S' port %u path '%S'\n",
102            updateurl, host, port, path);
103 
104     updatefile = ajHttpRead(NULL, updatedbname, NULL, host, port, path);
105 
106     if(!updatefile)
107     {
108         ajFmtPrintF(outfile,
109                     "%S release %S: update information not available\n",
110                     packagename, embossversion);
111         ajDie("Failed to read '%S'", updateurl);
112     }
113 
114     ajFilebuffHtmlNoheader(updatefile);
115     doheader = ajFalse;
116 
117     while(ajBuffreadLine(updatefile, &rdline))
118     {
119         ajDebug("doheader %B updates %B version '%S' msglen %u\n%S",
120                doheader, updates, fixversion, ajStrGetLen(updatemsg), rdline);
121 
122         if(doheader)
123         {
124             if(ajStrPrefixC(rdline, "Fix "))
125                 doheader = ajFalse;
126             else
127                 ajStrAppendS(&updatemsg, rdline);
128         }
129 
130         if(ajStrPrefixC(rdline, "Release "))
131         {
132             ajFmtScanS(rdline, "Release %S", &initversion);
133             ajFmtPrintS(&fixversion, "%S.0", initversion);
134             doheader = ajTrue;
135         }
136 
137         if(ajStrPrefixC(rdline, "Fix "))
138         {
139             ajFmtScanS(rdline, "Fix %u", &lastfix);
140             ajFmtPrintS(&fixversion, "%S.%u", initversion, lastfix);
141             doheader = ajFalse;
142         }
143 
144         if(ajStrCmpS(embossversion, fixversion) < 0)
145         {
146             if(!updates)
147                 ajFmtPrintF(outfile,
148                             "\nRelease %S: "
149                             "A more recent version is available\n\n",
150                             embossversion);
151             updates = ajTrue;
152             ajFmtPrintF(outfile, "%S", rdline);
153         }
154     }
155 
156     if(updates)
157     {
158         ajFmtPrintF(outfile, "\n%S", updatemsg);
159     }
160 
161     ajStrAssignC(&tmpstr, ensSoftwareGetVersion());
162     if (!ajStrGetLen(tmpstr))
163         ajStrAssignC(&tmpstr, "(unknown)");
164 
165     c_plgver(tmpver);
166     ajStrAssignC(&tmpstr, tmpver);
167     if (!ajStrGetLen(tmpstr))
168         ajStrAssignC(&tmpstr, "(unknown)");
169 
170 #ifdef ELIBSOURCES
171     ajStrAssignC(&tmpstr, pcre_version());
172 #else
173     ajStrAssignC(&tmpstr, "");
174 #endif
175 
176     if (!ajStrGetLen(tmpstr))
177         ajStrAssignC(&tmpstr, "(unknown)");
178 
179     ajStrAssignC(&tmpstr, zlibVersion());
180     if (!ajStrGetLen(tmpstr))
181         ajStrAssignC(&tmpstr, "(unknown)");
182 
183     ajStrAssignC(&tmpstr, XML_ExpatVersion());
184     if (!ajStrGetLen(tmpstr))
185         ajStrAssignC(&tmpstr, "(unknown)");
186 
187     if(!updates)
188         ajFmtPrintF(outfile, "%S %S is the latest version (%S)\n",
189                     packagename, embossversion, fixversion);
190 
191     ajStrDel(&updatemsg);
192     ajStrDel(&updateurl);
193     ajStrDel(&packagename);
194     ajStrDel(&updatedbname);
195     ajStrDel(&rdline);
196     ajStrDel(&initversion);
197     ajStrDel(&fixversion);
198     ajStrDel(&embossversion);
199     ajStrDel(&embosssystem);
200     ajStrDel(&tmpstr);
201     ajFileClose(&outfile);
202     ajFilebuffDel(&updatefile);
203     ajStrDel(&host);
204     ajStrDel(&path);
205 
206     embExit();
207 
208     return 0;
209 }
210