├── .clang-format ├── .github └── workflows │ └── clang-format-check.yml ├── .gitignore ├── AUTHORS ├── CHANGES.md ├── COPYING ├── COPYING.LIB ├── ChangeLog.old ├── INSTALL ├── Makefile.am ├── README.md ├── castget.1 ├── castgetrc.5 ├── castgetrc.example ├── configure.ac ├── contrib └── Dockerfile ├── src ├── Makefile.am ├── castget.c ├── channel.c ├── channel.h ├── configuration.c ├── configuration.h ├── date_parsing.c ├── date_parsing.h ├── filenames.c ├── filenames.h ├── htmlent.c ├── htmlent.h ├── libxmlutil.c ├── libxmlutil.h ├── patterns.c ├── patterns.h ├── progress.c ├── progress.h ├── rss.c ├── rss.h ├── urlget.c ├── urlget.h ├── utils.c └── utils.h └── tests ├── Makefile.am ├── mocks.c ├── mocks.h ├── test_filenames.c ├── test_patterns.c └── test_progress.c /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Google 3 | ColumnLimit: 80 4 | IndentWidth: 2 5 | ContinuationIndentWidth: 4 6 | UseTab: Never 7 | BreakBeforeBraces: Linux 8 | AllowShortBlocksOnASingleLine: false 9 | AllowShortCaseLabelsOnASingleLine: false 10 | AllowShortFunctionsOnASingleLine: None 11 | AllowShortIfStatementsOnASingleLine: false 12 | AllowShortLoopsOnASingleLine: false 13 | SortIncludes: true 14 | AlignConsecutiveMacros: true 15 | IndentCaseLabels: false 16 | Cpp11BracedListStyle: false 17 | IncludeCategories: 18 | - Regex: '^<.*\.h>' 19 | Priority: 2 20 | SortPriority: 0 21 | - Regex: '.*' 22 | Priority: 1 23 | SortPriority: 0 24 | ... 25 | -------------------------------------------------------------------------------- /.github/workflows/clang-format-check.yml: -------------------------------------------------------------------------------- 1 | name: clang-format Check 2 | on: [push] 3 | jobs: 4 | formatting-check: 5 | name: Formatting Check 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v2 9 | - name: Run clang-format style check for C programs. 10 | uses: jidicula/clang-format-action@v2.0.0 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | compile 2 | configure 3 | depcomp 4 | install-sh 5 | libtool 6 | test-driver 7 | ltmain.sh 8 | Makefile 9 | Makefile.in 10 | m4 11 | missing 12 | mkinstalldirs 13 | stamp-h1 14 | autom4te.cache 15 | config.guess 16 | config.h 17 | config.h.in 18 | config.h.in~ 19 | config.log 20 | config.status 21 | config.sub 22 | aclocal.m4 23 | po 24 | .libs 25 | .deps 26 | *.o 27 | *.log 28 | *.trs 29 | *.dirstamp 30 | src/castget 31 | tests/test_progress 32 | tests/test_patterns 33 | tests/test_filenames 34 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Marius L. Jøhndal 2 | Jick Nan 3 | Wilhelm Schuster 4 | Tony Armistead 5 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | This is a summary of changes between each release. See the commit log on 2 | https://github.com/mlj/castget/commits/master for a details. 3 | 4 | Version 2.0.1 (2019/10/26): 5 | 6 | * Fix broken man pages in distribution (issue #37) 7 | 8 | Version 2.0.0 (2019/10/12): 9 | 10 | * Add support for filename patterns (configuration option `filename`, issue #13, issue #21) 11 | * Behaviour change: The `-f`/`--filter` option and the filter configuration 12 | options now match the URLs of enclosures instead of the filenames castget 13 | infers for them 14 | * Refuse to overwrite existing downloads unless explicitly asked to resume a 15 | download 16 | * Require glib >= 2.30 and make regular expression support mandatory 17 | * Drop autogen.sh and require autoreconf when building from git 18 | * Enable libcurl's compression support (PR #28) 19 | * Fix feeds with enclosure type `audio/mp3` (PR #30) 20 | 21 | Version 1.2.4 (2017/05/17): 22 | 23 | * Fix build issues involving man pages (issue #20) 24 | 25 | Version 1.2.3 (2017/05/16): 26 | 27 | * Fix lack of support for https (issue #10, issue #14, PR #15) 28 | * Fix broken handling of COLUMNS environment variable etc. (PR #16) 29 | * Improve error reporting when enclosure download fails 30 | * Check sanity of reported length of enclosures in feeds 31 | * Fix MacOS build 32 | * Replace ChangeLog and NEWS files with CHANGES file 33 | 34 | Version 1.2.2 (2016/01/26): 35 | 36 | * Fix width of the progress bar. 37 | 38 | Version 1.2.1 (2016/01/04): 39 | 40 | * Fix broken enclosure filenames. 41 | 42 | Version 1.2.0 (2013/07/10): 43 | 44 | * Add command line option -p for an optional progress bar. 45 | * Add command line option --debug for optional connection debugging. 46 | * Use glib's option parsing. 47 | * Fix incorrect memory allocation when enclosure download fails. 48 | * Document proxy configuration. 49 | 50 | Version 1.1.0 (2010/02/20): 51 | 52 | * New command line option --rcfile for specifying an alternate location for 53 | the configuration file. 54 | 55 | * New command line option --filter and configuration key filter for 56 | restricting operations to enclosures matching a regular 57 | expression. This feature requires glib >= 2.14 and can be disabled 58 | by supplying --disable-gregex to configure. 59 | 60 | * Distribution files are compressed with bzip2. 61 | 62 | Version 1.0.1 (2007/11/14): 63 | 64 | * castget now identifies itself using the HTTP User-Agent header. 65 | 66 | See https://github.com/mlj/castget/blob/4ac9ebd27b35838ae102ff50cf973645614d314e/ChangeLog 67 | for changes between version 0.9.0 (2005/11/14) and version 1.0.0 (2007/09/20). 68 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | -------------------------------------------------------------------------------- /COPYING.LIB: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 489 | 490 | Also add information on how to contact you by electronic and paper mail. 491 | 492 | You should also get your employer (if you work as a programmer) or your 493 | school, if any, to sign a "copyright disclaimer" for the library, if 494 | necessary. Here is a sample; alter the names: 495 | 496 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 497 | library `Frob' (a library for tweaking knobs) written by James Random Hacker. 498 | 499 | , 1 April 1990 500 | Ty Coon, President of Vice 501 | 502 | That's all there is to it! 503 | 504 | 505 | -------------------------------------------------------------------------------- /ChangeLog.old: -------------------------------------------------------------------------------- 1 | This changelog is no longer updated. 2 | 3 | See the NEWS file for a summary of changes between each release. 4 | 5 | See the commit log on https://github.com/mlj/castget/commits/master for a 6 | detailed breakdown of recent changes. 7 | 8 | --- 9 | 10 | 2013-07-02 Marius L. Jøhndal 11 | 12 | * Avoid updating progress bar unless actually changed. 13 | 14 | 2013-07-01 Marius L. Jøhndal 15 | 16 | * Limit the number of prints when updating the progess bar. 17 | 18 | 2013-06-24 Marius L. Jøhndal 19 | 20 | * Fixed incorrect freeing of enclosure_full_filename on enclosure write failure. 21 | * Ensure that output starts on new line after download with progress bar enabled. 22 | 23 | 2013-06-16 Marius L. Jøhndal 24 | 25 | * Switched to glib's options parsing. 26 | * Corrected location of binaries in gitignore file. 27 | * Added optional download progress bar. 28 | * Added --debug option for connection debugging. 29 | * Added short section on HTTP proxy use to castget(1). 30 | * Updated links in documentation. 31 | 32 | 2011-05-15 Marius L. Jøhndal 33 | 34 | * Copyright update and whitespace removal. 35 | 36 | 2010-02-20 Marius L. Jøhndal 37 | 38 | * configure.ac: Bumped version number to 1.1.0. 39 | 40 | 2007-11-14 Marius L. Jøhndal 41 | 42 | * castget.1.in, castgetrc.5.in, src/castget.c, src/channel.c, 43 | src/channel.h, src/configuration.c, src/configuration.h: Added 44 | support for per-channel enclosure regex filters. 45 | 46 | * src/castget.c: Made rcfile non-global. Synchronised help message 47 | with man page. 48 | 49 | * README: Added details about dependencies. 50 | 51 | * configure.ac: Switched to bzip2 for dist files. 52 | 53 | * castget.1.in, configure.ac, src/castget.c, src/channel.c, 54 | src/channel.h: Added support for restricting operations to 55 | enclosures matching a regex given on the command line. 56 | 57 | 2007-11-14 Marius L. Jøhndal 58 | 59 | * configure.ac: Bumped version number to 1.0.1. 60 | 61 | 2007-11-13 Marius L. Jøhndal 62 | 63 | * libcastget/utils.c: Improved handling of out of disk space 64 | errors. Removed superfluous close(). 65 | 66 | 2007-10-18 Marius L. Jøhndal 67 | 68 | * libcastget/urlget.c: Added custom User-Agent header. 69 | 70 | * castget/castget.c: Updated banner copyright. 71 | 72 | 2007-10-12 Marius Larsen Jøhndal 73 | 74 | * castget.1.in: Documented --rcfile option. 75 | 76 | 2007-10-12 Jick Nan 77 | 78 | * src/castget.c: Add --rcfile option. 79 | 80 | 2007-09-20 Marius L. Jøhndal 81 | 82 | * configure.ac: Bumped version number to 1.0.0. 83 | 84 | * castgetrc.5.in: Minor language clean-up. 85 | 86 | 2007-09-20 Marius Larsen Jøhndal 87 | 88 | * src/Makefile.am, src/castget.c, src/channel.c, src/channel.h, 89 | src/libcastget.h, src/rss.h, src/urlget.c, src/urlget.h, 90 | src/utils.c, src/utils.h: Eliminated libcastget.h. 91 | 92 | * configure.ac, src/Makefile.am, src/castget.c, 93 | src/configuration.c, src/htmlent.h, src/rss.c, src/urlget.h, 94 | src/channel.c, src/configuration.h, src/libxmlutil.c, src/rss.h, 95 | src/utils.c, src/channel.h, src/htmlent.c, src/libxmlutil.h, 96 | src/urlget.c, src/utils.h: Moved all source files into a single 97 | subdirectory src/ in order to remove libcastget. 98 | 99 | 2007-02-15 Marius L. Jøhndal 100 | 101 | * configure.ac: Bumped version number to 0.9.6. 102 | 103 | * castget.1.in, castget/castget.c, libcastget/channel.c, 104 | libcastget/channel.h, libcastget/libcastget.h, 105 | libcastget/urlget.c, libcastget/urlget.h: Added --resume option 106 | (Jick Nan). 107 | 108 | 2007-01-24 Marius L. Jøhndal 109 | 110 | * castget/castget.c: Added --new-only option (Jick Nan). 111 | 112 | * castget.1.in, castgetrc.5.in: Documented --new option. Clarified 113 | behaviour of channel files when configurations are removed from 114 | configuration files. 115 | 116 | * libcastget/rss.c, libcastget/rss.c: Added the field fetched_time 117 | to the RSS file structure. 118 | 119 | * castget/castget.c, libcastget/libcastget.c, 120 | libcastget/libcastget.h: Refactored libcastget_channel_update, 121 | libcastget_channel_catchup and libcastget_channel_list. Added 122 | first_only flag. 123 | 124 | * castget/castget.c, castget.1.in: Added --first-only option. 125 | 126 | 2006-11-09 Marius L. Jøhndal 127 | 128 | * castget.1.in: Clarified intended behaviour of the --list option. 129 | 130 | 2006-09-03 Marius L. Jøhndal 131 | 132 | * configure.ac: Tried to correct problems with the id3lib checking 133 | failing to link. 134 | 135 | 2006-07-28 Marius L. Jøhndal 136 | 137 | * castget/castget.c: Fixed a problem with the "quiet" option 138 | interfering with the writing of ID3 tags (!) 139 | 140 | * castget/castget.c, libcastget/rss.c, libcastget/utils.c: 141 | Removed some warnings. 142 | 143 | 2006-07-22 Marius L. Jøhndal 144 | 145 | * castget.c: Changed printing of file sizes to use kB, MB, and GB 146 | also when listing available downloads. 147 | 148 | 2006-07-08 Marius L. Jøhndal 149 | 150 | * configure.ac: Bumped version number to 0.9.5. 151 | 152 | * castgetrc.5.in, Makefile.am, configure.ac: Added new man page on 153 | the configuration file. 154 | 155 | * castget.1.in: Clarifyed the default behaviour of castget when 156 | invoked without arguments. Added reference to castgetrc(5). 157 | 158 | * castget/castget.c: Added verification of keys in configuration 159 | file. 160 | 161 | 2006-06-21 Marius L. Jøhndal 162 | 163 | * libcastget/utils.c: Rewrote temporary file handling to avoid 164 | renaming files across devices. 165 | 166 | 2006-06-10 Marius L. Jøhndal 167 | 168 | * configure.ac: Bumped version number to 0.9.4. 169 | 170 | * libcastget/channel.c: Added missing escaping of URLs written to 171 | channel file. 172 | 173 | * castget/castget.c: Removed silly verbosity check from channel 174 | listing function. 175 | 176 | * castget/castget.c: Fixed bad handling of errors generated by 177 | g_key_file_load_from_file when loading configuration files. 178 | 179 | 2006-06-09 Marius L. Jøhndal 180 | 181 | * libcastget/Makefile.am, libcastget/htmlent.c, 182 | libcastget/htmlent.h, libcastget/rss.c: Added work-around for HTML 183 | entitites in RSS files. 184 | 185 | 2006-05-25 Marius L. Jøhndal 186 | 187 | * castget.c: Removed misplaced libcastget_channel_free() in 188 | channel parsing function. 189 | 190 | 2006-05-06 Marius L. Jøhndal 191 | 192 | * castget.c: Removed printing of enclosure length when length is 193 | zero. Fixed broken enclosure MIME type check when no MIME type 194 | appears in RSS feed. 195 | 196 | 2006-03-30 Marius L. Jøhndal 197 | 198 | * rss.c, libcastget.h, channel.c, castget.c: Moved enclosure 199 | filename into enclosure structure and changed progress output to 200 | filename instead of URL. 201 | 202 | 2006-03-21 Marius L. Jøhndal 203 | 204 | * configure.ac: Bumped version number to 0.9.3. 205 | 206 | * libcastget.h, rss.c, libxmlutil.c, libxmlutil.h: Added support 207 | for the MRSS content tag. MRSS information will be preferred over 208 | attributes on an enclosure tag. 209 | 210 | * castget.c: Changed printing of file sizes to use kB, MB, and GB 211 | when suitable. Some formatting adjustments to progress printout. 212 | 213 | 2005-12-08 Marius L. Jøhndal 214 | 215 | * configure.ac: Bumped version number to 0.9.2. 216 | 217 | * libcastget/rss.c, libcastget/utils.c: Fixed invalid cross device 218 | link errors caused by uninitialized pointer in temporary file 219 | function. 220 | 221 | 2005-12-07 Marius L. Jøhndal 222 | 223 | * castget/castget.c: Added a missing test to exclude the global 224 | group "*" from channel iteration. 225 | 226 | 2005-12-01 Marius L. Jøhndal 227 | 228 | * castget/castget.c: Fixed broken handling of missing configuration 229 | file. 230 | 231 | 2005-12-01 Marius L. Jøhndal 232 | 233 | * libcastget/Makefile.am: Removed superfluous (and broken) include 234 | path. 235 | 236 | 2005-11-19 Marius L. Jøhndal 237 | 238 | * configure.ac: Bumped version number to 0.9.1. 239 | 240 | 2005-11-19 Marius L. Jøhndal 241 | 242 | * Makefile.am, castget.1.in, configure.ac: Added man 243 | page for castget program. 244 | 245 | 2005-11-19 Marius L. Jøhndal 246 | 247 | * castgetrc.example, castget/castgetrc.example, Makefile.am, 248 | castget/Makefile.am: Moved example configuration file to top-level 249 | directory. 250 | 251 | 2005-11-19 Marius L. Jøhndal 252 | 253 | * castget/Makefile.am, castget/castget.c, 254 | castget/castgetrc.example, castget/configuration.c, 255 | castget/configuration.h: Added a global section to the 256 | configuration file. 257 | 258 | 2005-11-14 Marius L. Jøhndal 259 | 260 | * castget/castget.c: Expanded usage information. 261 | 262 | 2005-11-14 Marius L. Jøhndal 263 | 264 | * configure.ac: Bumped version number for initial release. 265 | 266 | 2005-11-14 Marius L. Jøhndal 267 | 268 | * libcastget/channel.c, libcastget/channel.h, libcastget/utils.c, 269 | libcastget/utils.h: Added timestamping of channel updates and 270 | enclosure downloads. 271 | 272 | 2005-11-13 Marius L. Jøhndal 273 | 274 | * libcastget/channel.c, libcastget/rss.c, libcastget/urlget.c, 275 | libcastget/urlget.h, libcastget/utils.c, libcastget/utils.h: 276 | Switched to downloading RSS file to temporary file in order to 277 | avoid recurrent libxml2 parse errors. 278 | 279 | 2005-11-13 Marius L. Jøhndal 280 | 281 | * castget/castget.c: Added user-defined per-channel ID3 tags. 282 | 283 | 2005-10-24 Marius L. Jøhndal 284 | 285 | * libcastget/Makefile.am, libcastget/channel.c, libcastget/utils.c, 286 | libcastget/utils.h: Modified channel file saving function to use 287 | temporary files. Added proper XML prologue and a version number to 288 | channel files. 289 | 290 | 2005-08-28 Marius L. Jøhndal 291 | 292 | * castget/castget.c: Check return value of libcastget_channel_new 293 | and report error. Moved libxml2 to main block for now. 294 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | ************************* 3 | 4 | Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005 Free 5 | Software Foundation, Inc. 6 | 7 | This file is free documentation; the Free Software Foundation gives 8 | unlimited permission to copy, distribute and modify it. 9 | 10 | Basic Installation 11 | ================== 12 | 13 | These are generic installation instructions. 14 | 15 | The `configure' shell script attempts to guess correct values for 16 | various system-dependent variables used during compilation. It uses 17 | those values to create a `Makefile' in each directory of the package. 18 | It may also create one or more `.h' files containing system-dependent 19 | definitions. Finally, it creates a shell script `config.status' that 20 | you can run in the future to recreate the current configuration, and a 21 | file `config.log' containing compiler output (useful mainly for 22 | debugging `configure'). 23 | 24 | It can also use an optional file (typically called `config.cache' 25 | and enabled with `--cache-file=config.cache' or simply `-C') that saves 26 | the results of its tests to speed up reconfiguring. (Caching is 27 | disabled by default to prevent problems with accidental use of stale 28 | cache files.) 29 | 30 | If you need to do unusual things to compile the package, please try 31 | to figure out how `configure' could check whether to do them, and mail 32 | diffs or instructions to the address given in the `README' so they can 33 | be considered for the next release. If you are using the cache, and at 34 | some point `config.cache' contains results you don't want to keep, you 35 | may remove or edit it. 36 | 37 | The file `configure.ac' (or `configure.in') is used to create 38 | `configure' by a program called `autoconf'. You only need 39 | `configure.ac' if you want to change it or regenerate `configure' using 40 | a newer version of `autoconf'. 41 | 42 | The simplest way to compile this package is: 43 | 44 | 1. `cd' to the directory containing the package's source code and type 45 | `./configure' to configure the package for your system. If you're 46 | using `csh' on an old version of System V, you might need to type 47 | `sh ./configure' instead to prevent `csh' from trying to execute 48 | `configure' itself. 49 | 50 | Running `configure' takes awhile. While running, it prints some 51 | messages telling which features it is checking for. 52 | 53 | 2. Type `make' to compile the package. 54 | 55 | 3. Optionally, type `make check' to run any self-tests that come with 56 | the package. 57 | 58 | 4. Type `make install' to install the programs and any data files and 59 | documentation. 60 | 61 | 5. You can remove the program binaries and object files from the 62 | source code directory by typing `make clean'. To also remove the 63 | files that `configure' created (so you can compile the package for 64 | a different kind of computer), type `make distclean'. There is 65 | also a `make maintainer-clean' target, but that is intended mainly 66 | for the package's developers. If you use it, you may have to get 67 | all sorts of other programs in order to regenerate files that came 68 | with the distribution. 69 | 70 | Compilers and Options 71 | ===================== 72 | 73 | Some systems require unusual options for compilation or linking that the 74 | `configure' script does not know about. Run `./configure --help' for 75 | details on some of the pertinent environment variables. 76 | 77 | You can give `configure' initial values for configuration parameters 78 | by setting variables in the command line or in the environment. Here 79 | is an example: 80 | 81 | ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix 82 | 83 | *Note Defining Variables::, for more details. 84 | 85 | Compiling For Multiple Architectures 86 | ==================================== 87 | 88 | You can compile the package for more than one kind of computer at the 89 | same time, by placing the object files for each architecture in their 90 | own directory. To do this, you must use a version of `make' that 91 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 92 | directory where you want the object files and executables to go and run 93 | the `configure' script. `configure' automatically checks for the 94 | source code in the directory that `configure' is in and in `..'. 95 | 96 | If you have to use a `make' that does not support the `VPATH' 97 | variable, you have to compile the package for one architecture at a 98 | time in the source code directory. After you have installed the 99 | package for one architecture, use `make distclean' before reconfiguring 100 | for another architecture. 101 | 102 | Installation Names 103 | ================== 104 | 105 | By default, `make install' will install the package's files in 106 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 107 | installation prefix other than `/usr/local' by giving `configure' the 108 | option `--prefix=PREFIX'. 109 | 110 | You can specify separate installation prefixes for 111 | architecture-specific files and architecture-independent files. If you 112 | give `configure' the option `--exec-prefix=PREFIX', the package will 113 | use PREFIX as the prefix for installing programs and libraries. 114 | Documentation and other data files will still use the regular prefix. 115 | 116 | In addition, if you use an unusual directory layout you can give 117 | options like `--bindir=DIR' to specify different values for particular 118 | kinds of files. Run `configure --help' for a list of the directories 119 | you can set and what kinds of files go in them. 120 | 121 | If the package supports it, you can cause programs to be installed 122 | with an extra prefix or suffix on their names by giving `configure' the 123 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 124 | 125 | Optional Features 126 | ================= 127 | 128 | Some packages pay attention to `--enable-FEATURE' options to 129 | `configure', where FEATURE indicates an optional part of the package. 130 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 131 | is something like `gnu-as' or `x' (for the X Window System). The 132 | `README' should mention any `--enable-' and `--with-' options that the 133 | package recognizes. 134 | 135 | For packages that use the X Window System, `configure' can usually 136 | find the X include and library files automatically, but if it doesn't, 137 | you can use the `configure' options `--x-includes=DIR' and 138 | `--x-libraries=DIR' to specify their locations. 139 | 140 | Specifying the System Type 141 | ========================== 142 | 143 | There may be some features `configure' cannot figure out automatically, 144 | but needs to determine by the type of machine the package will run on. 145 | Usually, assuming the package is built to be run on the _same_ 146 | architectures, `configure' can figure that out, but if it prints a 147 | message saying it cannot guess the machine type, give it the 148 | `--build=TYPE' option. TYPE can either be a short name for the system 149 | type, such as `sun4', or a canonical name which has the form: 150 | 151 | CPU-COMPANY-SYSTEM 152 | 153 | where SYSTEM can have one of these forms: 154 | 155 | OS KERNEL-OS 156 | 157 | See the file `config.sub' for the possible values of each field. If 158 | `config.sub' isn't included in this package, then this package doesn't 159 | need to know the machine type. 160 | 161 | If you are _building_ compiler tools for cross-compiling, you should 162 | use the `--target=TYPE' option to select the type of system they will 163 | produce code for. 164 | 165 | If you want to _use_ a cross compiler, that generates code for a 166 | platform different from the build platform, you should specify the 167 | "host" platform (i.e., that on which the generated programs will 168 | eventually be run) with `--host=TYPE'. 169 | 170 | Sharing Defaults 171 | ================ 172 | 173 | If you want to set default values for `configure' scripts to share, you 174 | can create a site shell script called `config.site' that gives default 175 | values for variables like `CC', `cache_file', and `prefix'. 176 | `configure' looks for `PREFIX/share/config.site' if it exists, then 177 | `PREFIX/etc/config.site' if it exists. Or, you can set the 178 | `CONFIG_SITE' environment variable to the location of the site script. 179 | A warning: not all `configure' scripts look for a site script. 180 | 181 | Defining Variables 182 | ================== 183 | 184 | Variables not defined in a site shell script can be set in the 185 | environment passed to `configure'. However, some packages may run 186 | configure again during the build, and the customized values of these 187 | variables may be lost. In order to avoid this problem, you should set 188 | them in the `configure' command line, using `VAR=value'. For example: 189 | 190 | ./configure CC=/usr/local2/bin/gcc 191 | 192 | causes the specified `gcc' to be used as the C compiler (unless it is 193 | overridden in the site shell script). Here is a another example: 194 | 195 | /bin/bash ./configure CONFIG_SHELL=/bin/bash 196 | 197 | Here the `CONFIG_SHELL=/bin/bash' operand causes subsequent 198 | configuration-related scripts to be executed by `/bin/bash'. 199 | 200 | `configure' Invocation 201 | ====================== 202 | 203 | `configure' recognizes the following options to control how it operates. 204 | 205 | `--help' 206 | `-h' 207 | Print a summary of the options to `configure', and exit. 208 | 209 | `--version' 210 | `-V' 211 | Print the version of Autoconf used to generate the `configure' 212 | script, and exit. 213 | 214 | `--cache-file=FILE' 215 | Enable the cache: use and save the results of the tests in FILE, 216 | traditionally `config.cache'. FILE defaults to `/dev/null' to 217 | disable caching. 218 | 219 | `--config-cache' 220 | `-C' 221 | Alias for `--cache-file=config.cache'. 222 | 223 | `--quiet' 224 | `--silent' 225 | `-q' 226 | Do not print messages saying which checks are being made. To 227 | suppress all normal output, redirect it to `/dev/null' (any error 228 | messages will still be shown). 229 | 230 | `--srcdir=DIR' 231 | Look for the package's source code in directory DIR. Usually 232 | `configure' can determine that directory automatically. 233 | 234 | `configure' also accepts some other, not widely useful, options. Run 235 | `configure --help' for more details. 236 | 237 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2005-2018 Marius L. Jøhndal 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | ACLOCAL_AMFLAGS = -I m4 19 | 20 | SUBDIRS = tests src 21 | 22 | EXTRA_DIST = \ 23 | castgetrc.example \ 24 | castget.1 \ 25 | castgetrc.5 \ 26 | CHANGES.md \ 27 | ChangeLog.old 28 | 29 | man_MANS = \ 30 | castget.1 \ 31 | castgetrc.5 32 | 33 | AUTOMAKE_OPTIONS = foreign 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # castget 2 | 3 | castget is a simple, command-line based RSS enclosure downloader. It is 4 | primarily intended for automatic, unattended downloading of podcasts. 5 | 6 | ## Packages 7 | 8 | Many distributions have packages for castget: 9 | 10 | [![Packaging status](https://repology.org/badge/vertical-allrepos/castget.svg?header=castget)](https://repology.org/project/castget/versions) 11 | 12 | ## Building 13 | 14 | castget depends on 15 | 16 | * glib2 >= 2.30 17 | * libcurl >= 7.21.6 18 | * taglib (optional) 19 | 20 | If building on macOS, you can use Homebrew to install the dependencies: 21 | 22 | ```shell 23 | brew install glib taglib 24 | ``` 25 | 26 | On Ubuntu Xenial, you need the following: 27 | 28 | * libcurl4-gnutls-dev 29 | * libtagc0-dev (optional) 30 | 31 | On Alpine, you need the following: 32 | 33 | * libxml2-dev 34 | * glib-dev 35 | * curl-dev 36 | * taglib-dev (optional) 37 | 38 | On Debian 9 “stretch”, you need the following: 39 | 40 | * pkg-config 41 | * libglib2.0-dev 42 | * libxml2-dev 43 | * libcurl3-dev 44 | * libtagc0-dev (optional) 45 | 46 | ### Building from source 47 | 48 | To build from a distribution tarball, do the following: 49 | 50 | ```shell 51 | ./configure 52 | make 53 | make install 54 | ``` 55 | 56 | To disable taglib support, pass `--without-taglib` to `configure`; 57 | 58 | ```shell 59 | ./configure --without-taglib 60 | ``` 61 | 62 | ### Building from git 63 | 64 | To build from git, clone the master branch 65 | 66 | ```shell 67 | git clone https://github.com/mlj/castget.git 68 | ``` 69 | 70 | then rebuild the autoconf scripts 71 | 72 | ```shell 73 | autoreconf -fi 74 | ./configure 75 | make 76 | make install 77 | ``` 78 | 79 | ### Building from Dockerfile 80 | 81 | A Dockerfile is available in contrib folder. 82 | 83 | Build docker image. 84 | 85 | ``` 86 | docker build -t castget -f contrib/Dockerfile . 87 | ``` 88 | 89 | Create a file `.castgetrc` as shown on [Usage](Usage) and run container. 90 | 91 | ``` 92 | docker run -v $(pwd):/castget --rm -it castget 93 | ``` 94 | 95 | ## Usage 96 | 97 | For usage instructions see the 98 | [castget(1)](http://mlj.github.io/castget/castget.1.html) and 99 | [castget(5)](http://mlj.github.io/castget/castgetrc.5.html) man pages. 100 | 101 | You will find a sample configuration file castgetrc.example in the top level 102 | directory of the distribution. You should copy this file to your home directory 103 | as `.castgetrc` and edit it to suit your preferences. 104 | 105 | ## Bug reports 106 | 107 | Please use the [github bug tracker](https://github.com/mlj/castget/issues) to 108 | report bugs. 109 | 110 | ## License 111 | 112 | castget is maintained by Marius L. Jøhndal and is available under the LGPL license. 113 | -------------------------------------------------------------------------------- /castget.1: -------------------------------------------------------------------------------- 1 | .TH "CASTGET" "1" "January 2025" "castget 2.0.1" "User Commands" 2 | . 3 | .SH "NAME" 4 | \fBcastget\fR \- download RSS enclosures 5 | . 6 | .SH "SYNOPSIS" 7 | \fBcastget\fR [\fIOPTION\fR\.\.\.] [\fICHANNEL IDENTIFIER\fR\.\.\.] 8 | . 9 | .SH "DESCRIPTION" 10 | \fBcastget\fR downloads RSS enclosures, for example podcasts, from RSS feeds\. 11 | . 12 | .P 13 | RSS feeds are assigned \fIchannel identifier\fRs in the configuration file \fB\.castgetrc\fR\. Channels to be processed by \fBcastget\fR are indicated by supplying the channel identifiers as arguments\. If no channel identifiers are provided, all available channels are processed\. 14 | . 15 | .P 16 | If run without any options, \fBcastget\fR will perform the default action on all channels to be processed\. The default action is to download any enclosure not already downloaded\. Other actions may be performed by supplying one or more options as arguments\. 17 | . 18 | .SH "OPTIONS" 19 | . 20 | .SS "Operations" 21 | . 22 | .TP 23 | \fB\-c\fR, \fB\-\-catchup\fR 24 | Catch up with channels and exit\. 25 | . 26 | .TP 27 | \fB\-l\fR, \fB\-\-list\fR 28 | List available enclosures that have not yet been downloaded, and exit\. 29 | . 30 | .TP 31 | \fB\-h\fR, \fB\-\-help\fR 32 | Display help and exit\. 33 | . 34 | .TP 35 | \fB\-V\fR, \fB\-\-version\fR 36 | Output version information and exit\. 37 | . 38 | .SS "Operation filters" 39 | . 40 | .TP 41 | \fB\-n\fR, \fB\-\-new\-only\fR 42 | Restrict operation to new channels only, i\.e\. to channels that have never been downloaded from or been caught up with before\. Note that if a channel is added to the configuration and subsequently removed, its download history is preserved\. This means that a channel that has been removed from the configuration file will not be considered as \'new\' if it is added to the configuration again at a later time\. 43 | . 44 | .TP 45 | \fB\-1\fR, \fB\-\-first\-only\fR 46 | Restrict operation to the most recent item in each channel only\. 47 | . 48 | .TP 49 | \fB\-f\fR \fIpattern\fR, \fB\-\-filter\fR=\fIpattern\fR 50 | Restrict operation to enclosures whose download URLs match the regular expression \fBpattern\fR\. Note that this will override any regular expression filters given in the configuration file\. 51 | . 52 | .SS "Global options" 53 | . 54 | .TP 55 | \fB\-r\fR, \fB\-\-resume\fR 56 | Resume aborted downloads\. Make sure not to use this option if the RSS feed uses the same filename for multiple enclosures as this will corrupt existing downloads\. 57 | . 58 | .TP 59 | \fB\-q\fR, \fB\-\-quiet\fR 60 | Do not print anything except error messages\. 61 | . 62 | .TP 63 | \fB\-v\fR, \fB\-\-verbose\fR 64 | Print detailed progress information\. 65 | . 66 | .TP 67 | \fB\-d\fR, \fB\-\-debug\fR 68 | Print (lots of) connection debug information\. 69 | . 70 | .TP 71 | \fB\-p\fR, \fB\-\-progress\-bar\fR 72 | Print a progress bar when downloading enclosures\. 73 | . 74 | .TP 75 | \fB\-C\fR \fIfilename\fR, \fB\-\-rcfile\fR=\fIfilename\fR 76 | Override the default filename for the configuration file\. 77 | . 78 | .SH "EXAMPLES" 79 | . 80 | .TP 81 | Download all enclosures not already downloaded: 82 | . 83 | .IP 84 | $ castget 85 | . 86 | .TP 87 | Download all enclosures not already downloaded from channel \fBfoobar\fR and be verbose: 88 | . 89 | .IP 90 | $ castget \-v foobar 91 | . 92 | .TP 93 | List all enclosures not already downloaded: 94 | . 95 | .IP 96 | $ castget \-l 97 | . 98 | .TP 99 | Catch up with channel \fBfoobar\fR: 100 | . 101 | .IP 102 | $ castget \-c foobar 103 | . 104 | .TP 105 | List the first available enclosure in all new channels: 106 | . 107 | .IP 108 | $ castget \-1 \-n \-l 109 | . 110 | .TP 111 | Catch up with items that match the regular expression \fBFreddies0[67]\fR in the channel \fBfrederator\fR: 112 | . 113 | .IP 114 | $ castget \-c \-f "Freddies0[67]" frederator 115 | . 116 | .SH "HTTP PROXY" 117 | . 118 | .TP 119 | To use a HTTP proxy, set the environment variable \fBhttp_proxy\fR: 120 | . 121 | .IP 122 | http_proxy=http://your\.proxy\.server:port/ castget 123 | . 124 | .SH "SEE ALSO" 125 | castgetrc(5) 126 | . 127 | .SH "BUGS" 128 | Please see the castget home page \fIhttp://mlj\.github\.io/castget\fR for instructions on how to submit bug reports\. 129 | . 130 | .SH "AUTHORS" 131 | Marius L\. Jøhndal, Jick Nan\. 132 | . 133 | .SH "COPYRIGHT" 134 | Castget is Copyright (C) 2005\-2021 Marius L\. Jøhndal\. 135 | . 136 | .P 137 | Castget is Copyright (C) 2007 Jick Nan\. 138 | . 139 | .P 140 | This is free software; see the source for copying conditions\. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\. 141 | -------------------------------------------------------------------------------- /castgetrc.5: -------------------------------------------------------------------------------- 1 | .TH "CASTGETRC" "5" "January 2025" "castget 2.0.1" "User Commands" 2 | . 3 | .SH "NAME" 4 | \fBcastgetrc\fR \- configuration file for castget 5 | . 6 | .SH "DESCRIPTION" 7 | The configuration file \fB\.castgetrc\fR should be located in a user\'s home directory\. It defines the behaviour of the RSS enclosure downloader \fBcastget\fR, and in particular the list of channels it operates on\. 8 | . 9 | .P 10 | The file is based on a simple key\-value format\. It consists of a channel definition for each RSS feed \fBcastget\fR should process\. A channel definition starts with a line containing a channel identifier enclosed in brackets\. The channel identifier can be freely chosen by the user and is used for all subsequent operations on the channel\. Following this are one or more key\-value pairs on the form \fBkey=value\fR that define \fBcastget\fR\'s behaviour when operating on the channel\. A channel definition ends when another channel definition is started or at the end of the file\. 11 | . 12 | .P 13 | Lines beginning with a hash character (`#\') and blank lines are considered comments\. All identifiers, keys and values should be UTF\-8 encoded\. 14 | . 15 | .P 16 | Key\-value pairs in a channel definition define the behaviour of \fBcastget\fR when processing the channel\. The channel definition 17 | . 18 | .IP "" 4 19 | . 20 | .nf 21 | 22 | [fooc] 23 | url=http://downloads\.bbc\.co\.uk/podcasts/radio4/fooc/rss\.xml 24 | spool=/home/joe/podcasts 25 | . 26 | .fi 27 | . 28 | .IP "" 0 29 | . 30 | .P 31 | for example, instructs \fBcastget\fR to use \fB/home/joe/podcasts\fR as a download directory when processing the channel \fBfooc\fR\. 32 | . 33 | .P 34 | Directory names and filenames with spaces do not need to be quoted or escaped\. 35 | . 36 | .SH "KEYS" 37 | . 38 | .TP 39 | \fBurl\fR 40 | Retrieve RSS feed from this URL\. The field is mandatory for all channel definitions\. 41 | . 42 | .TP 43 | \fBspool\fR 44 | Download enclosures to this directory\. 45 | . 46 | .TP 47 | \fBplaylist\fR 48 | Write the fully qualified file names of all downloaded enclosures to an m3u style playlist file with this name\. 49 | . 50 | .TP 51 | \fBfilter\fR 52 | Restrict operation to enclosures whose URLs match this regular expression\. 53 | . 54 | .TP 55 | \fBtitle_tag\fR 56 | Add or set the title tag in the media file (e\.g\. `title\' (TIT2) in ID3v2)\. 57 | . 58 | .TP 59 | \fBalbum_tag\fR 60 | Add or set the album tag in the media file (e\.g\. `album\' (TALB) in ID3v2)\. 61 | . 62 | .TP 63 | \fBgenre_tag\fR 64 | Add or set the genre tag in the media file (e\.g\. `content type\' (TCON) in ID3v2)\. 65 | . 66 | .TP 67 | \fByear_tag\fR 68 | Add or set the year tag in the media file (e\.g\. `year\' (TYER) in ID3v2)\. 69 | . 70 | .TP 71 | \fBcomment_tag\fR 72 | Add or set the comment tag in the media file (e\.g\. `comment\' (COMM) in ID3v2)\. 73 | . 74 | .TP 75 | \fBfilename\fR 76 | Save downloads using the given filename pattern instead of deriving it from the URL of the enclosure\. See FILENAME PATTERNS\. 77 | . 78 | .SH "GLOBAL CONFIGURATION" 79 | A channel definition with the channel identifier \fB*\fR will define a global configuration affecting all channels\. The global configuration 80 | . 81 | .IP "" 4 82 | . 83 | .nf 84 | 85 | [*] 86 | genre_tag=Podcast 87 | . 88 | .fi 89 | . 90 | .IP "" 0 91 | . 92 | .P 93 | for example, is equivalent to adding the key\-value pair \fBgenre_tag=Podcast\fR to all other channel definitions\. 94 | . 95 | .P 96 | Key\-value pairs in channel definitions override the global configuration\. 97 | . 98 | .SH "FILENAME PATTERNS" 99 | Filename patterns can contain patterns on the form \fB%(parameter)\fR, which are expanded to form a complete filename\. Patterns are expanded once for each enclosure download and can therefore be used to generate filenames that are unique to each download\. 100 | . 101 | .P 102 | Anything that is not a pattern is as a literal that will be reproduced verbatim (subject to some sanity checking)\. The complete pathname of a download is determined by concatenating the channel\'s spool directory with the filename\. 103 | . 104 | .P 105 | Note that \fBcastget\fR will refuse to overwrite files that already exist except when it is invoked with the \fB\-r\fR option to resume downloads\. Some RSS feeds reuse the same filename for all enclosures\. In such cases the \fB\-r\fR option will corrupt existing downloads unless you use filename patterns to construct unique filenames\. 106 | . 107 | .P 108 | The following patterns take information from the \fBitem\fR element or the enclosure in the RSS feed: 109 | . 110 | .IP "\(bu" 4 111 | \fB%(date)\fR: date (by default on the format YYYY\-MM\-DD) 112 | . 113 | .IP "\(bu" 4 114 | \fB%(title)\fR: title 115 | . 116 | .IP "" 0 117 | . 118 | .P 119 | The following take information from the \fBchannel\fR element or the enclosure in the RSS feed: 120 | . 121 | .IP "\(bu" 4 122 | \fB%(channel_title)\fR: channel title 123 | . 124 | .IP "" 0 125 | . 126 | .P 127 | If any of the information required by a pattern is missing from the RSS feed or is invalid the pattern will be ignored and removed from the resulting filename\. 128 | . 129 | .SH "CHANNEL REMOVAL" 130 | If a channel configuration is removed, the channel status remains the same so that if the channel is subsequently re\-added, any enclosures marked as already downloaded will not be downloaded again\. 131 | . 132 | .SH "NOTE" 133 | The source distribution includes a sample configuration file demonstrating all supported settings\. 134 | . 135 | .SH "SEE ALSO" 136 | castget(1) 137 | . 138 | .SH "AUTHOR" 139 | Marius L\. Jøhndal\. 140 | -------------------------------------------------------------------------------- /castgetrc.example: -------------------------------------------------------------------------------- 1 | # 2 | # Example castgetrc file. 3 | # 4 | 5 | # 6 | # Global settings. 7 | # 8 | 9 | # This sets the default genre tag to "Podcast" and the default 10 | # download directory to /home/tom/podcasts. These settings can be 11 | # overriden per channel. 12 | [*] 13 | genre=Podcast 14 | spool=/home/tom/podcasts 15 | 16 | # 17 | # Per-channel settings. 18 | # 19 | 20 | # This defines a channel "dsc", sets the feed URL and overrides the 21 | # download directory. 22 | [dsc] 23 | url=http://radio.weblogs.com/0001014/categories/dailySourceCode/rss.xml 24 | spool=/home/tom/podcasts/dsc 25 | 26 | # Spaces in values (including filenames) do not require quotation marks 27 | # or escaping. 28 | [hollywoodbabbleon] 29 | url=http://feeds.feedburner.com/HollywoodBabbleOnPod 30 | spool=/Users/joe/My Podcasts 31 | 32 | # Use keys like "album_tag" to set tags in media files. 33 | [newsquizextra] 34 | url=http://podcasts.files.bbci.co.uk/b010m2mj.rss 35 | album_tag=BBC News Quiz Extra 36 | 37 | # Setting a tag to an empty string will clear the tag. Tags that are 38 | # not set to any specific value in the channel configuration will 39 | # be left the way they are. 40 | [freakonomics] 41 | url=http://feeds.feedburner.com/freakonomicsradio 42 | comment_tag= 43 | 44 | # castget will by default use the filnames that appear in the RSS feed. 45 | # This does not work if, for example, the RSS feed uses the same filename 46 | # for all files. You can use "filename" to specify a filename pattern 47 | # for saving files. See See castgetrc(5) for a list of supported patterns. 48 | # Be careful which patterns you use --- including the raw title from the 49 | # RSS feed, for example, may not be a good idea. 50 | [alphachat] 51 | url=http://podcast.ft.com/s/ft-alphachat/feed 52 | album_tag=FT Alphachat 53 | filespec=alphachat-$(date)-%(title).mp3 54 | 55 | # Media files can be added to a playlist when downloaded. 56 | [scientific_american] 57 | url=http://rss.sciam.com/sciam/science-talk 58 | album_tag=Scientific American 59 | filename=%(date)-%(title).mp3 60 | playlist=/home/tom/sciam.m3u 61 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | # 4 | # Copyright (C) 2005-2021 Marius L. Jøhndal 5 | # 6 | # This library is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Lesser General Public 8 | # License as published by the Free Software Foundation; either 9 | # version 2.1 of the License, or (at your option) any later version. 10 | # 11 | # This library is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this library; if not, write to the Free Software 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | # 20 | AC_PREREQ(2.59) 21 | AC_INIT(castget, 2.0.1, mariuslj@ifi.uio.no) 22 | AM_INIT_AUTOMAKE([1.8 dist-bzip2 no-dist-gzip foreign]) 23 | AC_CONFIG_SRCDIR([src/castget.c]) 24 | AC_CONFIG_HEADER([config.h]) 25 | AC_CONFIG_MACRO_DIRS([m4]) 26 | 27 | # Checks for programs. 28 | AC_PROG_CC 29 | AC_PROG_INSTALL 30 | AC_PROG_LIBTOOL 31 | 32 | # Checks for libraries. 33 | PKG_CHECK_MODULES(GLIBS, [ 34 | glib-2.0 >= 2.30 35 | libxml-2.0 36 | ]) 37 | 38 | AC_PATH_PROG(CURL_CONFIG, curl-config, no) 39 | if test "$CURL_CONFIG" = "no" ; then 40 | AC_MSG_ERROR(Required library libcurl not found) 41 | else 42 | CURL_CFLAGS=`$CURL_CONFIG --cflags` 43 | CURL_LIBS=`$CURL_CONFIG --libs` 44 | 45 | AC_SUBST(CURL_CFLAGS) 46 | AC_SUBST(CURL_LIBS) 47 | fi 48 | 49 | #AC_ARG_WITH(taglib, [ --without-taglib disable taglib support]) 50 | AC_ARG_WITH(taglib, AC_HELP_STRING([--without-taglib], [disable taglib support])]) 51 | if test "x$with_taglib" != "xno"; then 52 | PKG_CHECK_MODULES(TAGLIB, [taglib_c]) 53 | AC_SUBST(TAGLIB_CFLAGS) 54 | AC_SUBST(TAGLIB_LIBS) 55 | AC_DEFINE(HAVE_TAGLIB, [1], [Define to 1 if you have taglib support]) 56 | fi 57 | 58 | # Checks for header files. 59 | AC_HEADER_STDC 60 | AC_CHECK_HEADERS([stdlib.h string.h]) 61 | 62 | # Checks for typedefs, structures, and compiler characteristics. 63 | AC_C_CONST 64 | 65 | # Checks for library functions. 66 | AC_FUNC_MALLOC 67 | AC_CHECK_FUNCS([strdup strtol]) 68 | 69 | AC_CONFIG_FILES([ 70 | Makefile 71 | src/Makefile 72 | tests/Makefile 73 | ]) 74 | AC_OUTPUT 75 | -------------------------------------------------------------------------------- /contrib/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.14 2 | 3 | VOLUME /castget 4 | 5 | COPY . ./build 6 | 7 | RUN apk add --no-cache --virtual build-dependencies \ 8 | libxml2-dev glib-dev curl-dev taglib-dev alpine-sdk autoconf automake libtool \ 9 | && apk add --no-cache libxml2 glib curl taglib \ 10 | && cd build \ 11 | && autoreconf -fi \ 12 | && ./configure \ 13 | && make \ 14 | && make install \ 15 | && cd ../ \ 16 | && rm -rf build \ 17 | && apk del build-dependencies \ 18 | && adduser -h /castget -D -H castget 19 | 20 | USER castget 21 | 22 | ENTRYPOINT ["castget"] 23 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2005-2021 Marius L. Jøhndal 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Lesser General Public 6 | # License as published by the Free Software Foundation; either 7 | # version 2.1 of the License, or (at your option) any later version. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Lesser General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with this library; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | AM_CPPFLAGS = $(GLIBS_CFLAGS) $(CURL_CFLAGS) 19 | 20 | bin_PROGRAMS = castget 21 | 22 | castget_SOURCES = \ 23 | castget.c \ 24 | channel.c \ 25 | channel.h \ 26 | configuration.h \ 27 | configuration.c \ 28 | date_parsing.c \ 29 | date_parsing.h \ 30 | filenames.c \ 31 | filenames.h \ 32 | htmlent.c \ 33 | htmlent.h \ 34 | libxmlutil.c \ 35 | libxmlutil.h \ 36 | patterns.c \ 37 | patterns.h \ 38 | progress.c \ 39 | progress.h \ 40 | rss.c \ 41 | rss.h \ 42 | urlget.c \ 43 | urlget.h \ 44 | utils.c \ 45 | utils.h 46 | 47 | castget_LDADD = \ 48 | $(CURL_LIBS) \ 49 | $(GLIBS_LIBS) \ 50 | $(TAGLIB_LIBS) 51 | -------------------------------------------------------------------------------- /src/castget.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2021 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif /* HAVE_CONFIG_H */ 23 | 24 | #include "channel.h" 25 | #include "configuration.h" 26 | 27 | #define _GNU_SOURCE 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #ifdef HAVE_TAGLIB 36 | #include 37 | #endif /* HAVE_TAGLIB */ 38 | 39 | enum op { OP_UPDATE, OP_CATCHUP, OP_LIST }; 40 | 41 | static int _process_channel(const gchar *channel_directory, GKeyFile *kf, 42 | const char *identifier, enum op op, 43 | struct channel_configuration *defaults, 44 | enclosure_filter *filter); 45 | static void version(void); 46 | static GKeyFile *_configuration_file_open(const gchar *rcfile); 47 | static void _configuration_file_close(GKeyFile *kf); 48 | #ifdef HAVE_TAGLIB 49 | static void _set_tags(const gchar *filename, 50 | const struct channel_configuration *cfg); 51 | #endif /* HAVE_TAGLIB */ 52 | static int playlist_add(const gchar *playlist_file, const gchar *media_file); 53 | 54 | static gboolean verbose = FALSE; 55 | static gboolean quiet = FALSE; 56 | static gboolean first_only = FALSE; 57 | static gboolean resume = FALSE; 58 | static gboolean debug = FALSE; 59 | static gboolean show_progress_bar = FALSE; 60 | static gboolean show_version = FALSE; 61 | static gboolean new_only = FALSE; 62 | static gboolean list = FALSE; 63 | static gboolean catchup = FALSE; 64 | static gchar *rcfile = NULL; 65 | static gchar *filter_regex = NULL; 66 | 67 | int main(int argc, char **argv) 68 | { 69 | enum op op = OP_UPDATE; 70 | int i; 71 | int ret = 0; 72 | gchar **groups; 73 | gchar *channeldir; 74 | GKeyFile *kf; 75 | struct channel_configuration *defaults; 76 | enclosure_filter *filter = NULL; 77 | GError *error = NULL; 78 | GOptionContext *context; 79 | 80 | static GOptionEntry options[] = { 81 | { "catchup", 'c', 0, G_OPTION_ARG_NONE, &catchup, 82 | "catch up with channels and exit" }, 83 | { "list", 'l', 0, G_OPTION_ARG_NONE, &list, 84 | "list available enclosures that have not yet been downloaded and exit" }, 85 | { "version", 'V', 0, G_OPTION_ARG_NONE, &show_version, 86 | "print version and exit" }, 87 | 88 | { "resume", 'r', 0, G_OPTION_ARG_NONE, &resume, 89 | "resume aborted downloads" }, 90 | { "rcfile", 'C', 0, G_OPTION_ARG_FILENAME, &rcfile, 91 | "override the default configuration file name" }, 92 | 93 | { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, 94 | "print connection debug information" }, 95 | { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, 96 | "print detailed progress information" }, 97 | { "progress-bar", 'p', 0, G_OPTION_ARG_NONE, &show_progress_bar, 98 | "print progress bar" }, 99 | 100 | { "new-only", 'n', 0, G_OPTION_ARG_NONE, &new_only, 101 | "only process new channels" }, 102 | { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "only print error messages" }, 103 | { "first-only", '1', 0, G_OPTION_ARG_NONE, &first_only, 104 | "only process the most recent item from each channel" }, 105 | { "filter", 'f', 0, G_OPTION_ARG_STRING, &filter_regex, 106 | "only process items whose enclosure names match a regular expression" }, 107 | 108 | { NULL } 109 | }; 110 | 111 | context = g_option_context_new("CHANNELS"); 112 | g_option_context_add_main_entries(context, options, NULL); 113 | 114 | if (!g_option_context_parse(context, &argc, &argv, &error)) { 115 | g_print("option parsing failed: %s\n", error->message); 116 | exit(1); 117 | } 118 | 119 | /* Do some additional sanity checking of options. */ 120 | if ((verbose && quiet) || (show_progress_bar && quiet)) { 121 | g_print("option parsing failed: options are incompatible.\n"); 122 | exit(1); 123 | } 124 | 125 | if ((catchup && list) || (catchup && show_version) || 126 | (list && show_version)) { 127 | g_print( 128 | "option parsing failed: --catchup, --list and --version options are " 129 | "incompatible.\n"); 130 | exit(1); 131 | } 132 | 133 | /* Decide on the action to take */ 134 | if (show_version) { 135 | version(); 136 | exit(0); 137 | } 138 | 139 | if (catchup) 140 | op = OP_CATCHUP; 141 | 142 | if (list) 143 | op = OP_LIST; 144 | 145 | if (filter_regex) { 146 | filter = enclosure_filter_new(filter_regex, FALSE); 147 | g_free(filter_regex); 148 | } 149 | 150 | if (verbose && new_only) 151 | g_print("Fetching new channels only...\n"); 152 | 153 | LIBXML_TEST_VERSION; 154 | 155 | /* Build the channel directory path and ensure that it exists. */ 156 | channeldir = g_build_filename(g_get_home_dir(), ".castget", NULL); 157 | 158 | if (!g_file_test(channeldir, G_FILE_TEST_IS_DIR)) { 159 | if (g_mkdir(channeldir, 0755) < 0) { 160 | perror("Error creating channel directory"); 161 | return 1; 162 | } 163 | } 164 | 165 | /* Try opening configuration file. */ 166 | if (!rcfile) 167 | /* Supply default path name. */ 168 | rcfile = g_build_filename(g_get_home_dir(), ".castgetrc", NULL); 169 | 170 | kf = _configuration_file_open(rcfile); 171 | 172 | if (kf) { 173 | /* Read defaults. */ 174 | if (g_key_file_has_group(kf, "*")) { 175 | /* Verify the keys in the global configuration. */ 176 | if (channel_configuration_verify_keys(kf, "*") < 0) 177 | return -1; 178 | 179 | defaults = channel_configuration_new(kf, "*", NULL); 180 | } else 181 | defaults = NULL; 182 | 183 | /* Perform actions. */ 184 | if (optind < argc) { 185 | while (optind < argc) 186 | _process_channel(channeldir, kf, argv[optind++], op, defaults, filter); 187 | } else { 188 | groups = g_key_file_get_groups(kf, NULL); 189 | 190 | for (i = 0; groups[i]; i++) 191 | if (strcmp(groups[i], "*")) 192 | _process_channel(channeldir, kf, groups[i], op, defaults, filter); 193 | 194 | g_strfreev(groups); 195 | } 196 | 197 | /* Clean up defaults. */ 198 | if (defaults) 199 | channel_configuration_free(defaults); 200 | } else 201 | ret = 1; 202 | 203 | /* Clean-up. */ 204 | g_free(channeldir); 205 | 206 | if (filter) 207 | enclosure_filter_free(filter); 208 | 209 | g_free(rcfile); 210 | 211 | if (kf) 212 | _configuration_file_close(kf); 213 | 214 | xmlCleanupParser(); 215 | 216 | return ret; 217 | } 218 | 219 | static void version(void) 220 | { 221 | g_printf("%s %s", PACKAGE, VERSION); 222 | #ifdef HAVE_TAGLIB 223 | g_printf(" with taglib support\n"); 224 | #else 225 | g_printf("\n"); 226 | #endif 227 | 228 | g_printf("Copyright (C) 2005-2021 Marius L. Jøhndal\n"); 229 | } 230 | 231 | static void _print_item_update(const enclosure *enclosure, 232 | const gchar *filename) 233 | { 234 | if (enclosure->length > 0) { 235 | gchar *size = g_format_size(enclosure->length); 236 | g_printf(" * %s (%s)\n", enclosure->url, size); 237 | g_free(size); 238 | } else 239 | g_printf(" * %s (unknown size)\n", filename); 240 | } 241 | 242 | static void update_callback(void *user_data, channel_action action, 243 | channel_info *channel_info, enclosure *enclosure, 244 | const gchar *filename) 245 | { 246 | struct channel_configuration *c = (struct channel_configuration *)user_data; 247 | 248 | switch (action) { 249 | case CCA_RSS_DOWNLOAD_START: 250 | if (!quiet) 251 | g_printf("Updating channel %s...\n", c->identifier); 252 | break; 253 | 254 | case CCA_RSS_DOWNLOAD_END: 255 | break; 256 | 257 | case CCA_ENCLOSURE_DOWNLOAD_START: 258 | g_assert(channel_info); 259 | g_assert(enclosure); 260 | 261 | if (verbose) 262 | _print_item_update(enclosure, filename); 263 | 264 | break; 265 | 266 | case CCA_ENCLOSURE_DOWNLOAD_END: 267 | g_assert(channel_info); 268 | g_assert(enclosure); 269 | g_assert(filename); 270 | 271 | #ifdef HAVE_TAGLIB 272 | _set_tags(filename, c); 273 | #endif /* HAVE_TAGLIB */ 274 | 275 | /* Update playlist. */ 276 | if (c->playlist) { 277 | playlist_add(c->playlist, filename); 278 | 279 | if (verbose) 280 | printf(" * Added downloaded enclosure %s to playlist %s.\n", filename, 281 | c->playlist); 282 | } 283 | break; 284 | } 285 | } 286 | 287 | static void catchup_callback(void *user_data, channel_action action, 288 | channel_info *channel_info, enclosure *enclosure, 289 | const gchar *filename) 290 | { 291 | struct channel_configuration *c = (struct channel_configuration *)user_data; 292 | 293 | switch (action) { 294 | case CCA_RSS_DOWNLOAD_START: 295 | if (!quiet) 296 | g_printf("Catching up with channel %s...\n", c->identifier); 297 | break; 298 | 299 | case CCA_RSS_DOWNLOAD_END: 300 | break; 301 | 302 | case CCA_ENCLOSURE_DOWNLOAD_START: 303 | g_assert(channel_info); 304 | g_assert(enclosure); 305 | 306 | if (verbose) 307 | _print_item_update(enclosure, filename); 308 | 309 | break; 310 | 311 | case CCA_ENCLOSURE_DOWNLOAD_END: 312 | break; 313 | } 314 | } 315 | 316 | static void list_callback(void *user_data, channel_action action, 317 | channel_info *channel_info, enclosure *enclosure, 318 | const gchar *filename) 319 | { 320 | struct channel_configuration *c = (struct channel_configuration *)user_data; 321 | 322 | switch (action) { 323 | case CCA_RSS_DOWNLOAD_START: 324 | g_printf("Listing channel %s...\n", c->identifier); 325 | break; 326 | 327 | case CCA_RSS_DOWNLOAD_END: 328 | break; 329 | 330 | case CCA_ENCLOSURE_DOWNLOAD_START: 331 | g_assert(channel_info); 332 | g_assert(enclosure); 333 | 334 | if (verbose) 335 | _print_item_update(enclosure, filename); 336 | 337 | break; 338 | 339 | case CCA_ENCLOSURE_DOWNLOAD_END: 340 | break; 341 | } 342 | } 343 | 344 | static int _process_channel(const gchar *channel_directory, GKeyFile *kf, 345 | const char *identifier, enum op op, 346 | struct channel_configuration *defaults, 347 | enclosure_filter *filter) 348 | { 349 | channel *c; 350 | gchar *channel_filename, *channel_file; 351 | struct channel_configuration *channel_configuration; 352 | enclosure_filter *per_channel_filter = NULL; 353 | 354 | /* Check channel identifier and read channel configuration. */ 355 | if (!g_key_file_has_group(kf, identifier)) { 356 | fprintf(stderr, "Unknown channel identifier %s.\n", identifier); 357 | 358 | return -1; 359 | } 360 | 361 | /* Verify the keys in the channel configuration. */ 362 | if (channel_configuration_verify_keys(kf, identifier) < 0) 363 | return -1; 364 | 365 | channel_configuration = channel_configuration_new(kf, identifier, defaults); 366 | 367 | /* Check that mandatory keys were set. */ 368 | if (!channel_configuration->url) { 369 | fprintf(stderr, "No feed URL set for channel %s.\n", identifier); 370 | 371 | channel_configuration_free(channel_configuration); 372 | return -1; 373 | } 374 | 375 | if (!channel_configuration->spool_directory) { 376 | fprintf(stderr, "No spool directory set for channel %s.\n", identifier); 377 | 378 | channel_configuration_free(channel_configuration); 379 | return -1; 380 | } 381 | 382 | /* Construct channel file name. */ 383 | channel_filename = g_strjoin(".", identifier, "xml", NULL); 384 | channel_file = g_build_filename(channel_directory, channel_filename, NULL); 385 | g_free(channel_filename); 386 | 387 | if (new_only && access(channel_file, F_OK) == 0) { 388 | /* If we are only fetching new channels, skip the channel if there is 389 | already a channel file present. */ 390 | 391 | channel_configuration_free(channel_configuration); 392 | return 0; 393 | } 394 | 395 | c = channel_new(channel_configuration->url, channel_file, 396 | channel_configuration->spool_directory, 397 | channel_configuration->filename_pattern, resume); 398 | g_free(channel_file); 399 | 400 | if (!c) { 401 | fprintf(stderr, "Error parsing channel file for channel %s.\n", identifier); 402 | 403 | channel_configuration_free(channel_configuration); 404 | return -1; 405 | } 406 | 407 | /* Set up per-channel filter unless overridden on the command 408 | line. */ 409 | if (!filter && channel_configuration->regex_filter) { 410 | per_channel_filter = 411 | enclosure_filter_new(channel_configuration->regex_filter, FALSE); 412 | 413 | filter = per_channel_filter; 414 | } 415 | 416 | switch (op) { 417 | case OP_UPDATE: 418 | channel_update(c, channel_configuration, update_callback, 0, 0, first_only, 419 | resume, filter, debug, show_progress_bar); 420 | break; 421 | 422 | case OP_CATCHUP: 423 | channel_update(c, channel_configuration, catchup_callback, 1, 0, first_only, 424 | 0, filter, debug, show_progress_bar); 425 | break; 426 | 427 | case OP_LIST: 428 | channel_update(c, channel_configuration, list_callback, 1, 1, first_only, 0, 429 | filter, debug, show_progress_bar); 430 | break; 431 | } 432 | 433 | /* Clean-up. */ 434 | if (per_channel_filter) 435 | enclosure_filter_free(per_channel_filter); 436 | 437 | channel_free(c); 438 | channel_configuration_free(channel_configuration); 439 | 440 | return 0; 441 | } 442 | 443 | static GKeyFile *_configuration_file_open(const gchar *rcfile) 444 | { 445 | GKeyFile *kf; 446 | GError *error = NULL; 447 | 448 | kf = g_key_file_new(); 449 | 450 | if (!g_key_file_load_from_file(kf, rcfile, G_KEY_FILE_NONE, &error)) { 451 | fprintf(stderr, "Error reading configuration file %s: %s.\n", rcfile, 452 | error->message); 453 | g_error_free(error); 454 | g_key_file_free(kf); 455 | kf = NULL; 456 | } 457 | 458 | return kf; 459 | } 460 | 461 | static void _configuration_file_close(GKeyFile *kf) 462 | { 463 | g_key_file_free(kf); 464 | } 465 | 466 | #ifdef HAVE_TAGLIB 467 | static void _set_tags(const gchar *filename, 468 | const struct channel_configuration *cfg) 469 | { 470 | if (cfg->artist_tag || cfg->title_tag || cfg->album_tag || cfg->genre_tag || 471 | cfg->year_tag || cfg->comment_tag) { 472 | TagLib_File *file; 473 | TagLib_Tag *tag; 474 | 475 | file = taglib_file_new(filename); 476 | 477 | if (file == NULL) { 478 | fprintf(stderr, "Error setting tags for file %s.\n", filename); 479 | return; 480 | } 481 | 482 | tag = taglib_file_tag(file); 483 | 484 | if (cfg->artist_tag) { 485 | taglib_tag_set_artist(tag, cfg->artist_tag); 486 | 487 | if (verbose) 488 | printf(" * Set artist tag to %s.\n", cfg->artist_tag); 489 | } 490 | 491 | if (cfg->title_tag) { 492 | taglib_tag_set_title(tag, cfg->title_tag); 493 | 494 | if (verbose) 495 | printf(" * Set title tag to %s.\n", cfg->title_tag); 496 | } 497 | 498 | if (cfg->album_tag) { 499 | taglib_tag_set_album(tag, cfg->album_tag); 500 | 501 | if (verbose) 502 | printf(" * Set album tag to %s.\n", cfg->album_tag); 503 | } 504 | 505 | if (cfg->genre_tag) { 506 | taglib_tag_set_genre(tag, cfg->genre_tag); 507 | 508 | if (verbose) 509 | printf(" * Set genre tag to %s.\n", cfg->genre_tag); 510 | } 511 | 512 | if (cfg->year_tag) { 513 | taglib_tag_set_year(tag, g_ascii_strtoull(cfg->year_tag, NULL, 10)); 514 | 515 | if (verbose) 516 | printf(" * Set year tag to %s.\n", cfg->year_tag); 517 | } 518 | 519 | if (cfg->comment_tag) { 520 | taglib_tag_set_comment(tag, cfg->comment_tag); 521 | 522 | if (verbose) 523 | printf(" * Set comment tag to %s.\n", cfg->comment_tag); 524 | } 525 | 526 | if (!taglib_file_save(file)) 527 | fprintf(stderr, "Error setting tags for file %s.\n", filename); 528 | 529 | taglib_tag_free_strings(); 530 | taglib_file_free(file); 531 | } 532 | } 533 | #endif /* HAVE_TAGLIB */ 534 | 535 | static int playlist_add(const gchar *playlist_file, const gchar *media_file) 536 | { 537 | FILE *f; 538 | 539 | f = fopen(playlist_file, "a"); 540 | 541 | if (!f) { 542 | fprintf(stderr, "Error opening playlist file %s: %s.\n", playlist_file, 543 | strerror(errno)); 544 | return -1; 545 | } 546 | 547 | fprintf(f, "%s\n", media_file); 548 | fclose(f); 549 | return 0; 550 | } 551 | -------------------------------------------------------------------------------- /src/channel.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif /* HAVE_CONFIG_H */ 23 | 24 | #include "channel.h" 25 | #include "filenames.h" 26 | #include "libxmlutil.h" 27 | #include "progress.h" 28 | #include "rss.h" 29 | #include "urlget.h" 30 | #include "utils.h" 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | static int _enclosure_pattern_match(enclosure_filter *filter, 38 | const enclosure *enclosure); 39 | 40 | static void _enclosure_iterator(const void *user_data, int i, 41 | const xmlNode *node) 42 | { 43 | const char *downloadtime; 44 | 45 | channel *c = (channel *)user_data; 46 | 47 | downloadtime = libxmlutil_attr_as_string(node, "downloadtime"); 48 | 49 | if (downloadtime) 50 | downloadtime = g_strdup(downloadtime); 51 | else 52 | downloadtime = get_rfc822_time(); 53 | 54 | g_hash_table_insert(c->downloaded_enclosures, 55 | (gpointer)libxmlutil_attr_as_string(node, "url"), 56 | (gpointer)downloadtime); 57 | } 58 | 59 | channel *channel_new(const char *url, const char *channel_file, 60 | const char *spool_directory, const char *filename_pattern, 61 | int resume) 62 | { 63 | channel *c; 64 | xmlDocPtr doc; 65 | xmlNode *root_element = NULL; 66 | const char *s; 67 | 68 | c = (channel *)malloc(sizeof(struct _channel)); 69 | c->url = g_strdup(url); 70 | c->channel_filename = g_strdup(channel_file); 71 | c->spool_directory = g_strdup(spool_directory); 72 | c->filename_pattern = g_strdup(filename_pattern); 73 | // c->resume = resume; 74 | c->rss_last_fetched = NULL; 75 | c->downloaded_enclosures = 76 | g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); 77 | 78 | if (g_file_test(c->channel_filename, G_FILE_TEST_EXISTS)) { 79 | doc = xmlReadFile(c->channel_filename, NULL, 0); 80 | 81 | if (!doc) { 82 | g_fprintf(stderr, "Error parsing channel file %s.\n", 83 | c->channel_filename); 84 | return NULL; 85 | } 86 | 87 | root_element = xmlDocGetRootElement(doc); 88 | 89 | if (!root_element) { 90 | xmlFreeDoc(doc); 91 | 92 | g_fprintf(stderr, "Error parsing channel file %s.\n", 93 | c->channel_filename); 94 | return NULL; 95 | } 96 | 97 | /* Fetch channel attributes. */ 98 | s = libxmlutil_attr_as_string(root_element, "rsslastfetched"); 99 | 100 | if (s) 101 | c->rss_last_fetched = g_strdup(s); 102 | 103 | /* Iterate encolsure elements. */ 104 | libxmlutil_iterate_by_tag_name(root_element, "enclosure", c, 105 | _enclosure_iterator); 106 | 107 | xmlFreeDoc(doc); 108 | } 109 | 110 | return c; 111 | } 112 | 113 | static void _cast_channel_save_downloaded_enclosure(gpointer key, 114 | gpointer value, 115 | gpointer user_data) 116 | { 117 | FILE *f = (FILE *)user_data; 118 | gchar *escaped_key = g_markup_escape_text(key, -1); 119 | 120 | if (value) 121 | g_fprintf(f, " \n", escaped_key, 122 | (gchar *)value); 123 | else 124 | g_fprintf(f, " \n", escaped_key); 125 | 126 | g_free(escaped_key); 127 | } 128 | 129 | static int _cast_channel_save_channel(FILE *f, gpointer user_data, int debug) 130 | { 131 | channel *c = (channel *)user_data; 132 | 133 | g_fprintf(f, "\n"); 134 | 135 | if (c->rss_last_fetched) 136 | g_fprintf(f, "\n", 137 | c->rss_last_fetched); 138 | else 139 | g_fprintf(f, "\n"); 140 | 141 | g_hash_table_foreach(c->downloaded_enclosures, 142 | _cast_channel_save_downloaded_enclosure, f); 143 | 144 | g_fprintf(f, "\n"); 145 | 146 | return 0; 147 | } 148 | 149 | static void _cast_channel_save(channel *c, int debug) 150 | { 151 | write_by_temporary_file(c->channel_filename, _cast_channel_save_channel, c, 152 | NULL, debug); 153 | } 154 | 155 | void channel_free(channel *c) 156 | { 157 | g_hash_table_destroy(c->downloaded_enclosures); 158 | g_free(c->spool_directory); 159 | g_free(c->channel_filename); 160 | g_free(c->url); 161 | g_free(c->filename_pattern); 162 | free(c); 163 | } 164 | 165 | static size_t _enclosure_urlget_cb(void *buffer, size_t size, size_t nmemb, 166 | void *user_data) 167 | { 168 | FILE *f = (FILE *)user_data; 169 | 170 | return fwrite(buffer, size, nmemb, f); 171 | } 172 | 173 | static rss_file *_get_rss(channel *c, void *user_data, channel_callback cb, 174 | int debug) 175 | { 176 | rss_file *f; 177 | 178 | if (cb) 179 | cb(user_data, CCA_RSS_DOWNLOAD_START, NULL, NULL, NULL); 180 | 181 | if (!strncmp("http://", c->url, strlen("http://")) || 182 | !strncmp("https://", c->url, strlen("https://"))) 183 | f = rss_open_url(c->url, debug); 184 | else 185 | f = rss_open_file(c->url); 186 | 187 | if (cb) 188 | cb(user_data, CCA_RSS_DOWNLOAD_END, &(f->channel_info), NULL, NULL); 189 | 190 | return f; 191 | } 192 | 193 | static int _do_download(channel *c, channel_info *channel_info, rss_item *item, 194 | void *user_data, channel_callback cb, int resume, 195 | int debug, int show_progress_bar) 196 | { 197 | int download_failed; 198 | long resume_from = 0; 199 | gchar *enclosure_full_filename; 200 | FILE *enclosure_file; 201 | struct stat fileinfo; 202 | progress_bar *pb; 203 | 204 | /* Check that the spool directory exists. */ 205 | if (!g_file_test(c->spool_directory, G_FILE_TEST_IS_DIR)) { 206 | g_fprintf(stderr, "Spool directory %s not found.\n", c->spool_directory); 207 | return 1; 208 | } 209 | 210 | /* Build enclosure filename. */ 211 | enclosure_full_filename = build_enclosure_filename( 212 | c->spool_directory, c->filename_pattern, channel_info, item); 213 | 214 | if (g_file_test(enclosure_full_filename, G_FILE_TEST_EXISTS)) { 215 | /* A file with the same filename already exists. If the user has asked us 216 | to resume downloads, we should append to the file. Otherwise we should 217 | refuse to continue. If the feed uses the same filename for each 218 | enclosure, running in append mode will corrupt existing files. There is 219 | probably no practical way to avoid this, and the issue is documented in 220 | castget(1) and castgetrc(5). */ 221 | if (resume) { 222 | /* Set resume offset to the size of the file as it is now (and use 223 | non-append mode if the size is zero or stat() fails). */ 224 | if (0 == stat(enclosure_full_filename, &fileinfo)) 225 | resume_from = fileinfo.st_size; 226 | else 227 | resume_from = 0; 228 | } else { 229 | /* File exists but user does not allow us to append so we have to 230 | abort. */ 231 | g_fprintf(stderr, "Enclosure file %s already exists.\n", 232 | enclosure_full_filename); 233 | g_free(enclosure_full_filename); 234 | return 1; 235 | } 236 | } else 237 | /* By letting the offset be 0 we will write in non-append mode. */ 238 | resume_from = 0; 239 | 240 | enclosure_file = fopen(enclosure_full_filename, resume_from ? "ab" : "wb"); 241 | 242 | if (!enclosure_file) { 243 | g_fprintf(stderr, "Error opening enclosure file %s.\n", 244 | enclosure_full_filename); 245 | g_free(enclosure_full_filename); 246 | return 1; 247 | } 248 | 249 | if (cb) 250 | cb(user_data, CCA_ENCLOSURE_DOWNLOAD_START, channel_info, item->enclosure, 251 | enclosure_full_filename); 252 | 253 | if (show_progress_bar) 254 | pb = progress_bar_new(resume_from); 255 | else 256 | pb = NULL; 257 | 258 | if (urlget_buffer(item->enclosure->url, enclosure_file, _enclosure_urlget_cb, 259 | resume_from, debug, pb)) { 260 | g_fprintf(stderr, "Error downloading enclosure from %s.\n", 261 | item->enclosure->url); 262 | 263 | download_failed = 1; 264 | } else 265 | download_failed = 0; 266 | 267 | if (pb) 268 | progress_bar_free(pb); 269 | 270 | fclose(enclosure_file); 271 | 272 | if (cb) 273 | cb(user_data, CCA_ENCLOSURE_DOWNLOAD_END, channel_info, item->enclosure, 274 | enclosure_full_filename); 275 | 276 | g_free(enclosure_full_filename); 277 | 278 | return download_failed; 279 | } 280 | 281 | static int _do_catchup(channel *c, channel_info *channel_info, rss_item *item, 282 | void *user_data, channel_callback cb) 283 | { 284 | if (cb) { 285 | cb(user_data, CCA_ENCLOSURE_DOWNLOAD_START, channel_info, item->enclosure, 286 | NULL); 287 | 288 | cb(user_data, CCA_ENCLOSURE_DOWNLOAD_END, channel_info, item->enclosure, 289 | NULL); 290 | } 291 | 292 | return 0; 293 | } 294 | 295 | int channel_update(channel *c, void *user_data, channel_callback cb, 296 | int no_download, int no_mark_read, int first_only, 297 | int resume, enclosure_filter *filter, int debug, 298 | int show_progress_bar) 299 | { 300 | int i, download_failed; 301 | rss_file *f; 302 | 303 | /* Retrieve the RSS file. */ 304 | f = _get_rss(c, user_data, cb, debug); 305 | 306 | if (!f) 307 | return 1; 308 | 309 | /* Check enclosures in RSS file. */ 310 | for (i = 0; i < f->num_items; i++) 311 | if (f->items[i]->enclosure) { 312 | if (!g_hash_table_lookup_extended(c->downloaded_enclosures, 313 | f->items[i]->enclosure->url, NULL, 314 | NULL)) { 315 | rss_item *item; 316 | 317 | item = f->items[i]; 318 | 319 | if (!filter || _enclosure_pattern_match(filter, item->enclosure)) { 320 | if (no_download) 321 | download_failed = 322 | _do_catchup(c, &(f->channel_info), item, user_data, cb); 323 | else 324 | download_failed = 325 | _do_download(c, &(f->channel_info), item, user_data, cb, resume, 326 | debug, show_progress_bar); 327 | 328 | if (download_failed) 329 | break; 330 | 331 | if (!no_mark_read) { 332 | /* Mark enclosure as downloaded and immediately save channel 333 | file to ensure that it reflects the change. */ 334 | g_hash_table_insert(c->downloaded_enclosures, 335 | f->items[i]->enclosure->url, 336 | (gpointer)get_rfc822_time()); 337 | 338 | _cast_channel_save(c, debug); 339 | } 340 | 341 | /* If we have been instructed to deal only with the first 342 | available enclosure, it is time to break out of the loop. */ 343 | if (first_only) 344 | break; 345 | } 346 | } 347 | } 348 | 349 | if (!no_mark_read) { 350 | /* Update the RSS last fetched time and save the channel file again. */ 351 | 352 | if (c->rss_last_fetched) 353 | g_free(c->rss_last_fetched); 354 | 355 | c->rss_last_fetched = g_strdup(f->fetched_time); 356 | 357 | _cast_channel_save(c, debug); 358 | } 359 | 360 | rss_close(f); 361 | 362 | return 0; 363 | } 364 | 365 | /* Match the (file) name of an enclosure against a regexp. Letters 366 | in the pattern match both upper and lower case letters if 367 | 'caseless' is TRUE. Returns TRUE if the pattern matches, FALSE 368 | otherwise. */ 369 | static gboolean _enclosure_pattern_match(enclosure_filter *filter, 370 | const enclosure *enclosure) 371 | { 372 | GError *error = NULL; 373 | GRegexCompileFlags compile_options = 0; 374 | GRegexMatchFlags match_options = 0; 375 | GRegex *regex; 376 | gboolean match; 377 | 378 | g_assert(filter); 379 | g_assert(filter->pattern); 380 | g_assert(enclosure); 381 | 382 | if (filter->caseless) 383 | compile_options |= G_REGEX_CASELESS; 384 | 385 | regex = g_regex_new(filter->pattern, compile_options, match_options, &error); 386 | 387 | if (error) { 388 | fprintf(stderr, "Error compiling regular expression %s: %s\n", 389 | filter->pattern, error->message); 390 | g_error_free(error); 391 | return FALSE; 392 | } 393 | 394 | match = g_regex_match(regex, enclosure->url, match_options, NULL); 395 | 396 | g_regex_unref(regex); 397 | 398 | return match; 399 | } 400 | 401 | enclosure_filter *enclosure_filter_new(const gchar *pattern, gboolean caseless) 402 | { 403 | enclosure_filter *e = g_malloc(sizeof(struct _enclosure_filter)); 404 | 405 | g_assert(pattern); 406 | 407 | e->pattern = g_strdup(pattern); 408 | e->caseless = caseless; 409 | 410 | return e; 411 | } 412 | 413 | void enclosure_filter_free(enclosure_filter *e) 414 | { 415 | g_free(e->pattern); 416 | g_free(e); 417 | } 418 | -------------------------------------------------------------------------------- /src/channel.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef CHANNEL_H 21 | #define CHANNEL_H 22 | 23 | #include 24 | 25 | typedef enum { 26 | CCA_RSS_DOWNLOAD_START, 27 | CCA_RSS_DOWNLOAD_END, 28 | CCA_ENCLOSURE_DOWNLOAD_START, 29 | CCA_ENCLOSURE_DOWNLOAD_END 30 | } channel_action; 31 | 32 | typedef struct _channel { 33 | gchar *url; 34 | gchar *channel_filename; 35 | gchar *spool_directory; 36 | gchar *filename_pattern; 37 | GHashTable *downloaded_enclosures; 38 | gchar *rss_last_fetched; 39 | } channel; 40 | 41 | typedef struct _channel_info { 42 | char *title; 43 | char *link; 44 | char *description; 45 | char *language; 46 | } channel_info; 47 | 48 | typedef struct _enclosure { 49 | char *url; 50 | long length; 51 | char *type; 52 | } enclosure; 53 | 54 | typedef struct _enclosure_filter { 55 | gchar *pattern; 56 | gboolean caseless; 57 | } enclosure_filter; 58 | 59 | typedef void (*channel_callback)(void *user_data, channel_action action, 60 | channel_info *channel_info, 61 | enclosure *enclosure, const char *filename); 62 | 63 | channel *channel_new(const char *url, const char *channel_file, 64 | const char *spool_directory, const char *filename_pattern, 65 | int resume); 66 | void channel_free(channel *c); 67 | int channel_update(channel *c, void *user_data, channel_callback cb, 68 | int no_download, int no_mark_read, int first_only, 69 | int resume, enclosure_filter *filter, int debug, 70 | int progress_bar); 71 | 72 | enclosure_filter *enclosure_filter_new(const gchar *pattern, gboolean caseless); 73 | void enclosure_filter_free(enclosure_filter *e); 74 | 75 | #endif /* CHANNEL_H */ 76 | -------------------------------------------------------------------------------- /src/configuration.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2021 Marius L. Jøhndal 3 | Copyright (C) 2010 Tony Armitstead 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif /* HAVE_CONFIG_H */ 24 | 25 | #include "configuration.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | static gchar *_read_channel_configuration_key(GKeyFile *kf, 32 | const gchar *identifier, 33 | const gchar *key) 34 | { 35 | GError *error = NULL; 36 | 37 | if (g_key_file_has_key(kf, identifier, key, &error)) 38 | return g_strdup(g_key_file_get_value(kf, identifier, key, &error)); 39 | 40 | return NULL; 41 | } 42 | 43 | void channel_configuration_free(struct channel_configuration *c) 44 | { 45 | g_free(c->identifier); 46 | 47 | if (c->url) 48 | g_free(c->url); 49 | 50 | if (c->spool_directory) 51 | g_free(c->spool_directory); 52 | 53 | if (c->filename_pattern) 54 | g_free(c->filename_pattern); 55 | 56 | if (c->playlist) 57 | g_free(c->playlist); 58 | 59 | if (c->artist_tag) 60 | g_free(c->artist_tag); 61 | 62 | if (c->title_tag) 63 | g_free(c->title_tag); 64 | 65 | if (c->album_tag) 66 | g_free(c->album_tag); 67 | 68 | if (c->genre_tag) 69 | g_free(c->genre_tag); 70 | 71 | if (c->year_tag) 72 | g_free(c->year_tag); 73 | 74 | if (c->comment_tag) 75 | g_free(c->comment_tag); 76 | 77 | if (c->regex_filter) 78 | g_free(c->regex_filter); 79 | 80 | g_free(c); 81 | } 82 | 83 | struct channel_configuration *channel_configuration_new( 84 | GKeyFile *kf, const gchar *identifier, 85 | struct channel_configuration *defaults) 86 | { 87 | struct channel_configuration *c; 88 | 89 | g_assert(g_key_file_has_group(kf, identifier)); 90 | 91 | /* Allocate new structure and save identifierr. */ 92 | c = (struct channel_configuration *)g_malloc( 93 | sizeof(struct channel_configuration)); 94 | 95 | c->identifier = g_strdup(identifier); 96 | 97 | /* Read keys from configuration file. */ 98 | c->url = _read_channel_configuration_key(kf, identifier, "url"); 99 | c->spool_directory = _read_channel_configuration_key(kf, identifier, "spool"); 100 | c->filename_pattern = 101 | _read_channel_configuration_key(kf, identifier, "filename"); 102 | c->playlist = _read_channel_configuration_key(kf, identifier, "playlist"); 103 | c->artist_tag = _read_channel_configuration_key(kf, identifier, "artist_tag"); 104 | c->title_tag = _read_channel_configuration_key(kf, identifier, "title_tag"); 105 | c->album_tag = _read_channel_configuration_key(kf, identifier, "album_tag"); 106 | c->genre_tag = _read_channel_configuration_key(kf, identifier, "genre_tag"); 107 | c->year_tag = _read_channel_configuration_key(kf, identifier, "year_tag"); 108 | c->comment_tag = 109 | _read_channel_configuration_key(kf, identifier, "comment_tag"); 110 | c->regex_filter = _read_channel_configuration_key(kf, identifier, "filter"); 111 | 112 | /* Populate with defaults if necessary. */ 113 | if (defaults) { 114 | if (!c->url && defaults->url) 115 | c->url = g_strdup(defaults->url); 116 | 117 | if (!c->spool_directory && defaults->spool_directory) 118 | c->spool_directory = g_strdup(defaults->spool_directory); 119 | 120 | if (!c->filename_pattern && defaults->filename_pattern) 121 | c->filename_pattern = g_strdup(defaults->filename_pattern); 122 | 123 | if (!c->playlist && defaults->playlist) 124 | c->playlist = g_strdup(defaults->playlist); 125 | 126 | if (!c->artist_tag && defaults->artist_tag) 127 | c->artist_tag = g_strdup(defaults->artist_tag); 128 | 129 | if (!c->title_tag && defaults->title_tag) 130 | c->title_tag = g_strdup(defaults->title_tag); 131 | 132 | if (!c->album_tag && defaults->album_tag) 133 | c->album_tag = g_strdup(defaults->album_tag); 134 | 135 | if (!c->genre_tag && defaults->genre_tag) 136 | c->genre_tag = g_strdup(defaults->genre_tag); 137 | 138 | if (!c->year_tag && defaults->year_tag) 139 | c->year_tag = g_strdup(defaults->year_tag); 140 | 141 | if (!c->comment_tag && defaults->comment_tag) 142 | c->comment_tag = g_strdup(defaults->comment_tag); 143 | 144 | if (!c->regex_filter && defaults->regex_filter) 145 | c->regex_filter = g_strdup(defaults->regex_filter); 146 | } 147 | 148 | return c; 149 | } 150 | 151 | int channel_configuration_verify_keys(GKeyFile *kf, const char *identifier) 152 | { 153 | int i; 154 | gchar **key_list; 155 | 156 | key_list = g_key_file_get_keys(kf, identifier, NULL, NULL); 157 | 158 | if (!key_list) { 159 | fprintf(stderr, "Error reading keys in configuration of channel %s.\n", 160 | identifier); 161 | 162 | return -1; 163 | } 164 | 165 | for (i = 0; key_list[i]; i++) { 166 | if (!strcmp(key_list[i], "id3contentgroup")) 167 | fprintf(stderr, "Key id3contentgroup no longer supported.\n"); 168 | else if (!strcmp(key_list[i], "id3leadartist")) 169 | fprintf(stderr, 170 | "Key id3leadartist no longer supported. Please use artist_tag " 171 | "instead.\n"); 172 | else if (!strcmp(key_list[i], "id3title")) 173 | fprintf( 174 | stderr, 175 | "Key id3title no longer supported. Please use title_tag instead.\n"); 176 | else if (!strcmp(key_list[i], "id3album")) 177 | fprintf( 178 | stderr, 179 | "Key id3album no longer supported. Please use album_tag instead.\n"); 180 | else if (!strcmp(key_list[i], "id3contenttype")) 181 | fprintf(stderr, 182 | "Key id3contenttype no longer supported. Please use genre_tag " 183 | "instead.\n"); 184 | else if (!strcmp(key_list[i], "id3year")) 185 | fprintf( 186 | stderr, 187 | "Key id3year no longer supported. Please use year_tag instead.\n"); 188 | else if (!strcmp(key_list[i], "id3comment")) 189 | fprintf(stderr, 190 | "Key id3comment no longer supported. Please use comment_tag " 191 | "instead.\n"); 192 | else if (!(!strcmp(key_list[i], "url") || !strcmp(key_list[i], "spool") || 193 | !strcmp(key_list[i], "filename") || 194 | !strcmp(key_list[i], "playlist") || 195 | !strcmp(key_list[i], "artist_tag") || 196 | !strcmp(key_list[i], "title_tag") || 197 | !strcmp(key_list[i], "album_tag") || 198 | !strcmp(key_list[i], "genre_tag") || 199 | !strcmp(key_list[i], "year_tag") || 200 | !strcmp(key_list[i], "comment_tag") || 201 | !strcmp(key_list[i], "filter"))) { 202 | fprintf(stderr, "Invalid key %s in configuration of channel %s.\n", 203 | key_list[i], identifier); 204 | return -1; 205 | } 206 | } 207 | 208 | g_strfreev(key_list); 209 | 210 | return 0; 211 | } 212 | -------------------------------------------------------------------------------- /src/configuration.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2021 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef CONFIGURATION_H 21 | #define CONFIGURATION_H 22 | 23 | #include 24 | 25 | struct channel_configuration { 26 | gchar *identifier; 27 | gchar *url; 28 | gchar *spool_directory; 29 | gchar *filename_pattern; 30 | gchar *playlist; 31 | gchar *artist_tag; 32 | gchar *title_tag; 33 | gchar *album_tag; 34 | gchar *genre_tag; 35 | gchar *year_tag; 36 | gchar *comment_tag; 37 | gchar *regex_filter; 38 | }; 39 | 40 | struct channel_configuration *channel_configuration_new( 41 | GKeyFile *kf, const gchar *identifier, 42 | struct channel_configuration *defaults); 43 | void channel_configuration_free(struct channel_configuration *c); 44 | int channel_configuration_verify_keys(GKeyFile *kf, const char *identifier); 45 | 46 | #endif /* CONFIGURATION_H */ 47 | -------------------------------------------------------------------------------- /src/date_parsing.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2010 Tony Armitstead 3 | Copyright (C) 2017-2020 Marius L. Jøhndal 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif /* HAVE_CONFIG_H */ 24 | 25 | #include "date_parsing.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | static const char *days[7] = { 32 | "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 33 | }; 34 | 35 | static const char *months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 36 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; 37 | 38 | GDate *parse_rfc822_date(const char *rfc822_date_str) 39 | { 40 | const char *dstr = rfc822_date_str; 41 | int i = 0; 42 | int day, month, year; 43 | char mstr[20]; 44 | 45 | while (isspace(*dstr)) 46 | dstr++; 47 | 48 | if (*dstr == '\0') 49 | return NULL; 50 | 51 | /* Skip past any valid day, field */ 52 | for (i = 0; i < sizeof(days) / sizeof(days[0]); i++) { 53 | if (strncmp(dstr, days[i], 3) == 0) 54 | break; 55 | } 56 | 57 | if (i < sizeof(days) / sizeof(days[0])) { 58 | dstr += 3; 59 | 60 | while (isspace(*dstr)) 61 | dstr++; 62 | 63 | if (*dstr == '\0') 64 | return NULL; 65 | 66 | if (*dstr == ',') 67 | dstr++; 68 | 69 | while (isspace(*dstr)) 70 | dstr++; 71 | 72 | if (*dstr == '\0') 73 | return NULL; 74 | } 75 | 76 | /* Decode day, month, year */ 77 | if (sscanf(dstr, "%d %s %d", &day, mstr, &year) != 3) 78 | return NULL; 79 | 80 | for (i = 0; i < sizeof(months) / sizeof(months[0]); i++) { 81 | if (strncmp(mstr, months[i], 3) == 0) 82 | break; 83 | } 84 | 85 | if (i == sizeof(months) / sizeof(months[0])) 86 | return NULL; 87 | 88 | month = i + 1; 89 | 90 | if (year < 1900) { 91 | if (year < 50) 92 | year += 2000; 93 | else 94 | year += 1900; 95 | } 96 | 97 | if (!g_date_valid_dmy(day, month, year)) 98 | return NULL; 99 | 100 | return g_date_new_dmy(day, month, year); 101 | } 102 | -------------------------------------------------------------------------------- /src/date_parsing.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2010 Tony Armitstead 3 | Copyright (C) 2017-2020 Marius L. Jøhndal 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | */ 20 | 21 | #ifndef DATE_PARSING_H 22 | #define DATE_PARSING_H 23 | 24 | #include 25 | 26 | GDate *parse_rfc822_date(const char *rfc822_date_str); 27 | 28 | #endif /* DATE_PARSING_H */ 29 | -------------------------------------------------------------------------------- /src/filenames.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2010 Tony Armistead 3 | Copyright (C) 2017-2020 Marius L. Jøhndal 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif /* HAVE_CONFIG_H */ 24 | 25 | #include "date_parsing.h" 26 | #include "filenames.h" 27 | #include "patterns.h" 28 | 29 | static gchar *guess_filename_from_url(const gchar *url); 30 | static gchar *sanitise_filename(const gchar *filename); 31 | 32 | /* Determine filename of enclosure. */ 33 | /* Chop off ? and # and anything following that from the basename. */ 34 | static gchar *guess_filename_from_url(const gchar *url) 35 | { 36 | gchar *basename = g_path_get_basename(url); 37 | gchar **tokens = g_strsplit_set(basename, "?#", 2); 38 | gchar *guess = g_strdup(tokens[0]); 39 | 40 | g_free(basename); 41 | g_strfreev(tokens); 42 | 43 | return guess; 44 | } 45 | 46 | /* Removes unsafe and undesirable characters from a filename. The caller 47 | must free the returned string with g_free(). */ 48 | static gchar *sanitise_filename(const gchar *filename) 49 | { 50 | static const gchar *bad_characters = "/\\?%*:|\"<>,'\n\t\r"; 51 | gchar **parts = g_strsplit_set(filename, bad_characters, -1); 52 | gchar *new_filename = g_strjoinv(NULL, parts); 53 | g_strfreev(parts); 54 | return new_filename; 55 | } 56 | 57 | gchar *build_enclosure_filename(const char *spool_directory, 58 | const char *filename_pattern, 59 | const channel_info *channel_info, 60 | const rss_item *item) 61 | { 62 | gchar *filename; 63 | gchar *sanitised_filename; 64 | gchar *pathname; 65 | 66 | if (filename_pattern) 67 | filename = 68 | expand_string_with_patterns(filename_pattern, channel_info, item); 69 | else 70 | filename = guess_filename_from_url(item->enclosure->url); 71 | 72 | sanitised_filename = sanitise_filename(filename); 73 | g_free(filename); 74 | 75 | pathname = g_build_filename(spool_directory, sanitised_filename, NULL); 76 | g_free(sanitised_filename); 77 | 78 | return pathname; 79 | } 80 | -------------------------------------------------------------------------------- /src/filenames.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2010 Tony Armitstead 3 | Copyright (C) 2017-2020 Marius L. Jøhndal 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | */ 20 | 21 | #ifndef FILENAME_PATTERN_H 22 | #define FILENAME_PATTERN_H 23 | 24 | #include "rss.h" 25 | 26 | gchar *build_enclosure_filename(const char *spool_directory, 27 | const char *filename_pattern, 28 | const channel_info *channel_info, 29 | const rss_item *item); 30 | 31 | #endif /* FILENAME_PATTERN_H */ 32 | -------------------------------------------------------------------------------- /src/htmlent.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2006-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif /* HAVE_CONFIG_H */ 23 | 24 | #include "htmlent.h" 25 | 26 | GHashTable *htmlent_hash_new(void) 27 | { 28 | GHashTable *h; 29 | 30 | h = g_hash_table_new(g_str_hash, g_str_equal); 31 | 32 | g_hash_table_insert(h, "nbsp", " "); 33 | g_hash_table_insert(h, "iexcl", "¡"); 34 | g_hash_table_insert(h, "cent", "¢"); 35 | g_hash_table_insert(h, "pound", "£"); 36 | g_hash_table_insert(h, "curren", "¤"); 37 | g_hash_table_insert(h, "yen", "¥"); 38 | g_hash_table_insert(h, "brvbar", "¦"); 39 | g_hash_table_insert(h, "sect", "§"); 40 | g_hash_table_insert(h, "uml", "¨"); 41 | g_hash_table_insert(h, "copy", "©"); 42 | g_hash_table_insert(h, "ordf", "ª"); 43 | g_hash_table_insert(h, "laquo", "«"); 44 | g_hash_table_insert(h, "not", "¬"); 45 | g_hash_table_insert(h, "shy", "­"); 46 | g_hash_table_insert(h, "reg", "®"); 47 | g_hash_table_insert(h, "macr", "¯"); 48 | g_hash_table_insert(h, "deg", "°"); 49 | g_hash_table_insert(h, "plusmn", "±"); 50 | g_hash_table_insert(h, "sup2", "²"); 51 | g_hash_table_insert(h, "sup3", "³"); 52 | g_hash_table_insert(h, "acute", "´"); 53 | g_hash_table_insert(h, "micro", "µ"); 54 | g_hash_table_insert(h, "para", "¶"); 55 | g_hash_table_insert(h, "middot", "·"); 56 | g_hash_table_insert(h, "cedil", "¸"); 57 | g_hash_table_insert(h, "sup1", "¹"); 58 | g_hash_table_insert(h, "ordm", "º"); 59 | g_hash_table_insert(h, "raquo", "»"); 60 | g_hash_table_insert(h, "frac14", "¼"); 61 | g_hash_table_insert(h, "frac12", "½"); 62 | g_hash_table_insert(h, "frac34", "¾"); 63 | g_hash_table_insert(h, "iquest", "¿"); 64 | g_hash_table_insert(h, "Agrave", "À"); 65 | g_hash_table_insert(h, "Aacute", "Á"); 66 | g_hash_table_insert(h, "Acirc", "Â"); 67 | g_hash_table_insert(h, "Atilde", "Ã"); 68 | g_hash_table_insert(h, "Auml", "Ä"); 69 | g_hash_table_insert(h, "Aring", "Å"); 70 | g_hash_table_insert(h, "AElig", "Æ"); 71 | g_hash_table_insert(h, "Ccedil", "Ç"); 72 | g_hash_table_insert(h, "Egrave", "È"); 73 | g_hash_table_insert(h, "Eacute", "É"); 74 | g_hash_table_insert(h, "Ecirc", "Ê"); 75 | g_hash_table_insert(h, "Euml", "Ë"); 76 | g_hash_table_insert(h, "Igrave", "Ì"); 77 | g_hash_table_insert(h, "Iacute", "Í"); 78 | g_hash_table_insert(h, "Icirc", "Î"); 79 | g_hash_table_insert(h, "Iuml", "Ï"); 80 | g_hash_table_insert(h, "ETH", "Ð"); 81 | g_hash_table_insert(h, "Ntilde", "Ñ"); 82 | g_hash_table_insert(h, "Ograve", "Ò"); 83 | g_hash_table_insert(h, "Oacute", "Ó"); 84 | g_hash_table_insert(h, "Ocirc", "Ô"); 85 | g_hash_table_insert(h, "Otilde", "Õ"); 86 | g_hash_table_insert(h, "Ouml", "Ö"); 87 | g_hash_table_insert(h, "times", "×"); 88 | g_hash_table_insert(h, "Oslash", "Ø"); 89 | g_hash_table_insert(h, "Ugrave", "Ù"); 90 | g_hash_table_insert(h, "Uacute", "Ú"); 91 | g_hash_table_insert(h, "Ucirc", "Û"); 92 | g_hash_table_insert(h, "Uuml", "Ü"); 93 | g_hash_table_insert(h, "Yacute", "Ý"); 94 | g_hash_table_insert(h, "THORN", "Þ"); 95 | g_hash_table_insert(h, "szlig", "ß"); 96 | g_hash_table_insert(h, "agrave", "à"); 97 | g_hash_table_insert(h, "aacute", "á"); 98 | g_hash_table_insert(h, "acirc", "â"); 99 | g_hash_table_insert(h, "atilde", "ã"); 100 | g_hash_table_insert(h, "auml", "ä"); 101 | g_hash_table_insert(h, "aring", "å"); 102 | g_hash_table_insert(h, "aelig", "æ"); 103 | g_hash_table_insert(h, "ccedil", "ç"); 104 | g_hash_table_insert(h, "egrave", "è"); 105 | g_hash_table_insert(h, "eacute", "é"); 106 | g_hash_table_insert(h, "ecirc", "ê"); 107 | g_hash_table_insert(h, "euml", "ë"); 108 | g_hash_table_insert(h, "igrave", "ì"); 109 | g_hash_table_insert(h, "iacute", "í"); 110 | g_hash_table_insert(h, "icirc", "î"); 111 | g_hash_table_insert(h, "iuml", "ï"); 112 | g_hash_table_insert(h, "eth", "ð"); 113 | g_hash_table_insert(h, "ntilde", "ñ"); 114 | g_hash_table_insert(h, "ograve", "ò"); 115 | g_hash_table_insert(h, "oacute", "ó"); 116 | g_hash_table_insert(h, "ocirc", "ô"); 117 | g_hash_table_insert(h, "otilde", "õ"); 118 | g_hash_table_insert(h, "ouml", "ö"); 119 | g_hash_table_insert(h, "divide", "÷"); 120 | g_hash_table_insert(h, "oslash", "ø"); 121 | g_hash_table_insert(h, "ugrave", "ù"); 122 | g_hash_table_insert(h, "uacute", "ú"); 123 | g_hash_table_insert(h, "ucirc", "û"); 124 | g_hash_table_insert(h, "uuml", "ü"); 125 | g_hash_table_insert(h, "yacute", "ý"); 126 | g_hash_table_insert(h, "thorn", "þ"); 127 | g_hash_table_insert(h, "yuml", "ÿ"); 128 | g_hash_table_insert(h, "quot", """); 129 | g_hash_table_insert(h, "amp", "&#38;"); 130 | g_hash_table_insert(h, "lt", "&#60;"); 131 | g_hash_table_insert(h, "gt", ">"); 132 | g_hash_table_insert(h, "apos ", "'"); 133 | g_hash_table_insert(h, "OElig", "Œ"); 134 | g_hash_table_insert(h, "oelig", "œ"); 135 | g_hash_table_insert(h, "Scaron", "Š"); 136 | g_hash_table_insert(h, "scaron", "š"); 137 | g_hash_table_insert(h, "Yuml", "Ÿ"); 138 | g_hash_table_insert(h, "circ", "ˆ"); 139 | g_hash_table_insert(h, "tilde", "˜"); 140 | g_hash_table_insert(h, "ensp", " "); 141 | g_hash_table_insert(h, "emsp", " "); 142 | g_hash_table_insert(h, "thinsp", " "); 143 | g_hash_table_insert(h, "zwnj", "‌"); 144 | g_hash_table_insert(h, "zwj", "‍"); 145 | g_hash_table_insert(h, "lrm", "‎"); 146 | g_hash_table_insert(h, "rlm", "‏"); 147 | g_hash_table_insert(h, "ndash", "–"); 148 | g_hash_table_insert(h, "mdash", "—"); 149 | g_hash_table_insert(h, "lsquo", "‘"); 150 | g_hash_table_insert(h, "rsquo", "’"); 151 | g_hash_table_insert(h, "sbquo", "‚"); 152 | g_hash_table_insert(h, "ldquo", "“"); 153 | g_hash_table_insert(h, "rdquo", "”"); 154 | g_hash_table_insert(h, "bdquo", "„"); 155 | g_hash_table_insert(h, "dagger", "†"); 156 | g_hash_table_insert(h, "Dagger", "‡"); 157 | g_hash_table_insert(h, "permil", "‰"); 158 | g_hash_table_insert(h, "lsaquo", "‹"); 159 | g_hash_table_insert(h, "rsaquo", "›"); 160 | g_hash_table_insert(h, "euro", "€"); 161 | g_hash_table_insert(h, "fnof", "ƒ"); 162 | g_hash_table_insert(h, "Alpha", "Α"); 163 | g_hash_table_insert(h, "Beta", "Β"); 164 | g_hash_table_insert(h, "Gamma", "Γ"); 165 | g_hash_table_insert(h, "Delta", "Δ"); 166 | g_hash_table_insert(h, "Epsilon", "Ε"); 167 | g_hash_table_insert(h, "Zeta", "Ζ"); 168 | g_hash_table_insert(h, "Eta", "Η"); 169 | g_hash_table_insert(h, "Theta", "Θ"); 170 | g_hash_table_insert(h, "Iota", "Ι"); 171 | g_hash_table_insert(h, "Kappa", "Κ"); 172 | g_hash_table_insert(h, "Lambda", "Λ"); 173 | g_hash_table_insert(h, "Mu", "Μ"); 174 | g_hash_table_insert(h, "Nu", "Ν"); 175 | g_hash_table_insert(h, "Xi", "Ξ"); 176 | g_hash_table_insert(h, "Omicron", "Ο"); 177 | g_hash_table_insert(h, "Pi", "Π"); 178 | g_hash_table_insert(h, "Rho", "Ρ"); 179 | g_hash_table_insert(h, "Sigma", "Σ"); 180 | g_hash_table_insert(h, "Tau", "Τ"); 181 | g_hash_table_insert(h, "Upsilon", "Υ"); 182 | g_hash_table_insert(h, "Phi", "Φ"); 183 | g_hash_table_insert(h, "Chi", "Χ"); 184 | g_hash_table_insert(h, "Psi", "Ψ"); 185 | g_hash_table_insert(h, "Omega", "Ω"); 186 | g_hash_table_insert(h, "alpha", "α"); 187 | g_hash_table_insert(h, "beta", "β"); 188 | g_hash_table_insert(h, "gamma", "γ"); 189 | g_hash_table_insert(h, "delta", "δ"); 190 | g_hash_table_insert(h, "epsilon", "ε"); 191 | g_hash_table_insert(h, "zeta", "ζ"); 192 | g_hash_table_insert(h, "eta", "η"); 193 | g_hash_table_insert(h, "theta", "θ"); 194 | g_hash_table_insert(h, "iota", "ι"); 195 | g_hash_table_insert(h, "kappa", "κ"); 196 | g_hash_table_insert(h, "lambda", "λ"); 197 | g_hash_table_insert(h, "mu", "μ"); 198 | g_hash_table_insert(h, "nu", "ν"); 199 | g_hash_table_insert(h, "xi", "ξ"); 200 | g_hash_table_insert(h, "omicron", "ο"); 201 | g_hash_table_insert(h, "pi", "π"); 202 | g_hash_table_insert(h, "rho", "ρ"); 203 | g_hash_table_insert(h, "sigmaf", "ς"); 204 | g_hash_table_insert(h, "sigma", "σ"); 205 | g_hash_table_insert(h, "tau", "τ"); 206 | g_hash_table_insert(h, "upsilon", "υ"); 207 | g_hash_table_insert(h, "phi", "φ"); 208 | g_hash_table_insert(h, "chi", "χ"); 209 | g_hash_table_insert(h, "psi", "ψ"); 210 | g_hash_table_insert(h, "omega", "ω"); 211 | g_hash_table_insert(h, "thetasym", "ϑ"); 212 | g_hash_table_insert(h, "upsih", "ϒ"); 213 | g_hash_table_insert(h, "piv", "ϖ"); 214 | g_hash_table_insert(h, "bull", "•"); 215 | g_hash_table_insert(h, "hellip", "…"); 216 | g_hash_table_insert(h, "prime", "′"); 217 | g_hash_table_insert(h, "Prime", "″"); 218 | g_hash_table_insert(h, "oline", "‾"); 219 | g_hash_table_insert(h, "frasl", "⁄"); 220 | g_hash_table_insert(h, "weierp", "℘"); 221 | g_hash_table_insert(h, "image", "ℑ"); 222 | g_hash_table_insert(h, "real", "ℜ"); 223 | g_hash_table_insert(h, "trade", "™"); 224 | g_hash_table_insert(h, "alefsym", "ℵ"); 225 | g_hash_table_insert(h, "larr", "←"); 226 | g_hash_table_insert(h, "uarr", "↑"); 227 | g_hash_table_insert(h, "rarr", "→"); 228 | g_hash_table_insert(h, "darr", "↓"); 229 | g_hash_table_insert(h, "harr", "↔"); 230 | g_hash_table_insert(h, "crarr", "↵"); 231 | g_hash_table_insert(h, "lArr", "⇐"); 232 | g_hash_table_insert(h, "uArr", "⇑"); 233 | g_hash_table_insert(h, "rArr", "⇒"); 234 | g_hash_table_insert(h, "dArr", "⇓"); 235 | g_hash_table_insert(h, "hArr", "⇔"); 236 | g_hash_table_insert(h, "forall", "∀"); 237 | g_hash_table_insert(h, "part", "∂"); 238 | g_hash_table_insert(h, "exist", "∃"); 239 | g_hash_table_insert(h, "empty", "∅"); 240 | g_hash_table_insert(h, "nabla", "∇"); 241 | g_hash_table_insert(h, "isin", "∈"); 242 | g_hash_table_insert(h, "notin", "∉"); 243 | g_hash_table_insert(h, "ni", "∋"); 244 | g_hash_table_insert(h, "prod", "∏"); 245 | g_hash_table_insert(h, "sum", "∑"); 246 | g_hash_table_insert(h, "minus", "−"); 247 | g_hash_table_insert(h, "lowast", "∗"); 248 | g_hash_table_insert(h, "radic", "√"); 249 | g_hash_table_insert(h, "prop", "∝"); 250 | g_hash_table_insert(h, "infin", "∞"); 251 | g_hash_table_insert(h, "ang", "∠"); 252 | g_hash_table_insert(h, "and", "∧"); 253 | g_hash_table_insert(h, "or", "∨"); 254 | g_hash_table_insert(h, "cap", "∩"); 255 | g_hash_table_insert(h, "cup", "∪"); 256 | g_hash_table_insert(h, "int", "∫"); 257 | g_hash_table_insert(h, "there4", "∴"); 258 | g_hash_table_insert(h, "sim", "∼"); 259 | g_hash_table_insert(h, "cong", "≅"); 260 | g_hash_table_insert(h, "asymp", "≈"); 261 | g_hash_table_insert(h, "ne", "≠"); 262 | g_hash_table_insert(h, "equiv", "≡"); 263 | g_hash_table_insert(h, "le", "≤"); 264 | g_hash_table_insert(h, "ge", "≥"); 265 | g_hash_table_insert(h, "sub", "⊂"); 266 | g_hash_table_insert(h, "sup", "⊃"); 267 | g_hash_table_insert(h, "nsub", "⊄"); 268 | g_hash_table_insert(h, "sube", "⊆"); 269 | g_hash_table_insert(h, "supe", "⊇"); 270 | g_hash_table_insert(h, "oplus", "⊕"); 271 | g_hash_table_insert(h, "otimes", "⊗"); 272 | g_hash_table_insert(h, "perp", "⊥"); 273 | g_hash_table_insert(h, "sdot", "⋅"); 274 | g_hash_table_insert(h, "lceil", "⌈"); 275 | g_hash_table_insert(h, "rceil", "⌉"); 276 | g_hash_table_insert(h, "lfloor", "⌊"); 277 | g_hash_table_insert(h, "rfloor", "⌋"); 278 | g_hash_table_insert(h, "lang", "〈"); 279 | g_hash_table_insert(h, "rang", "〉"); 280 | g_hash_table_insert(h, "loz", "◊"); 281 | g_hash_table_insert(h, "spades", "♠"); 282 | g_hash_table_insert(h, "clubs", "♣"); 283 | g_hash_table_insert(h, "hearts", "♥"); 284 | g_hash_table_insert(h, "diams", "♦"); 285 | 286 | return h; 287 | } 288 | 289 | void htmlent_hash_destroy(GHashTable *h) 290 | { 291 | g_hash_table_destroy(h); 292 | } 293 | -------------------------------------------------------------------------------- /src/htmlent.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2006-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef HTMLENT_H 21 | #define HTMLENT_H 22 | 23 | #include 24 | 25 | GHashTable *htmlent_hash_new(void); 26 | void htmlent_hash_destroy(GHashTable *h); 27 | 28 | #endif /* HTMLENT_H */ 29 | -------------------------------------------------------------------------------- /src/libxmlutil.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif /* HAVE_CONFIG_H */ 23 | 24 | #include "libxmlutil.h" 25 | 26 | #include 27 | #include 28 | 29 | char *libxmlutil_dup_attr(const xmlNode *node, const char *name) 30 | { 31 | xmlChar *s; 32 | 33 | s = xmlGetProp((xmlNode *)node, (const xmlChar *)name); 34 | 35 | if (s) 36 | return strdup((char *)s); 37 | else 38 | return NULL; 39 | } 40 | 41 | const char *libxmlutil_attr_as_string(const xmlNode *node, const char *name) 42 | { 43 | return (const char *)xmlGetProp((xmlNode *)node, (const xmlChar *)name); 44 | } 45 | 46 | long libxmlutil_attr_as_long(const xmlNode *node, const char *name) 47 | { 48 | xmlChar *s; 49 | 50 | s = xmlGetProp((xmlNode *)node, (const xmlChar *)name); 51 | 52 | if (s) 53 | return strtol((char *)s, (char **)NULL, 10); 54 | else 55 | return -1; 56 | } 57 | 58 | int libxmlutil_attr_as_int(const xmlNode *node, const char *name) 59 | { 60 | return (int)libxmlutil_attr_as_long(node, name); 61 | } 62 | 63 | char *libxmlutil_dup_value(const xmlNode *node) 64 | { 65 | xmlChar *s; 66 | 67 | s = xmlNodeListGetString(node->doc, node->xmlChildrenNode, 1); 68 | 69 | if (s) 70 | return strdup((char *)s); 71 | else 72 | return NULL; 73 | } 74 | 75 | int libxmlutil_count_by_tag_name(const xmlNode *node, const char *name) 76 | { 77 | int n = 0; 78 | 79 | for (node = node->children; node; node = node->next) 80 | if (node->type == XML_ELEMENT_NODE && !strcmp((char *)node->name, name)) 81 | n++; 82 | 83 | return n; 84 | } 85 | 86 | void libxmlutil_iterate_by_tag_name(const xmlNode *node, const char *name, 87 | void *user_data, 88 | void (*f)(const void *user_data, int i, 89 | const xmlNode *node)) 90 | { 91 | int i = 0; 92 | 93 | for (node = node->children; node; node = node->next) 94 | if (node->type == XML_ELEMENT_NODE && !strcmp((char *)node->name, name)) { 95 | f(user_data, i, node); 96 | i++; 97 | } 98 | } 99 | 100 | const xmlNode *libxmlutil_child_node_by_name(const xmlNode *node, 101 | const char *ns, const char *name) 102 | { 103 | for (node = node->children; node; node = node->next) 104 | if (node->type == XML_ELEMENT_NODE && !strcmp((char *)node->name, name) && 105 | (!ns || !strcmp((char *)node->ns->href, ns))) 106 | return node; 107 | 108 | return NULL; 109 | } 110 | -------------------------------------------------------------------------------- /src/libxmlutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef LIBXMLUTIL_H 21 | #define LIBXMLUTIL_H 22 | 23 | #include 24 | #include 25 | 26 | char *libxmlutil_dup_attr(const xmlNode *node, const char *name); 27 | const char *libxmlutil_attr_as_string(const xmlNode *node, const char *name); 28 | long libxmlutil_attr_as_long(const xmlNode *node, const char *name); 29 | int libxmlutil_attr_as_int(const xmlNode *node, const char *name); 30 | char *libxmlutil_dup_value(const xmlNode *node); 31 | int libxmlutil_count_by_tag_name(const xmlNode *node, const char *name); 32 | void libxmlutil_iterate_by_tag_name(const xmlNode *node, const char *name, 33 | void *user_data, 34 | void (*f)(const void *user_data, int i, 35 | const xmlNode *node)); 36 | const xmlNode *libxmlutil_child_node_by_name(const xmlNode *node, 37 | const char *ns, const char *name); 38 | 39 | #endif /* LIBXMLUTIL_H */ 40 | -------------------------------------------------------------------------------- /src/patterns.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2010 Tony Armistead 3 | Copyright (C) 2017-2020 Marius L. Jøhndal 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif /* HAVE_CONFIG_H */ 24 | 25 | #include "date_parsing.h" 26 | #include "patterns.h" 27 | 28 | static gchar *expand_date_pattern(const rss_item *item); 29 | static gchar *expand_title_pattern(const rss_item *item); 30 | static gchar *expand_channel_title_pattern(const channel_info *info); 31 | static gchar *expand_pattern(const channel_info *channel_info, 32 | const rss_item *item, const gchar *pattern); 33 | 34 | /* Expands a 'date' pattern to the value of the item's pub_date. Returns 35 | an empty string if pub_date is absent or invalid. Formats the date 36 | on the format 'YYYY-MM-DD'. Caller must free returned string with g_free. */ 37 | static gchar *expand_date_pattern(const rss_item *item) 38 | { 39 | gchar str_date[20]; // FIXME: suspicious 40 | 41 | if (item->pub_date) { 42 | GDate *rfc822_date = parse_rfc822_date(item->pub_date); 43 | 44 | if (rfc822_date) { 45 | g_date_strftime(str_date, sizeof(str_date), "%Y-%m-%d", rfc822_date); 46 | g_date_free(rfc822_date); 47 | return g_strdup(str_date); 48 | } 49 | } 50 | 51 | return g_strdup(""); 52 | } 53 | 54 | /* Expands a 'title' pattern to the value of the item's title. Returns 55 | an empty string if title is absent. Caller must free returned string with 56 | g_free. */ 57 | static gchar *expand_title_pattern(const rss_item *item) 58 | { 59 | if (item->title) 60 | return g_strdup(item->title); 61 | else 62 | return g_strdup(""); 63 | } 64 | 65 | /* Expands a 'channel_title' pattern to the value of the channel's title. 66 | Returns an empty string if title is absent. Caller must free returned string 67 | with g_free. */ 68 | static gchar *expand_channel_title_pattern(const channel_info *info) 69 | { 70 | if (info->title) 71 | return g_strdup(info->title); 72 | else 73 | return g_strdup(""); 74 | } 75 | 76 | /* Expands a pattern to values from the RSS field's item. Returns an empty 77 | string if pattern is invalid or if it cannot be expanded. Caller must free 78 | returned string with g_free. */ 79 | static gchar *expand_pattern(const channel_info *channel_info, 80 | const rss_item *item, const gchar *pattern) 81 | { 82 | if (g_ascii_strcasecmp(pattern, "date") == 0) 83 | return expand_date_pattern(item); 84 | else if (g_ascii_strcasecmp(pattern, "title") == 0) 85 | return expand_title_pattern(item); 86 | else if (g_ascii_strcasecmp(pattern, "channel_title") == 0) 87 | return expand_channel_title_pattern(channel_info); 88 | else 89 | return g_strdup(""); 90 | } 91 | 92 | #define DIM(a) sizeof(a) / sizeof(a[0]) 93 | 94 | gchar *expand_string_with_patterns(const gchar *string, 95 | const channel_info *channel_info, 96 | const rss_item *item) 97 | { 98 | enum { STATE_COPY, STATE_FIELD, STATE_DONE } state = STATE_COPY; 99 | GString *parts; 100 | gchar fieldname[80]; 101 | int fieldname_idx = 0; 102 | gchar *expanded_field; 103 | const gchar *cp_start = string; 104 | const gchar *cp_end = string; 105 | 106 | parts = g_string_new(NULL); 107 | 108 | while (state != STATE_DONE) { 109 | switch (state) { 110 | case STATE_COPY: 111 | /* Process */ 112 | if ((*cp_end == '\0' || *cp_end == '%') && cp_end > cp_start) 113 | g_string_append_len(parts, cp_start, cp_end - cp_start); 114 | 115 | /* State update */ 116 | if (*cp_end == '%') { 117 | state = STATE_FIELD; 118 | fieldname_idx = 0; 119 | } 120 | if (*cp_end == '\0') 121 | state = STATE_DONE; 122 | break; 123 | case STATE_FIELD: 124 | /* Process */ 125 | if (*cp_end == '\0' || *cp_end == ')') { 126 | fieldname[fieldname_idx] = '\0'; 127 | expanded_field = expand_pattern(channel_info, item, fieldname); 128 | g_string_append(parts, expanded_field); 129 | g_free(expanded_field); 130 | } else if ((*cp_end != '(') && (fieldname_idx < DIM(fieldname) - 1)) 131 | fieldname[fieldname_idx++] = *cp_end; 132 | /* State update */ 133 | if (*cp_end == '\0') 134 | state = STATE_DONE; 135 | else if (*cp_end == ')') { 136 | state = STATE_COPY; 137 | cp_start = cp_end + 1; 138 | } 139 | break; 140 | case STATE_DONE: 141 | break; 142 | } 143 | ++cp_end; 144 | } 145 | 146 | /* Free GString but keep actual string data. Caller must free this using 147 | g_free() */ 148 | return g_string_free(parts, FALSE); 149 | } 150 | -------------------------------------------------------------------------------- /src/patterns.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef PATTERN_H 21 | #define PATTERN_H 22 | 23 | #include "rss.h" 24 | 25 | gchar *expand_string_with_patterns(const gchar *string, 26 | const channel_info *channel_info, 27 | const rss_item *item); 28 | 29 | #endif /* PATTERN_H */ 30 | -------------------------------------------------------------------------------- /src/progress.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif /* HAVE_CONFIG_H */ 23 | 24 | #include "progress.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | /* This code was inspired/guided by the progress-bar implementation found in 32 | curl (src/tool_cb_prg.c) by Daniel Stenberg, in turn building on an 33 | implementation by Lars Aas. */ 34 | int progress_bar_cb(void *clientp, double dltotal, double dlnow, double ultotal, 35 | double ulnow) 36 | { 37 | double fraction; 38 | int num; 39 | int i; 40 | 41 | progress_bar *pb = (progress_bar *)clientp; 42 | 43 | /* We expect ultotal and ulnow to be 0 since we never upload anything. */ 44 | g_assert(ultotal == 0); 45 | g_assert(ulnow == 0); 46 | 47 | if (pb->width > 0) { 48 | if (dltotal == 0.0) { 49 | fraction = 0.0; 50 | num = 0; 51 | } else { 52 | long total; 53 | long position; 54 | 55 | total = (long)dltotal + pb->resume_from; 56 | position = MIN((long)dlnow + pb->resume_from, total); 57 | 58 | fraction = (double)position / (double)total; 59 | num = (int)((double)pb->width * fraction); 60 | } 61 | 62 | if (num != pb->previous_num) { 63 | for (i = 0; i < pb->width; i++) 64 | pb->buffer[i] = (i < num ? '#' : ' '); 65 | 66 | pb->buffer[pb->width] = 0; 67 | 68 | fprintf(pb->f, "\r%s %3d%%", pb->buffer, (int)(fraction * 100.0)); 69 | fflush(pb->f); 70 | 71 | pb->previous_num = num; 72 | } 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | progress_bar *progress_bar_new(long resume_from) 79 | { 80 | progress_bar *pb; 81 | gchar **environ; 82 | const gchar *columns; 83 | 84 | pb = (progress_bar *)g_malloc(sizeof(struct _progress_bar)); 85 | pb->resume_from = resume_from; 86 | pb->f = stdout; 87 | pb->width = 79; 88 | pb->previous_num = -1; 89 | 90 | /* Try to grab the COLUMNS environment variable to initialize pb->with with a 91 | suitable value. */ 92 | environ = g_get_environ(); 93 | columns = g_environ_getenv(environ, "COLUMNS"); 94 | 95 | if (columns) { 96 | char *endptr; 97 | long num = strtol(columns, &endptr, 10); 98 | if ((endptr != columns) && (endptr == columns + strlen(columns)) && 99 | (num > 0)) { 100 | pb->width = MIN( 101 | pb->width, 102 | (int)num); // restrict width of progress bar to avoid insane values 103 | } 104 | } 105 | 106 | g_strfreev(environ); 107 | 108 | /* Leave a margin for printing the percentages (the longest string is 109 | " 100%"). */ 110 | pb->width = MAX(0, pb->width - 5); 111 | 112 | /* Allocate space for progress bar string + terminating zero. */ 113 | pb->buffer = g_malloc(pb->width + 1); 114 | 115 | return pb; 116 | } 117 | 118 | void progress_bar_free(progress_bar *pb) 119 | { 120 | fprintf(pb->f, "\n"); // Make sure that we will start output on a new line. 121 | g_free(pb->buffer); 122 | g_free(pb); 123 | } 124 | -------------------------------------------------------------------------------- /src/progress.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef PROGRESS_H 21 | #define PROGRESS_H 22 | 23 | #include 24 | 25 | typedef struct _progress_bar { 26 | FILE *f; 27 | long resume_from; 28 | int width; 29 | int previous_num; 30 | char *buffer; 31 | } progress_bar; 32 | 33 | progress_bar *progress_bar_new(long resume_from); 34 | void progress_bar_free(progress_bar *pb); 35 | int progress_bar_cb(void *clientp, double dltotal, double dlnow, double ultotal, 36 | double ulnow); 37 | 38 | #endif /* PROGRESS_H */ 39 | -------------------------------------------------------------------------------- /src/rss.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif /* HAVE_CONFIG_H */ 23 | 24 | #include "htmlent.h" 25 | #include "libxmlutil.h" 26 | #include "rss.h" 27 | #include "urlget.h" 28 | #include "utils.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define MRSS_NAMESPACE "http://search.yahoo.com/mrss" 37 | 38 | static char *_dup_child_node_value(const xmlNode *node, const gchar *tag) 39 | { 40 | const xmlNode *n; 41 | 42 | n = libxmlutil_child_node_by_name(node, NULL, tag); 43 | 44 | if (n) 45 | return libxmlutil_dup_value(n); 46 | else 47 | return NULL; 48 | } 49 | 50 | static void _item_iterator(const void *user_data, int i, const xmlNode *node) 51 | { 52 | rss_file *f = (rss_file *)user_data; 53 | const xmlNode *encl; 54 | const xmlNode *mrss_content; 55 | const xmlNode *mrss_group; 56 | 57 | /* Allocate item structure. */ 58 | f->items[i] = (rss_item *)malloc(sizeof(struct _rss_item)); 59 | 60 | /* Copy item meta-information. */ 61 | f->items[i]->title = _dup_child_node_value(node, "title"); 62 | f->items[i]->link = _dup_child_node_value(node, "link"); 63 | f->items[i]->description = _dup_child_node_value(node, "description"); 64 | f->items[i]->pub_date = _dup_child_node_value(node, "pubDate"); 65 | 66 | /* Look for mrss information first, if there is any. It may be 67 | located either directly under the "item" tag, or inside an mrss 68 | "group" tag. */ 69 | mrss_content = libxmlutil_child_node_by_name(node, MRSS_NAMESPACE, "content"); 70 | 71 | if (!mrss_content) { 72 | mrss_group = libxmlutil_child_node_by_name(node, MRSS_NAMESPACE, "group"); 73 | 74 | if (mrss_group) 75 | mrss_content = 76 | libxmlutil_child_node_by_name(mrss_group, MRSS_NAMESPACE, "content"); 77 | } 78 | 79 | /* Figure out if there is an "enclosure" tag here. */ 80 | encl = libxmlutil_child_node_by_name(node, NULL, "enclosure"); 81 | 82 | if (mrss_content || encl) { 83 | f->items[i]->enclosure = (enclosure *)malloc(sizeof(struct _enclosure)); 84 | 85 | /* Set default values */ 86 | f->items[i]->enclosure->url = NULL; 87 | f->items[i]->enclosure->length = 0; 88 | f->items[i]->enclosure->type = NULL; 89 | 90 | /* Now read attributes. Prefer mrss over enclosure. */ 91 | if (mrss_content) { 92 | f->items[i]->enclosure->url = libxmlutil_dup_attr(mrss_content, "url"); 93 | f->items[i]->enclosure->length = 94 | libxmlutil_attr_as_long(mrss_content, "fileSize"); 95 | f->items[i]->enclosure->type = libxmlutil_dup_attr(encl, "type"); 96 | } 97 | 98 | if (encl) { 99 | if (!f->items[i]->enclosure->url) 100 | f->items[i]->enclosure->url = libxmlutil_dup_attr(encl, "url"); 101 | 102 | if (!f->items[i]->enclosure->length) 103 | f->items[i]->enclosure->length = 104 | libxmlutil_attr_as_long(encl, "length"); 105 | 106 | if (!f->items[i]->enclosure->type) 107 | f->items[i]->enclosure->type = libxmlutil_dup_attr(encl, "type"); 108 | } 109 | 110 | /* Clean up garbage values from the feed */ 111 | if (f->items[i]->enclosure->length < 0) 112 | f->items[i]->enclosure->length = 0; 113 | } else 114 | f->items[i]->enclosure = NULL; 115 | } 116 | 117 | static rss_file *rss_parse(const gchar *url, const xmlNode *root_element, 118 | gchar *fetched_time) 119 | { 120 | const char *version_string; 121 | const xmlNode *channel; 122 | rss_file *f; 123 | enum rss_version version; 124 | 125 | /* Do some sanity checking and extract the RSS version number. */ 126 | if (strcmp((char *)root_element->name, "rss")) { 127 | fprintf(stderr, 128 | "Error parsing RSS file %s: Unrecognized top-level element %s.\n", 129 | url, (char *)root_element->name); 130 | return NULL; 131 | } 132 | 133 | version_string = libxmlutil_attr_as_string(root_element, "version"); 134 | 135 | if (!strcmp(version_string, "2.0")) { 136 | version = RSS_VERSION_2_0; 137 | } else if (!strcmp(version_string, "0.91")) { 138 | version = RSS_VERSION_0_91; 139 | } else if (!strcmp(version_string, "0.92")) { 140 | version = RSS_VERSION_0_92; 141 | } else { 142 | version = RSS_UNKNOWN; 143 | } 144 | 145 | /* Find the channel tag and parse it. */ 146 | channel = libxmlutil_child_node_by_name(root_element, NULL, "channel"); 147 | 148 | if (channel) { 149 | /* Allocate RSS file structure and room for pointers to all entries. */ 150 | f = (rss_file *)malloc(sizeof(struct _rss_file)); 151 | 152 | f->fetched_time = g_strdup(fetched_time); 153 | 154 | f->num_items = libxmlutil_count_by_tag_name(channel, "item"); 155 | f->items = (rss_item **)malloc(sizeof(rss_item *) * f->num_items); 156 | 157 | f->version = version; 158 | 159 | /* Copy channel meta-information. */ 160 | f->channel_info.title = _dup_child_node_value(channel, "title"); 161 | f->channel_info.link = _dup_child_node_value(channel, "link"); 162 | f->channel_info.description = _dup_child_node_value(channel, "description"); 163 | f->channel_info.language = _dup_child_node_value(channel, "language"); 164 | 165 | libxmlutil_iterate_by_tag_name(channel, "item", f, _item_iterator); 166 | } else 167 | f = NULL; 168 | 169 | return f; 170 | } 171 | 172 | static xmlEntityPtr _get_entity(void *ctxt, const xmlChar *name) 173 | { 174 | static GHashTable *html_entities = NULL; 175 | xmlEntityPtr entity; 176 | gchar *contents; 177 | 178 | /* Check if entity is any of the predefined entities such as & */ 179 | entity = xmlGetPredefinedEntity(name); 180 | 181 | if (!entity) { 182 | /* Some of the RSS "specifications" are vague on whether HTML 183 | entities are allowed or not, so we will assume that they are, 184 | and look up HTML entities whenever we encounter them. */ 185 | 186 | if (!html_entities) 187 | html_entities = htmlent_hash_new(); 188 | 189 | contents = (gchar *)g_hash_table_lookup(html_entities, name); 190 | 191 | if (contents) { 192 | /* TODO: Where do we free this memory? */ 193 | entity = (xmlEntityPtr)g_new0(xmlEntity, 1); 194 | entity->type = XML_ENTITY_DECL; 195 | entity->name = name; 196 | entity->orig = (xmlChar *)contents; 197 | entity->content = (xmlChar *)contents; 198 | entity->length = g_utf8_strlen(contents, -1); 199 | entity->etype = XML_INTERNAL_PREDEFINED_ENTITY; 200 | } 201 | } 202 | 203 | return entity; 204 | } 205 | 206 | rss_file *rss_open_file(const char *filename) 207 | { 208 | xmlParserCtxtPtr ctxt; 209 | xmlDocPtr doc; 210 | rss_file *f; 211 | xmlNode *root_element = NULL; 212 | gchar *fetched_time; 213 | 214 | ctxt = xmlNewParserCtxt(); 215 | ctxt->sax->getEntity = _get_entity; 216 | doc = xmlSAXParseFile(ctxt->sax, filename, 0); 217 | 218 | if (!doc) { 219 | fprintf(stderr, "Error parsing RSS file %s.\n", filename); 220 | xmlFreeParserCtxt(ctxt); 221 | 222 | return NULL; 223 | } 224 | 225 | root_element = xmlDocGetRootElement(doc); 226 | 227 | if (!root_element) { 228 | xmlFreeDoc(doc); 229 | xmlFreeParserCtxt(ctxt); 230 | 231 | fprintf(stderr, "Error parsing RSS file %s.\n", filename); 232 | return NULL; 233 | } 234 | 235 | /* Establish the time the RSS file was 'fetched'. */ 236 | fetched_time = get_rfc822_time(); 237 | 238 | if (!fetched_time) { 239 | xmlFreeDoc(doc); 240 | xmlFreeParserCtxt(ctxt); 241 | 242 | g_fprintf(stderr, "Error retrieving current time.\n"); 243 | return NULL; 244 | } 245 | 246 | f = rss_parse(filename, root_element, fetched_time); 247 | 248 | xmlFreeDoc(doc); 249 | xmlFreeParserCtxt(ctxt); 250 | g_free(fetched_time); 251 | 252 | return f; 253 | } 254 | 255 | static int _rss_open_url_cb(FILE *f, gpointer user_data, int debug) 256 | { 257 | gchar *url = (gchar *)user_data; 258 | 259 | return urlget_file(url, f, debug); 260 | } 261 | 262 | rss_file *rss_open_url(const char *url, int debug) 263 | { 264 | rss_file *f; 265 | gchar *rss_filename; 266 | 267 | if (write_by_temporary_file(NULL, _rss_open_url_cb, (gpointer)url, 268 | &rss_filename, debug)) 269 | return NULL; 270 | 271 | f = rss_open_file(rss_filename); 272 | 273 | unlink(rss_filename); 274 | g_free(rss_filename); 275 | 276 | return f; 277 | } 278 | 279 | void rss_close(rss_file *f) 280 | { 281 | int i; 282 | rss_item *item; 283 | 284 | for (i = 0; i < f->num_items; i++) { 285 | item = f->items[i]; 286 | 287 | if (item->enclosure) { 288 | if (item->enclosure->url) 289 | free(item->enclosure->url); 290 | 291 | if (item->enclosure->type) 292 | free(item->enclosure->type); 293 | 294 | free(item->enclosure); 295 | } 296 | 297 | if (item->title) 298 | free(item->title); 299 | 300 | if (item->pub_date) 301 | free(item->pub_date); 302 | 303 | free(item); 304 | } 305 | 306 | if (f->channel_info.title) 307 | free(f->channel_info.title); 308 | 309 | g_free(f->fetched_time); 310 | 311 | free(f); 312 | } 313 | 314 | long rss_total_enclosure_size(rss_file *f) 315 | { 316 | int i; 317 | long n = 0; 318 | 319 | for (i = 0; i < f->num_items; i++) 320 | if (f->items[i]->enclosure) 321 | n += f->items[i]->enclosure->length; 322 | 323 | return n; 324 | } 325 | -------------------------------------------------------------------------------- /src/rss.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef RSS_H 21 | #define RSS_H 22 | 23 | #include "channel.h" 24 | 25 | typedef struct _rss_item { 26 | char *title; 27 | char *link; 28 | char *description; 29 | char *pub_date; 30 | enclosure *enclosure; 31 | } rss_item; 32 | 33 | enum rss_version { 34 | RSS_UNKNOWN, 35 | RSS_VERSION_0_91, 36 | RSS_VERSION_0_92, 37 | RSS_VERSION_2_0 38 | }; 39 | 40 | typedef struct _rss_file { 41 | enum rss_version version; 42 | int num_items; 43 | rss_item **items; 44 | channel_info channel_info; 45 | gchar *fetched_time; 46 | } rss_file; 47 | 48 | rss_file *rss_open_file(const char *filename); 49 | rss_file *rss_open_url(const char *url, int debug); 50 | void rss_close(rss_file *f); 51 | 52 | #endif /* RSS_H */ 53 | -------------------------------------------------------------------------------- /src/urlget.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif /* HAVE_CONFIG_H */ 23 | 24 | #include "progress.h" 25 | #include "urlget.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | int urlget_file(const char *url, FILE *f, int debug) 33 | { 34 | return urlget_buffer(url, (void *)f, NULL, 0, debug, NULL); 35 | } 36 | 37 | int urlget_buffer(const char *url, void *user_data, 38 | size_t (*write_buffer)(void *buffer, size_t size, 39 | size_t nmemb, void *user_data), 40 | long resume_from, int debug, progress_bar *pb) 41 | { 42 | CURL *easyhandle; 43 | CURLcode success; 44 | char errbuf[CURL_ERROR_SIZE]; 45 | int ret = 0; 46 | gchar *user_agent; 47 | 48 | /* Construct user agent string. */ 49 | user_agent = g_strdup_printf("%s (%s rss enclosure downloader)", 50 | PACKAGE_STRING, PACKAGE); 51 | 52 | /* Initialise curl. */ 53 | easyhandle = curl_easy_init(); 54 | 55 | if (easyhandle) { 56 | curl_easy_setopt(easyhandle, CURLOPT_URL, url); 57 | curl_easy_setopt(easyhandle, CURLOPT_ERRORBUFFER, errbuf); 58 | curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, write_buffer); 59 | curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, user_data); 60 | curl_easy_setopt(easyhandle, CURLOPT_FOLLOWLOCATION, 1); 61 | curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, user_agent); 62 | curl_easy_setopt(easyhandle, CURLOPT_ACCEPT_ENCODING, ""); 63 | 64 | if (pb) { 65 | curl_easy_setopt(easyhandle, CURLOPT_NOPROGRESS, 0); 66 | curl_easy_setopt(easyhandle, CURLOPT_PROGRESSFUNCTION, progress_bar_cb); 67 | curl_easy_setopt(easyhandle, CURLOPT_PROGRESSDATA, pb); 68 | } else 69 | curl_easy_setopt(easyhandle, CURLOPT_NOPROGRESS, 1); 70 | 71 | if (resume_from) 72 | curl_easy_setopt(easyhandle, CURLOPT_RESUME_FROM_LARGE, 73 | (curl_off_t)resume_from); 74 | 75 | curl_easy_setopt(easyhandle, CURLOPT_VERBOSE, debug); 76 | 77 | success = curl_easy_perform(easyhandle); 78 | 79 | curl_easy_cleanup(easyhandle); 80 | 81 | if (success != CURLE_OK) { 82 | if (pb) 83 | /* Insert an extra CR on stdout as we may have started printing a 84 | progress bar there. */ 85 | fprintf(stdout, "\n"); 86 | 87 | if (success == CURLE_WRITE_ERROR) { 88 | fprintf(stderr, "Error retrieving %s: %s: ", url, errbuf); 89 | perror(NULL); 90 | fprintf(stderr, "\n"); 91 | } else 92 | fprintf(stderr, "Error retrieving %s: %s\n", url, errbuf); 93 | 94 | ret = 1; 95 | } 96 | } else 97 | ret = 1; 98 | 99 | g_free(user_agent); 100 | 101 | return ret; 102 | } 103 | -------------------------------------------------------------------------------- /src/urlget.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef URLGET_H 21 | #define URLGET_H 22 | 23 | #include "progress.h" 24 | 25 | int urlget_file(const char *url, FILE *f, int debug); 26 | int urlget_buffer(const char *url, void *user_data, 27 | size_t (*write_buffer)(void *buffer, size_t size, 28 | size_t nmemb, void *user_data), 29 | long resume_from, int debug, progress_bar *pb); 30 | 31 | #endif /* URLGET_H */ 32 | -------------------------------------------------------------------------------- /src/utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif /* HAVE_CONFIG_H */ 23 | 24 | #include "utils.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | int write_by_temporary_file(const gchar *filename, 34 | int (*writer)(FILE *f, gpointer user_data, 35 | int debug), 36 | gpointer user_data, gchar **used_filename, 37 | int debug) 38 | { 39 | int retval; 40 | FILE *f; 41 | gint fd; 42 | gchar *tmp_filename_used; 43 | 44 | if (filename) { 45 | tmp_filename_used = g_strconcat(filename, ".XXXXXX", NULL); 46 | 47 | fd = g_mkstemp(tmp_filename_used); 48 | 49 | if (fd < 0) { 50 | perror("Error opening temporary file"); 51 | g_free(tmp_filename_used); 52 | return -1; 53 | } 54 | } else { 55 | GError *error = NULL; 56 | 57 | fd = g_file_open_tmp(NULL, &tmp_filename_used, &error); 58 | 59 | if (fd < 0) { 60 | g_fprintf(stderr, "Error opening temporary file: %s\n", error->message); 61 | return -1; 62 | } 63 | } 64 | 65 | f = fdopen(fd, "w"); 66 | 67 | if (!f) { 68 | perror("Error opening temporary file stream"); 69 | 70 | close(fd); 71 | g_free(tmp_filename_used); 72 | return -1; 73 | } 74 | 75 | retval = writer(f, user_data, debug); 76 | 77 | fclose(f); 78 | 79 | if (errno == ENOSPC) { 80 | fprintf(stderr, "No space left on device.\n"); 81 | unlink(tmp_filename_used); 82 | g_free(tmp_filename_used); 83 | return -1; 84 | } 85 | 86 | if (retval == 0 && filename) { 87 | if (g_rename(tmp_filename_used, filename) < 0) { 88 | fprintf(stderr, "Error renaming temporary file %s to %s: %s.\n", 89 | tmp_filename_used, filename, strerror(errno)); 90 | 91 | unlink(tmp_filename_used); 92 | g_free(tmp_filename_used); 93 | return -1; 94 | } 95 | 96 | if (used_filename) 97 | *used_filename = g_strdup(filename); 98 | } else { 99 | if (used_filename) 100 | *used_filename = g_strdup(tmp_filename_used); 101 | } 102 | 103 | g_free(tmp_filename_used); 104 | 105 | return retval; 106 | } 107 | 108 | #define RFC822_TIME_BUFFER_LEN 64 109 | 110 | gchar *get_rfc822_time(void) 111 | { 112 | char rfc822_time_buffer[RFC822_TIME_BUFFER_LEN]; 113 | time_t now; 114 | 115 | now = time(NULL); 116 | 117 | if (strftime(rfc822_time_buffer, RFC822_TIME_BUFFER_LEN, 118 | "%a, %d-%b-%Y %X GMT", gmtime(&now))) 119 | return g_strdup(rfc822_time_buffer); 120 | else 121 | return NULL; 122 | } 123 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2005-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef UTILS_H 21 | #define UTILS_H 22 | 23 | #include 24 | #include 25 | 26 | int write_by_temporary_file(const gchar *filename, 27 | int (*writer)(FILE *f, gpointer user_data, 28 | int debug), 29 | gpointer user_data, gchar **used_filename, 30 | int debug); 31 | gchar *get_rfc822_time(void); 32 | 33 | #endif /* UTILS_H */ 34 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2017 Wilhelm Schuster 3 | # Copyright (C) 2017-2018 Marius L. Jøhndal 4 | # 5 | # This library is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU Lesser General Public 7 | # License as published by the Free Software Foundation; either 8 | # version 2.1 of the License, or (at your option) any later version. 9 | # 10 | # This library is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | # Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this library; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | # 19 | AM_CPPFLAGS = $(GLIBS_CFLAGS) $(CURL_CFLAGS) 20 | 21 | AUTOMAKE_OPTIONS = subdir-objects 22 | 23 | TESTS = \ 24 | test_patterns \ 25 | test_progress \ 26 | test_filenames 27 | 28 | check_PROGRAMS = \ 29 | test_patterns \ 30 | test_progress \ 31 | test_filenames 32 | 33 | test_progress_SOURCES = test_progress.c ../src/progress.c ../src/progress.h 34 | 35 | test_progress_LDADD = $(GLIBS_LIBS) $(CURL_LIBS) 36 | 37 | test_patterns_SOURCES = test_patterns.c ../src/date_parsing.c ../src/date_parsing.h ../src/patterns.c ../src/patterns.h mocks.c mocks.h 38 | 39 | test_patterns_LDADD = $(GLIBS_LIBS) $(CURL_LIBS) 40 | 41 | test_filenames_SOURCES = test_filenames.c ../src/filenames.c ../src/filenames.h ../src/date_parsing.c ../src/date_parsing.h ../src/patterns.c ../src/patterns.h mocks.c mocks.h 42 | 43 | test_filenames_LDADD = $(GLIBS_LIBS) $(CURL_LIBS) 44 | -------------------------------------------------------------------------------- /tests/mocks.c: -------------------------------------------------------------------------------- 1 | #include "mocks.h" 2 | 3 | #include 4 | 5 | rss_item *mock_rss_item_new(char *item_title, char *item_pub_date) 6 | { 7 | rss_item *mock_item; 8 | 9 | mock_item = g_malloc(sizeof(struct _rss_item)); 10 | mock_item->title = item_title; 11 | mock_item->link = NULL; 12 | mock_item->description = NULL; 13 | mock_item->pub_date = item_pub_date; 14 | mock_item->enclosure = NULL; 15 | 16 | return mock_item; 17 | } 18 | 19 | void mock_rss_item_free(rss_item *item) 20 | { 21 | g_free(item); 22 | } 23 | 24 | channel_info *mock_channel_info_new(char *title) 25 | { 26 | channel_info *mock_channel_info; 27 | 28 | mock_channel_info = g_malloc(sizeof(struct _channel_info)); 29 | mock_channel_info->title = title; 30 | mock_channel_info->link = NULL; 31 | mock_channel_info->description = NULL; 32 | mock_channel_info->language = NULL; 33 | 34 | return mock_channel_info; 35 | } 36 | 37 | void mock_channel_info_free(channel_info *info) 38 | { 39 | g_free(info); 40 | } 41 | -------------------------------------------------------------------------------- /tests/mocks.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018-2020 Marius L. Jøhndal 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | 18 | */ 19 | 20 | #ifndef MOCKS_H 21 | #define MOCKS_H 22 | 23 | #include "../src/channel.h" 24 | #include "../src/patterns.h" 25 | 26 | rss_item *mock_rss_item_new(char *item_title, char *item_pub_date); 27 | channel_info *mock_channel_info_new(char *title); 28 | void mock_rss_item_free(rss_item *item); 29 | void mock_channel_info_free(channel_info *info); 30 | 31 | #endif /* MOCKS_H */ 32 | -------------------------------------------------------------------------------- /tests/test_filenames.c: -------------------------------------------------------------------------------- 1 | #include "../src/filenames.h" 2 | #include "mocks.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | static void filename_helper(const char *pattern, char *channel_title, 9 | char *item_title, char *item_pub_date, 10 | const char *expected_filename) 11 | { 12 | channel_info *mock_channel_info = mock_channel_info_new(channel_title); 13 | rss_item *mock_item = mock_rss_item_new(item_title, item_pub_date); 14 | gchar *filename = 15 | build_enclosure_filename("/spool", pattern, mock_channel_info, mock_item); 16 | 17 | g_assert_cmpstr(filename, ==, expected_filename); 18 | 19 | g_free(filename); 20 | mock_rss_item_free(mock_item); 21 | mock_channel_info_free(mock_channel_info); 22 | } 23 | 24 | static void test_build_enclosure_filename() 25 | { 26 | filename_helper("", NULL, NULL, NULL, "/spool"); 27 | filename_helper("static_name.mp3", NULL, NULL, NULL, 28 | "/spool/static_name.mp3"); 29 | 30 | filename_helper("%(title).mp3", NULL, "Test Title", NULL, 31 | "/spool/Test Title.mp3"); 32 | filename_helper("foo %(title) bar.mp3", NULL, "Test Title", NULL, 33 | "/spool/foo Test Title bar.mp3"); 34 | 35 | filename_helper("%(date).mp3", NULL, NULL, "Thu, 01 Oct 2015 09:53:38 GMT", 36 | "/spool/2015-10-01.mp3"); 37 | filename_helper("foo %(date) bar.mp3", NULL, NULL, 38 | "Thu, 01 Oct 2015 09:53:38 GMT", 39 | "/spool/foo 2015-10-01 bar.mp3"); 40 | 41 | /* Suspicious values */ 42 | filename_helper("%(title).mp3", NULL, "Test/Title", NULL, 43 | "/spool/TestTitle.mp3"); 44 | filename_helper("foo/%(title)/bar.mp3", NULL, "Test Title", NULL, 45 | "/spool/fooTest Titlebar.mp3"); 46 | filename_helper("invalid/name.mp3", NULL, NULL, NULL, 47 | "/spool/invalidname.mp3"); 48 | } 49 | 50 | int main(int argc, char *argv[]) 51 | { 52 | g_test_init(&argc, &argv, NULL); 53 | 54 | g_test_add_func("/filename_patterns/build_enclosure_filename", 55 | test_build_enclosure_filename); 56 | 57 | return g_test_run(); 58 | } 59 | -------------------------------------------------------------------------------- /tests/test_patterns.c: -------------------------------------------------------------------------------- 1 | #include "mocks.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | static void pattern_helper(const char *pattern, char *channel_title, 8 | char *item_title, char *item_pub_date, 9 | const char *expected_string) 10 | { 11 | channel_info *mock_channel_info = mock_channel_info_new(channel_title); 12 | rss_item *mock_item = mock_rss_item_new(item_title, item_pub_date); 13 | 14 | gchar *string = 15 | expand_string_with_patterns(pattern, mock_channel_info, mock_item); 16 | 17 | g_assert_cmpstr(string, ==, expected_string); 18 | 19 | g_free(string); 20 | mock_rss_item_free(mock_item); 21 | mock_channel_info_free(mock_channel_info); 22 | } 23 | 24 | static void test_expand_string_with_empty_pattern() 25 | { 26 | pattern_helper("", NULL, NULL, NULL, ""); 27 | } 28 | 29 | static void test_expand_string_with_static_pattern() 30 | { 31 | pattern_helper("static_name", NULL, NULL, NULL, "static_name"); 32 | } 33 | 34 | static void test_expand_string_with_date_pattern() 35 | { 36 | pattern_helper("%(date)", NULL, NULL, "Thu, 01 Oct 2015 09:53:38 GMT", 37 | "2015-10-01"); 38 | pattern_helper("foo %(date) bar", NULL, NULL, "Thu, 01 Oct 2015 09:53:38 GMT", 39 | "foo 2015-10-01 bar"); 40 | } 41 | 42 | static void test_expand_string_with_item_title_pattern() 43 | { 44 | pattern_helper("%(title)", "Channel Title", "Item Title", NULL, "Item Title"); 45 | pattern_helper("foo %(title) bar", "Channel Title", "Item Title", NULL, 46 | "foo Item Title bar"); 47 | } 48 | 49 | static void test_expand_string_with_channel_title_pattern() 50 | { 51 | pattern_helper("%(channel_title)", "Channel Title", "Item Title", NULL, 52 | "Channel Title"); 53 | pattern_helper("foo %(channel_title) bar", "Channel Title", "Item Title", 54 | NULL, "foo Channel Title bar"); 55 | } 56 | 57 | static void test_expand_string_with_pattern_with_slashes() 58 | { 59 | pattern_helper("%(title)", "Channel Title", "Test/Title", NULL, "Test/Title"); 60 | pattern_helper("foo/%(title)/bar", "Channel Title", "Test Title", NULL, 61 | "foo/Test Title/bar"); 62 | pattern_helper("invalid/name", "Channel Title", NULL, NULL, "invalid/name"); 63 | } 64 | 65 | int main(int argc, char *argv[]) 66 | { 67 | g_test_init(&argc, &argv, NULL); 68 | 69 | g_test_add_func("/patterns/expand_string_with_empty_pattern", 70 | test_expand_string_with_empty_pattern); 71 | g_test_add_func("/patterns/expand_string_with_static_pattern", 72 | test_expand_string_with_static_pattern); 73 | g_test_add_func("/patterns/expand_string_with_date_pattern", 74 | test_expand_string_with_date_pattern); 75 | g_test_add_func("/patterns/expand_string_with_item_title_pattern", 76 | test_expand_string_with_item_title_pattern); 77 | g_test_add_func("/patterns/expand_string_with_channel_title_pattern", 78 | test_expand_string_with_channel_title_pattern); 79 | g_test_add_func("/patterns/expand_string_with_pattern_with_slashes", 80 | test_expand_string_with_pattern_with_slashes); 81 | 82 | return g_test_run(); 83 | } 84 | -------------------------------------------------------------------------------- /tests/test_progress.c: -------------------------------------------------------------------------------- 1 | #include "../src/progress.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | static void test_progress_bar_new() 8 | { 9 | char *old_columns = getenv("COLUMNS"); 10 | progress_bar *pb; 11 | 12 | setenv("COLUMNS", "120", 1); 13 | pb = progress_bar_new(0); 14 | g_assert_cmpint(pb->width, ==, 74); 15 | progress_bar_free(pb); 16 | 17 | setenv("COLUMNS", "50", 1); 18 | pb = progress_bar_new(0); 19 | g_assert_cmpint(pb->width, ==, 45); 20 | progress_bar_free(pb); 21 | 22 | setenv("COLUMNS", "abc", 1); 23 | pb = progress_bar_new(0); 24 | g_assert_cmpint(pb->width, ==, 74); 25 | progress_bar_free(pb); 26 | 27 | if (old_columns) { 28 | setenv("COLUMNS", old_columns, 1); 29 | } 30 | } 31 | 32 | static void test_progress_bar_cb() 33 | { 34 | char *old_columns = getenv("COLUMNS"); 35 | progress_bar *pb; 36 | 37 | setenv("COLUMNS", "78", 1); 38 | pb = progress_bar_new(0); 39 | /* Silence progress bar output by directing it to a temporary file */ 40 | pb->f = tmpfile(); 41 | 42 | progress_bar_cb(pb, 300, 0, 0, 0); 43 | g_assert_cmpstr(pb->buffer, ==, 44 | " " 45 | " "); 46 | progress_bar_cb(pb, 300, 150, 0, 0); 47 | g_assert_cmpstr(pb->buffer, ==, 48 | "#################################### " 49 | " "); 50 | progress_bar_cb(pb, 300, 450, 0, 0); 51 | g_assert_cmpstr(pb->buffer, ==, 52 | "############################################################" 53 | "#############"); 54 | progress_bar_cb(pb, 300, -1, 0, 0); 55 | g_assert_cmpstr(pb->buffer, ==, 56 | " " 57 | " "); 58 | pb->resume_from = 150; 59 | progress_bar_cb(pb, 150, 0, 0, 0); 60 | g_assert_cmpstr(pb->buffer, ==, 61 | "#################################### " 62 | " "); 63 | 64 | fclose(pb->f); 65 | progress_bar_free(pb); 66 | 67 | if (old_columns) { 68 | setenv("COLUMNS", old_columns, 1); 69 | } 70 | } 71 | 72 | int main(int argc, char *argv[]) 73 | { 74 | g_test_init(&argc, &argv, NULL); 75 | 76 | g_test_add_func("/progress/progress_bar_new", test_progress_bar_new); 77 | g_test_add_func("/progress/progress_bar_cb", test_progress_bar_cb); 78 | 79 | return g_test_run(); 80 | } 81 | --------------------------------------------------------------------------------