summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiscomfitor <michael.blumenkrantz@gmail.com>2013-03-26 18:44:09 +0000
committerdiscomfitor <michael.blumenkrantz@gmail.com>2013-03-27 19:38:37 +0000
commit74b7e8eb87b1e78cd16f8638e1db4071fb24a84f (patch)
treec8bf3cc397b5fac329cf9df92f4c01382dc7fa2d
first commit for eRSSd: the enlightened RSS daemon
-rw-r--r--.gitignore26
-rw-r--r--AUTHORS2
-rw-r--r--COPYING502
-rw-r--r--Makefile.am40
-rw-r--r--README24
-rw-r--r--configure.ac125
-rw-r--r--erssd.conf17
-rw-r--r--erssd.pc.in11
-rw-r--r--m4/efl_compiler_flag.m457
-rw-r--r--src/bin/Makefile.mk29
-rw-r--r--src/bin/Zshare.h52
-rw-r--r--src/bin/config.c97
-rw-r--r--src/bin/dbus.c325
-rw-r--r--src/bin/eet.c327
-rw-r--r--src/bin/erssd.h109
-rw-r--r--src/bin/feed.c465
-rw-r--r--src/bin/getopt.c74
-rw-r--r--src/bin/main.c115
-rw-r--r--src/bin/zshare_config.c156
-rw-r--r--src/bin/zshare_daemon.c178
-rw-r--r--src/bin/zshare_pid.c92
-rw-r--r--src/bin/zshare_private.h32
-rw-r--r--src/lib/Erssd.h61
-rw-r--r--src/lib/Makefile.mk21
-rw-r--r--src/lib/erssd_dbus.c408
-rw-r--r--src/lib/erssd_eet.c154
-rw-r--r--src/lib/erssd_lib.c39
-rw-r--r--src/lib/erssd_private.h43
-rw-r--r--src/utils/Makefile.mk14
-rw-r--r--src/utils/erssd-config.c507
30 files changed, 4102 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ea8882
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,26 @@
1Makefile
2*.o
3*.lo
4.deps
5.libs
6.dirstamp
7*.la
8m4/l*
9erssd
10Makefile.in
11aclocal.m4
12config.guess
13config.h*
14config.sub
15configure
16depcomp
17install-sh
18ltmain.sh
19missing
20compile
21autom4te*
22/config.*
23/erssd.pc
24erssd-config
25libtool
26stamp-h1
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..e1a0c6e
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
1Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
2
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..4362b49
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,502 @@
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 Street, 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
16freedom to share and change it. By contrast, the GNU General Public
17Licenses are intended to guarantee your freedom to share and change
18free software--to make sure the software is free for all its users.
19
20 This license, the Lesser General Public License, applies to some
21specially designated software packages--typically libraries--of the
22Free Software Foundation and other authors who decide to use it. You
23can use it too, but we suggest you first think carefully about whether
24this license or the ordinary General Public License is the better
25strategy 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,
28not price. Our General Public Licenses are designed to make sure that
29you have the freedom to distribute copies of free software (and charge
30for this service if you wish); that you receive source code or can get
31it if you want it; that you can change the software and use pieces of
32it in new free programs; and that you are informed that you can do
33these things.
34
35 To protect your rights, we need to make restrictions that forbid
36distributors to deny you these rights or to ask you to surrender these
37rights. These restrictions translate to certain responsibilities for
38you 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
41or for a fee, you must give the recipients all the rights that we gave
42you. You must make sure that they, too, receive or can get the source
43code. If you link other code with the library, you must provide
44complete object files to the recipients, so that they can relink them
45with the library after making changes to the library and recompiling
46it. 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
49library, and (2) we offer you this license, which gives you legal
50permission to copy, distribute and/or modify the library.
51
52 To protect each distributor, we want to make it very clear that
53there is no warranty for the free library. Also, if the library is
54modified by someone else and passed on, the recipients should know
55that what they have is not the original version, so that the original
56author's reputation will not be affected by problems that might be
57introduced by others.
58
59 Finally, software patents pose a constant threat to the existence of
60any free program. We wish to make sure that a company cannot
61effectively restrict the users of a free program by obtaining a
62restrictive license from a patent holder. Therefore, we insist that
63any patent license obtained for a version of the library must be
64consistent with the full freedom of use specified in this license.
65
66 Most GNU software, including some libraries, is covered by the
67ordinary GNU General Public License. This license, the GNU Lesser
68General Public License, applies to certain designated libraries, and
69is quite different from the ordinary General Public License. We use
70this license for certain libraries in order to permit linking those
71libraries into non-free programs.
72
73 When a program is linked with a library, whether statically or using
74a shared library, the combination of the two is legally speaking a
75combined work, a derivative of the original library. The ordinary
76General Public License therefore permits such linking only if the
77entire combination fits its criteria of freedom. The Lesser General
78Public License permits more lax criteria for linking other code with
79the library.
80
81 We call this license the "Lesser" General Public License because it
82does Less to protect the user's freedom than the ordinary General
83Public License. It also provides other free software developers Less
84of an advantage over competing non-free programs. These disadvantages
85are the reason we use the ordinary General Public License for many
86libraries. However, the Lesser license provides advantages in certain
87special circumstances.
88
89 For example, on rare occasions, there may be a special need to
90encourage the widest possible use of a certain library, so that it becomes
91a de-facto standard. To achieve this, non-free programs must be
92allowed to use the library. A more frequent case is that a free
93library does the same job as widely used non-free libraries. In this
94case, there is little to gain by limiting the free library to free
95software only, so we use the Lesser General Public License.
96
97 In other cases, permission to use a particular library in non-free
98programs enables a greater number of people to use a large body of
99free software. For example, permission to use the GNU C Library in
100non-free programs enables many more people to use the whole GNU
101operating system, as well as its variant, the GNU/Linux operating
102system.
103
104 Although the Lesser General Public License is Less protective of the
105users' freedom, it does ensure that the user of a program that is
106linked with the Library has the freedom and the wherewithal to run
107that program using a modified version of the Library.
108
109 The precise terms and conditions for copying, distribution and
110modification follow. Pay close attention to the difference between a
111"work based on the library" and a "work that uses the library". The
112former contains code derived from the library, whereas the latter must
113be 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
119program which contains a notice placed by the copyright holder or
120other authorized party saying it may be distributed under the terms of
121this Lesser General Public License (also called "this License").
122Each licensee is addressed as "you".
123
124 A "library" means a collection of software functions and/or data
125prepared 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
129which has been distributed under these terms. A "work based on the
130Library" means either the Library or any derivative work under
131copyright law: that is to say, a work containing the Library or a
132portion of it, either verbatim or with modifications and/or translated
133straightforwardly into another language. (Hereinafter, translation is
134included without limitation in the term "modification".)
135
136 "Source code" for a work means the preferred form of the work for
137making modifications to it. For a library, complete source code means
138all the source code for all modules it contains, plus any associated
139interface definition files, plus the scripts used to control compilation
140and installation of the library.
141
142 Activities other than copying, distribution and modification are not
143covered by this License; they are outside its scope. The act of
144running a program using the Library is not restricted, and output from
145such a program is covered only if its contents constitute a work based
146on the Library (independent of the use of the Library in a tool for
147writing it). Whether that is true depends on what the Library does
148and what the program that uses the Library does.
149
150 1. You may copy and distribute verbatim copies of the Library's
151complete source code as you receive it, in any medium, provided that
152you conspicuously and appropriately publish on each copy an
153appropriate copyright notice and disclaimer of warranty; keep intact
154all the notices that refer to this License and to the absence of any
155warranty; and distribute a copy of this License along with the
156Library.
157
158 You may charge a fee for the physical act of transferring a copy,
159and you may at your option offer warranty protection in exchange for a
160fee.
161
162 2. You may modify your copy or copies of the Library or any portion
163of it, thus forming a work based on the Library, and copy and
164distribute such modifications or work under the terms of Section 1
165above, 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
190These requirements apply to the modified work as a whole. If
191identifiable sections of that work are not derived from the Library,
192and can be reasonably considered independent and separate works in
193themselves, then this License, and its terms, do not apply to those
194sections when you distribute them as separate works. But when you
195distribute the same sections as part of a whole which is a work based
196on the Library, the distribution of the whole must be on the terms of
197this License, whose permissions for other licensees extend to the
198entire whole, and thus to each and every part regardless of who wrote
199it.
200
201Thus, it is not the intent of this section to claim rights or contest
202your rights to work written entirely by you; rather, the intent is to
203exercise the right to control the distribution of derivative or
204collective works based on the Library.
205
206In addition, mere aggregation of another work not based on the Library
207with the Library (or with a work based on the Library) on a volume of
208a storage or distribution medium does not bring the other work under
209the scope of this License.
210
211 3. You may opt to apply the terms of the ordinary GNU General Public
212License instead of this License to a given copy of the Library. To do
213this, you must alter all the notices that refer to this License, so
214that they refer to the ordinary GNU General Public License, version 2,
215instead of to this License. (If a newer version than version 2 of the
216ordinary GNU General Public License has appeared, then you can specify
217that version instead if you wish.) Do not make any other change in
218these notices.
219
220 Once this change is made in a given copy, it is irreversible for
221that copy, so the ordinary GNU General Public License applies to all
222subsequent copies and derivative works made from that copy.
223
224 This option is useful when you wish to copy part of the code of
225the Library into a program that is not a library.
226
227 4. You may copy and distribute the Library (or a portion or
228derivative of it, under Section 2) in object code or executable form
229under the terms of Sections 1 and 2 above provided that you accompany
230it with the complete corresponding machine-readable source code, which
231must be distributed under the terms of Sections 1 and 2 above on a
232medium customarily used for software interchange.
233
234 If distribution of object code is made by offering access to copy
235from a designated place, then offering equivalent access to copy the
236source code from the same place satisfies the requirement to
237distribute the source code, even though third parties are not
238compelled to copy the source along with the object code.
239
240 5. A program that contains no derivative of any portion of the
241Library, but is designed to work with the Library by being compiled or
242linked with it, is called a "work that uses the Library". Such a
243work, in isolation, is not a derivative work of the Library, and
244therefore falls outside the scope of this License.
245
246 However, linking a "work that uses the Library" with the Library
247creates an executable that is a derivative of the Library (because it
248contains portions of the Library), rather than a "work that uses the
249library". The executable is therefore covered by this License.
250Section 6 states terms for distribution of such executables.
251
252 When a "work that uses the Library" uses material from a header file
253that is part of the Library, the object code for the work may be a
254derivative work of the Library even though the source code is not.
255Whether this is true is especially significant if the work can be
256linked without the Library, or if the work is itself a library. The
257threshold for this to be true is not precisely defined by law.
258
259 If such an object file uses only numerical parameters, data
260structure layouts and accessors, and small macros and small inline
261functions (ten lines or less in length), then the use of the object
262file is unrestricted, regardless of whether it is legally a derivative
263work. (Executables containing this object code plus portions of the
264Library will still fall under Section 6.)
265
266 Otherwise, if the work is a derivative of the Library, you may
267distribute the object code for the work under the terms of Section 6.
268Any executables containing that work also fall under Section 6,
269whether 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
272link a "work that uses the Library" with the Library to produce a
273work containing portions of the Library, and distribute that work
274under terms of your choice, provided that the terms permit
275modification of the work for the customer's own use and reverse
276engineering for debugging such modifications.
277
278 You must give prominent notice with each copy of the work that the
279Library is used in it and that the Library and its use are covered by
280this License. You must supply a copy of this License. If the work
281during execution displays copyright notices, you must include the
282copyright notice for the Library among them, as well as a reference
283directing the user to the copy of this License. Also, you must do one
284of 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
319Library" must include any data and utility programs needed for
320reproducing the executable from it. However, as a special exception,
321the materials to be distributed need not include anything that is
322normally distributed (in either source or binary form) with the major
323components (compiler, kernel, and so on) of the operating system on
324which the executable runs, unless that component itself accompanies
325the executable.
326
327 It may happen that this requirement contradicts the license
328restrictions of other proprietary libraries that do not normally
329accompany the operating system. Such a contradiction means you cannot
330use both them and the Library together in an executable that you
331distribute.
332
333 7. You may place library facilities that are a work based on the
334Library side-by-side in a single library together with other library
335facilities not covered by this License, and distribute such a combined
336library, provided that the separate distribution of the work based on
337the Library and of the other library facilities is otherwise
338permitted, 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
350the Library except as expressly provided under this License. Any
351attempt otherwise to copy, modify, sublicense, link with, or
352distribute the Library is void, and will automatically terminate your
353rights under this License. However, parties who have received copies,
354or rights, from you under this License will not have their licenses
355terminated so long as such parties remain in full compliance.
356
357 9. You are not required to accept this License, since you have not
358signed it. However, nothing else grants you permission to modify or
359distribute the Library or its derivative works. These actions are
360prohibited by law if you do not accept this License. Therefore, by
361modifying or distributing the Library (or any work based on the
362Library), you indicate your acceptance of this License to do so, and
363all its terms and conditions for copying, distributing or modifying
364the Library or works based on it.
365
366 10. Each time you redistribute the Library (or any work based on the
367Library), the recipient automatically receives a license from the
368original licensor to copy, distribute, link with or modify the Library
369subject to these terms and conditions. You may not impose any further
370restrictions on the recipients' exercise of the rights granted herein.
371You are not responsible for enforcing compliance by third parties with
372this License.
373
374 11. If, as a consequence of a court judgment or allegation of patent
375infringement or for any other reason (not limited to patent issues),
376conditions are imposed on you (whether by court order, agreement or
377otherwise) that contradict the conditions of this License, they do not
378excuse you from the conditions of this License. If you cannot
379distribute so as to satisfy simultaneously your obligations under this
380License and any other pertinent obligations, then as a consequence you
381may not distribute the Library at all. For example, if a patent
382license would not permit royalty-free redistribution of the Library by
383all those who receive copies directly or indirectly through you, then
384the only way you could satisfy both it and this License would be to
385refrain entirely from distribution of the Library.
386
387If any portion of this section is held invalid or unenforceable under any
388particular circumstance, the balance of the section is intended to apply,
389and the section as a whole is intended to apply in other circumstances.
390
391It is not the purpose of this section to induce you to infringe any
392patents or other property right claims or to contest validity of any
393such claims; this section has the sole purpose of protecting the
394integrity of the free software distribution system which is
395implemented by public license practices. Many people have made
396generous contributions to the wide range of software distributed
397through that system in reliance on consistent application of that
398system; it is up to the author/donor to decide if he or she is willing
399to distribute software through any other system and a licensee cannot
400impose that choice.
401
402This section is intended to make thoroughly clear what is believed to
403be a consequence of the rest of this License.
404
405 12. If the distribution and/or use of the Library is restricted in
406certain countries either by patents or by copyrighted interfaces, the
407original copyright holder who places the Library under this License may add
408an explicit geographical distribution limitation excluding those countries,
409so that distribution is permitted only in or among countries not thus
410excluded. In such case, this License incorporates the limitation as if
411written in the body of this License.
412
413 13. The Free Software Foundation may publish revised and/or new
414versions of the Lesser General Public License from time to time.
415Such new versions will be similar in spirit to the present version,
416but may differ in detail to address new problems or concerns.
417
418Each version is given a distinguishing version number. If the Library
419specifies a version number of this License which applies to it and
420"any later version", you have the option of following the terms and
421conditions either of that version or of any later version published by
422the Free Software Foundation. If the Library does not specify a
423license version number, you may choose any version ever published by
424the Free Software Foundation.
425
426 14. If you wish to incorporate parts of the Library into other free
427programs whose distribution conditions are incompatible with these,
428write to the author to ask for permission. For software which is
429copyrighted by the Free Software Foundation, write to the Free
430Software Foundation; we sometimes make exceptions for this. Our
431decision will be guided by the two goals of preserving the free status
432of all derivatives of our free software and of promoting the sharing
433and reuse of software generally.
434
435 NO WARRANTY
436
437 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446
447 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456DAMAGES.
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
463possible use to the public, we recommend making it free software that
464everyone can redistribute and change. You can do so by permitting
465redistribution under these terms (or, alternatively, under the terms of the
466ordinary General Public License).
467
468 To apply these terms, attach the following notices to the library. It is
469safest to attach them to the start of each source file to most effectively
470convey 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 <one line to give the library's name and a brief idea of what it does.>
474 Copyright (C) <year> <name of author>
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
489
490Also add information on how to contact you by electronic and paper mail.
491
492You should also get your employer (if you work as a programmer) or your
493school, if any, to sign a "copyright disclaimer" for the library, if
494necessary. 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 <signature of Ty Coon>, 1 April 1990
500 Ty Coon, President of Vice
501
502That's all there is to it!
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..76317d4
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,40 @@
1ACLOCAL_AMFLAGS = -I m4
2AUTOMAKE_OPTIONS = subdir-objects
3
4EXTRA_DIST = \
5AUTHORS \
6COPYING \
7erssd.conf \
8erssd.pc.in
9
10bin_PROGRAMS =
11
12pkgconfigdir = $(libdir)/pkgconfig
13pkgconfig_DATA = erssd.pc
14
15erssdconfdir = $(datadir)/$(PACKAGE)
16erssdconf_DATA = erssd.conf
17
18CLEANFILES = erssd-*.tar.*
19DISTCLEANFILES =
20MAINTAINERCLEANFILES = \
21Makefile.in \
22aclocal.m4 \
23config.guess \
24config.h* \
25config.sub \
26configure \
27depcomp \
28install-sh \
29ltmain.sh \
30missing \
31compile \
32m4/l*
33
34include src/bin/Makefile.mk
35include src/lib/Makefile.mk
36include src/utils/Makefile.mk
37
38maintainer-clean-local:
39 rm -rf autom4te.cache
40
diff --git a/README b/README
new file mode 100644
index 0000000..da85046
--- /dev/null
+++ b/README
@@ -0,0 +1,24 @@
1eRSSd is a daemon for subscribing and caching multiple RSS feeds across applications and systems.
2
3
4
5Requirements:
6=============
7Azy
8Efreet
9Edbus2
10
11
12
13Configuration
14=============
15A sample erssd.conf file is installed into $(datadir)/erssd. This file controls the base
16aspects of the daemon, such as the location of feed cache files and pidfiles. By default,
17erssd will search for config files in and save files to $XDG_CONFIG_HOME/erssd/, but this can be
18changed by cmdline options as well as config file options.
19
20
21Use
22===
23Feeds can be added/removed as cmdline options to the daemon, or using the dbus interfaces.
24A sample utility for configuration, erssd-config, is included.
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..85f7a4b
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,125 @@
1##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
2##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
3m4_define([v_maj], [0])
4m4_define([v_min], [0])
5m4_define([v_mic], [99])
6m4_define([v_rev], m4_esyscmd([(git rev-list --count HEAD 2>/dev/null || echo 0) | tr -d '\n']))dnl
7##-- When released, remove the dnl on the below line
8dnl m4_undefine([v_rev])
9##-- When doing snapshots - change soname. remove dnl on below line
10m4_define([relname], [ver-pre-svn-09])
11m4_define([v_rel], [-release relname])
12##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
13m4_ifdef([v_rev], [m4_define([v_ver], [v_maj.v_min.v_mic.v_rev])],
14[m4_define([v_ver], [v_maj.v_min.v_mic])])
15m4_define([lt_rev], m4_eval(v_maj + v_min))
16m4_define([lt_cur], v_mic)
17m4_define([lt_age], v_min)
18##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
19##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
20
21AC_INIT([erssd], [v_ver], [michael.blumenkrantz@gmail.com], [erssd])
22AC_CONFIG_SRCDIR([Makefile.am])
23AC_CONFIG_MACRO_DIR([m4])
24AC_CONFIG_HEADER([config.h])
25
26AC_GNU_SOURCE
27AC_ISC_POSIX
28
29##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
30##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
31m4_ifdef([v_rev], , [m4_define([v_rev], [0])])
32m4_ifdef([v_rel], , [m4_define([v_rel], [])])
33AC_DEFINE_UNQUOTED(VMAJ, [v_maj], [Major version])
34AC_DEFINE_UNQUOTED(VMIN, [v_min], [Minor version])
35AC_DEFINE_UNQUOTED(VMIC, [v_mic], [Micro version])
36AC_DEFINE_UNQUOTED(VREV, [v_rev], [Revison])
37version_info="lt_rev:lt_cur:lt_age"
38release_info="v_rel"
39AC_SUBST(version_info)
40AC_SUBST(release_info)
41##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
42##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##--##
43VMAJ=v_maj
44AC_SUBST(VMAJ)
45
46AM_INIT_AUTOMAKE([foreign])
47m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
48
49AC_PROG_LIBTOOL
50AC_PROG_INSTALL
51AC_PROG_CC
52AM_PROG_CC_C_O
53AC_PROG_MAKE_SET
54AC_HEADER_STDC
55
56AC_FUNC_ALLOCA
57
58PKG_PROG_PKG_CONFIG
59
60min_efl_version=1.7
61ERSSD_UTIL_REQUIRES="eina >= $min_efl_version eet >= $min_efl_version azy edbus2"
62
63PKG_CHECK_MODULES(ERSSD_UTIL, [$ERSSD_UTIL_REQUIRES])
64PKG_CHECK_MODULES(ERSSD, [ecore >= $min_efl_version ecore-file >= $min_efl_version efreet >= $min_efl_version])
65
66want_config=
67build_config=
68AC_ARG_ENABLE([config],
69 [AC_HELP_STRING([--disable-config], [disable building erssd-config @<:@default=detect@:>@])],
70 [want_config=$enableval]
71)
72
73if test "x$want_config" != "xno" ; then
74 CONFIG_REQUIRES="elementary >= $min_efl_version"
75 PKG_CHECK_MODULES(CONFIG, [$CONFIG_REQUIRES], [build_config=config], [build_config=])
76fi
77AM_CONDITIONAL(BUILD_CONFIG, [test -n "${build_config}"])
78
79
80EFL_COMPILER_FLAG([-fvisibility=hidden])
81m4_ifdef([v_rev],
82 [
83 EFL_COMPILER_FLAG([-Wshadow])
84 EFL_COMPILER_FLAG([-Wall])
85 EFL_COMPILER_FLAG([-Wextra])
86 ])
87
88AC_SUBST(ERSSD_UTIL_REQUIRES)
89
90# write output
91AC_CONFIG_FILES([
92 Makefile
93 erssd.pc
94])
95AC_OUTPUT
96
97# report
98txt_strip() {
99 echo "[$]@" | sed -e 's/^[[ \t]]*\([[^ \t]]*\)[[ \t]]*$/\1/g'
100}
101
102echo
103cat << SUMMARY_EOF
104Summary:
105 * project.........: $PACKAGE $VERSION
106 * prefix..........: $(txt_strip $prefix)
107 * CFLAGS..........: $(txt_strip $CFLAGS)
108 * LDFLAGS.........: $(txt_strip $LDFLAGS)
109SUMMARY_EOF
110
111cat << UTILITIES_EOF
112Utilities:
113 * erssd-config....: $(test -n $build_config && echo yes)
114UTILITIES_EOF
115echo
116
117cat << COMPILE_EOF
118Compilation........: make (or gmake)
119COMPILE_EOF
120echo
121
122cat << INSTALL_EOF
123Installation.......: make all install (as root if needed, with 'su' or 'sudo')
124INSTALL_EOF
125echo
diff --git a/erssd.conf b/erssd.conf
new file mode 100644
index 0000000..586503b
--- /dev/null
+++ b/erssd.conf
@@ -0,0 +1,17 @@
1# this is the directory where eet config data is saved
2#cfg_dir=/path/to/some/dir
3
4# this is the location to create a pid file
5#pid_file=/path/to/file.pid
6
7# this is the log level to run with
8# default=2||WARN
9#log_level=[0-5]||[EINA_LOG_LEVEL_{CRITICAL,ERR,WARN,INFO,DBG,UNKNOWN}]
10
11# this is the base, non-adjusted delay to update feeds on
12# default=15
13#feed_interval=some_number_in_minutes
14
15# whether to run the daemon system-wide or as a session
16# default is 0
17#system_mode=0||1
diff --git a/erssd.pc.in b/erssd.pc.in
new file mode 100644
index 0000000..ded149a
--- /dev/null
+++ b/erssd.pc.in
@@ -0,0 +1,11 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5
6Name: erssd
7Description: Client utilities for eRSSd
8Version: @VERSION@
9Libs: -L${libdir} -lerssd_util
10Requires.private: @ERSSD_UTIL_REQUIRES@
11Cflags: -I${includedir}/@PACKAGE@-@VMAJ@
diff --git a/m4/efl_compiler_flag.m4 b/m4/efl_compiler_flag.m4
new file mode 100644
index 0000000..25c285d
--- /dev/null
+++ b/m4/efl_compiler_flag.m4
@@ -0,0 +1,57 @@
1dnl Copyright (C) 2010 Vincent Torri <vtorri at univ-evry dot fr>
2dnl and Albin Tonnerre <albin dot tonnerre at gmail dot com>
3dnl That code is public domain and can be freely used or copied.
4
5dnl Macro that checks if a compiler flag is supported by the compiler.
6
7dnl Usage: EFL_COMPILER_FLAG(flag)
8dnl flag is added to CFLAGS if supported.
9
10AC_DEFUN([EFL_COMPILER_FLAG],
11[
12
13CFLAGS_save="${CFLAGS}"
14CFLAGS="${CFLAGS} $1"
15
16AC_LANG_PUSH([C])
17AC_MSG_CHECKING([whether the compiler supports $1])
18
19AC_COMPILE_IFELSE(
20 [AC_LANG_PROGRAM([[]])],
21 [have_flag="yes"],
22 [have_flag="no"])
23AC_MSG_RESULT([${have_flag}])
24
25if test "x${have_flag}" = "xno" ; then
26 CFLAGS="${CFLAGS_save}"
27fi
28AC_LANG_POP([C])
29
30])
31
32dnl Macro that checks if a linker flag is supported by the compiler.
33
34dnl Usage: EFL_LINKER_FLAG(flag)
35dnl flag is added to LDFLAGS if supported (will be passed to ld anyway).
36
37AC_DEFUN([EFL_LINKER_FLAG],
38[
39
40LDFLAGS_save="${LDFLAGS}"
41LDFLAGS="${LDFLAGS} $1"
42
43AC_LANG_PUSH([C])
44AC_MSG_CHECKING([whether the compiler supports $1])
45
46AC_LINK_IFELSE(
47 [AC_LANG_PROGRAM([[]])],
48 [have_flag="yes"],
49 [have_flag="no"])
50AC_MSG_RESULT([${have_flag}])
51
52if test "x${have_flag}" = "xno" ; then
53 LDFLAGS="${LDFLAGS_save}"
54fi
55AC_LANG_POP([C])
56
57])
diff --git a/src/bin/Makefile.mk b/src/bin/Makefile.mk
new file mode 100644
index 0000000..53b67b0
--- /dev/null
+++ b/src/bin/Makefile.mk
@@ -0,0 +1,29 @@
1bin_PROGRAMS += src/bin/erssd
2
3EXTRA_DIST += \
4src/bin/erssd.h \
5src/bin/Zshare.h \
6src/bin/zshare_private.h
7
8src_bin_erssd_CPPFLAGS = \
9-I$(top_srcdir) \
10-I$(top_srcdir)/src/lib \
11@ERSSD_CFLAGS@ \
12@ERSSD_UTIL_CFLAGS@
13
14src_bin_erssd_LDADD = \
15@ERSSD_LIBS@ \
16@ERSSD_UTIL_LIBS@ \
17$(top_builddir)/src/lib/liberssd_util.la \
18-lm
19
20src_bin_erssd_SOURCES = \
21src/bin/config.c \
22src/bin/dbus.c \
23src/bin/eet.c \
24src/bin/feed.c \
25src/bin/getopt.c \
26src/bin/main.c \
27src/bin/zshare_config.c \
28src/bin/zshare_daemon.c \
29src/bin/zshare_pid.c
diff --git a/src/bin/Zshare.h b/src/bin/Zshare.h
new file mode 100644
index 0000000..da80b25
--- /dev/null
+++ b/src/bin/Zshare.h
@@ -0,0 +1,52 @@
1/* ZSHARE
2 * Copyright (C) 2011 Mike Blumenkrantz, Zentific LLC
3 *
4 * All rights reserved.
5 * Use is subject to license terms.
6 *
7 * Please visit http://zentific.com for news and updates
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 */
19#ifndef Z_SHARE_H
20#define Z_SHARE_H
21
22#include <time.h>
23
24#ifdef ZAPI
25# undef ZAPI
26#endif
27
28#ifdef __GNUC__
29# if __GNUC__ >= 4
30# define ZAPI __attribute__ ((visibility("default")))
31# else
32# define ZAPI
33# endif
34#else
35# define ZAPI
36#endif
37
38
39/* config */
40typedef int (*Zshare_Config_Parse_Cb)(int, const char *, const char *, void *);
41
42ZAPI int zshare_config_parse(const char *file, Zshare_Config_Parse_Cb cb, void *data);
43
44/* PID */
45ZAPI int zshare_pid_check(const char *pid_file);
46ZAPI int zshare_pid_create(const char *pid_file);
47ZAPI void zshare_pid_delete(void);
48
49/* daemon */
50ZAPI int zshare_daemon_detach(int ignsigcld);
51ZAPI int zshare_daemon_closefds(int all);
52#endif
diff --git a/src/bin/config.c b/src/bin/config.c
new file mode 100644
index 0000000..cdc918d
--- /dev/null
+++ b/src/bin/config.c
@@ -0,0 +1,97 @@
1#include "erssd.h"
2#include "Zshare.h"
3
4static int
5_config_parse_cb(int lineno EINA_UNUSED, const char *name, const char *value, void *data EINA_UNUSED)
6{
7 if (!strcmp(name, "cfg_dir"))
8 {
9 if (strlen(value) > PATH_MAX) return 0;
10 if (!erssd_cf->cfg_dir)
11 erssd_cf->cfg_dir = strdup(value);
12 return 1;
13 }
14 if (!strcmp(name, "pid_file"))
15 {
16 if (strlen(value) > PATH_MAX) return 0;
17 if (!erssd_cf->pid_file)
18 erssd_cf->pid_file = strdup(value);
19 return 1;
20 }
21 if (!strcmp(name, "log_level"))
22 {
23 if (isdigit(value[0]))
24 {
25 int level;
26
27 errno = 0;
28 level = strtol(value, NULL, 10);
29 if (errno) return 0;
30 if ((level < EINA_LOG_LEVEL_CRITICAL) || (level > EINA_LOG_LEVEL_UNKNOWN)) return 0;
31 if (erssd_cf->log_level != 10) return 1;
32 erssd_cf->log_level = level;
33 return 1;
34 }
35 else if (!strncmp(value, "EINA_LOG_LEVEL_", sizeof("EINA_LOG_LEVEL_") - 1))
36 {
37 const char *level = value + sizeof("EINA_LOG_LEVEL_") - 1;
38 Eina_Log_Level l;
39
40 if (!strcmp(level, "CRITICAL"))
41 l = EINA_LOG_LEVEL_CRITICAL;
42 else if (!strcmp(level, "ERR"))
43 l = EINA_LOG_LEVEL_ERR;
44 else if (!strcmp(level, "WARN"))
45 l = EINA_LOG_LEVEL_WARN;
46 else if (!strcmp(level, "INFO"))
47 l = EINA_LOG_LEVEL_INFO;
48 else if (!strcmp(level, "DBG"))
49 l = EINA_LOG_LEVEL_DBG;
50 else if (!strcmp(level, "UNKNOWN"))
51 l = EINA_LOG_LEVEL_UNKNOWN;
52 else return 0;
53 if (erssd_cf->log_level != 10) return 1;
54 erssd_cf->log_level = l;
55 return 1;
56 }
57 return 0;
58 }
59 if (!strcmp(name, "feed_interval"))
60 {
61 errno = 0;
62 erssd_cf->feed_interval = strtoul(value, NULL, 10);
63 return !errno;
64 }
65 if (!strcmp(name, "system_mode"))
66 {
67 errno = 0;
68 erssd_cf->feed_interval = strtoul(value, NULL, 10);
69 return !errno;
70 }
71 return 0;
72}
73
74void
75erssd_config_file_read(const char *file)
76{
77 if (!file)
78 {
79 if (erssd_cf->system)
80 {
81 file = "/etc/erssd/" ERSSD_CONFIG_FILENAME;
82 }
83 else
84 {
85 char buf[PATH_MAX];
86 const char *dir;
87
88 dir = efreet_config_home_get();
89 if (dir)
90 snprintf(buf, sizeof(buf), "%s/erssd/" ERSSD_CONFIG_FILENAME, dir);
91 else
92 snprintf(buf, sizeof(buf), "%s/." ERSSD_CONFIG_FILENAME, getenv("HOME"));
93 file = buf;
94 }
95 }
96 zshare_config_parse(file, _config_parse_cb, NULL);
97}
diff --git a/src/bin/dbus.c b/src/bin/dbus.c
new file mode 100644
index 0000000..86193d9
--- /dev/null
+++ b/src/bin/dbus.c
@@ -0,0 +1,325 @@
1#include "erssd.h"
2
3#include <EDBus.h>
4
5static EDBus_Connection *erssd_dbus_conn = NULL;
6static EDBus_Service_Interface *erssd_base_iface = NULL;
7static EDBus_Service_Interface *erssd_feed_iface = NULL;
8
9/////////////////// METHODS ///////////////////////////////////////
10/******************* BASE *****************************************/
11static EDBus_Message *
12_dbus_cfgfile_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg EINA_UNUSED)
13{
14 EDBus_Message *reply;
15
16 reply = edbus_message_method_return_new(msg);
17 edbus_message_arguments_append(reply, "s", erssd_eet_feed_cfgfile_get());
18 return reply;
19}
20
21static EDBus_Message *
22_dbus_cachefile_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg EINA_UNUSED)
23{
24 EDBus_Message *reply;
25
26 reply = edbus_message_method_return_new(msg);
27 edbus_message_arguments_append(reply, "s", erssd_eet_feed_cachefile_get());
28 return reply;
29}
30
31static EDBus_Message *
32_dbus_quit_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg EINA_UNUSED)
33{
34 erssd_exit(0);
35 return NULL;
36}
37
38static const EDBus_Method base_methods[] =
39{
40 { "FeedConfigFile", NULL, EDBUS_ARGS({"s", "Path to currently-used feed config file"}), _dbus_cfgfile_cb, 0},
41 { "FeedCacheFile", NULL, EDBUS_ARGS({"s", "Path to currently-used feed cache file"}), _dbus_cachefile_cb, 0},
42 { "Shutdown", NULL, NULL, _dbus_quit_cb, 0},
43 {NULL, NULL, NULL, NULL, 0}
44};
45
46static const EDBus_Service_Interface_Desc base_desc =
47{
48 ERSSD_INTERFACE, base_methods, NULL, NULL, NULL, NULL
49};
50/******************* FEED *****************************************/
51static EDBus_Message *
52_dbus_feed_add_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg)
53{
54 char *url;
55 Eina_Bool ret;
56 EDBus_Message *reply;
57 const char *error_name, *error_text;
58
59 if (edbus_message_error_get(msg, &error_name, &error_text))
60 {
61 ERR("%s: %s", error_name, error_text);
62 goto error;
63 }
64 if (!edbus_message_arguments_get(msg, "s", &url)) goto error;
65 if ((!url) || (!url[0])) goto error;
66 ret = erssd_feed_add_by_url(url);
67 reply = edbus_message_method_return_new(msg);
68 edbus_message_arguments_append(reply, "b", ret);
69 return reply;
70error:
71 reply = edbus_message_error_new(msg, "org.erssd.error", "Ouch!");
72 return reply;
73}
74
75static EDBus_Message *
76_dbus_feed_del_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg)
77{
78 char *url;
79 Eina_Bool ret;
80 EDBus_Message *reply;
81 const char *error_name, *error_text;
82
83 if (edbus_message_error_get(msg, &error_name, &error_text))
84 {
85 ERR("%s: %s", error_name, error_text);
86 goto error;
87 }
88 if (!edbus_message_arguments_get(msg, "s", &url)) goto error;
89 if ((!url) || (!url[0])) goto error;
90 ret = erssd_feed_del_by_url(url);
91 reply = edbus_message_method_return_new(msg);
92 edbus_message_arguments_append(reply, "b", ret);
93 return reply;
94error:
95 reply = edbus_message_error_new(msg, "org.erssd.error", "Ouch!");
96 return reply;
97}
98
99static Eina_Bool
100_dbus_feed_list_hasher(const Eina_Hash *h EINA_UNUSED, const char *key, void *data EINA_UNUSED, EDBus_Message_Iter *iter)
101{
102 edbus_message_iter_basic_append(iter, 's', key);
103 return EINA_TRUE;
104}
105
106static EDBus_Message *
107_dbus_feed_list_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg)
108{
109 EDBus_Message *reply;
110 EDBus_Message_Iter *iter, *array;
111
112 reply = edbus_message_method_return_new(msg);
113 iter = edbus_message_iter_get(reply);
114 array = edbus_message_iter_container_new(iter, 'a', "s");
115 eina_hash_foreach(erssd_feeds, (Eina_Hash_Foreach)_dbus_feed_list_hasher, array);
116 edbus_message_iter_container_close(iter, array);
117 return reply;
118}
119
120static EDBus_Message *
121_dbus_feed_item_clear_read_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg)
122{
123 char *url;
124 Rss_Feed *feed;
125 EDBus_Message *reply;
126 const char *error_name, *error_text;
127
128 if (edbus_message_error_get(msg, &error_name, &error_text))
129 {
130 ERR("%s: %s", error_name, error_text);
131 goto error;
132 }
133 if (!edbus_message_arguments_get(msg, "s", &url)) goto error;
134 if ((!url) || (!url[0])) goto error;
135 feed = eina_hash_find(erssd_feeds, url);
136 if (!feed) goto error;
137 erssd_feed_clear_read(feed);
138 return edbus_message_method_return_new(msg);
139error:
140 reply = edbus_message_error_new(msg, "org.erssd.error", "Ouch!");
141 return reply;
142}
143
144static EDBus_Message *
145_dbus_feed_item_read_all_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg)
146{
147 char *url;
148 Rss_Feed *feed;
149 EDBus_Message *reply;
150 const char *error_name, *error_text;
151
152 if (edbus_message_error_get(msg, &error_name, &error_text))
153 {
154 ERR("%s: %s", error_name, error_text);
155 goto error;
156 }
157 if (!edbus_message_arguments_get(msg, "s", &url)) goto error;
158 if ((!url) || (!url[0])) goto error;
159 feed = eina_hash_find(erssd_feeds, url);
160 if (!feed) goto error;
161 erssd_feed_read(feed);
162 return edbus_message_method_return_new(msg);
163error:
164 reply = edbus_message_error_new(msg, "org.erssd.error", "Ouch!");
165 return reply;
166}
167
168static EDBus_Message *
169_dbus_feed_item_read_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg)
170{
171 char *url, *uuid;
172 Rss_Feed *feed;
173 EDBus_Message *reply;
174 const char *error_name, *error_text;
175
176 if (edbus_message_error_get(msg, &error_name, &error_text))
177 {
178 ERR("%s: %s", error_name, error_text);
179 goto error;
180 }
181 if (!edbus_message_arguments_get(msg, "ss", &url, &uuid)) goto error;
182 if ((!url) || (!url[0])) goto error;
183 if ((!uuid) || (!uuid[0])) goto error;
184 feed = eina_hash_find(erssd_feeds, url);
185 if (!feed) goto error;
186 if (erssd_feed_item_read_set(feed, uuid, EINA_TRUE))
187 return edbus_message_method_return_new(msg);
188error:
189 reply = edbus_message_error_new(msg, "org.erssd.error", "Ouch!");
190 return reply;
191}
192
193static EDBus_Message *
194_dbus_feed_item_unread_cb(const EDBus_Service_Interface *iface EINA_UNUSED, const EDBus_Message *msg)
195{
196 char *url, *uuid;
197 Rss_Feed *feed;
198 EDBus_Message *reply;
199 const char *error_name, *error_text;
200
201 if (edbus_message_error_get(msg, &error_name, &error_text))
202 {
203 ERR("%s: %s", error_name, error_text);
204 goto error;
205 }
206 if (!edbus_message_arguments_get(msg, "ss", &url, &uuid)) goto error;
207 if ((!url) || (!url[0])) goto error;
208 if ((!uuid) || (!uuid[0])) goto error;
209 feed = eina_hash_find(erssd_feeds, url);
210 if (!feed) goto error;
211 if (erssd_feed_item_read_set(feed, uuid, EINA_FALSE))
212 return edbus_message_method_return_new(msg);
213error:
214 reply = edbus_message_error_new(msg, "org.erssd.error", "Ouch!");
215 return reply;
216}
217
218static const EDBus_Method feed_methods[] =
219{
220 { "Add", EDBUS_ARGS({"s", "url"}), EDBUS_ARGS({"b", "success"}), _dbus_feed_add_cb, 0},
221 { "List", NULL, EDBUS_ARGS({"as", "urls"}), _dbus_feed_list_cb, 0},
222 { "Del", EDBUS_ARGS({"s", "url"}), EDBUS_ARGS({"b", "success"}), _dbus_feed_del_cb, 0},
223 { "ReadAll", EDBUS_ARGS({"s", "Feed URL"}), NULL, _dbus_feed_item_read_all_cb, 0},
224 { "ClearRead", EDBUS_ARGS({"s", "Feed URL"}), NULL, _dbus_feed_item_clear_read_cb, 0},
225 { "ReadItem", EDBUS_ARGS({"s", "Feed URL"}, {"s", "uuid"}), NULL, _dbus_feed_item_read_cb, 0},
226 { "UnreadItem", EDBUS_ARGS({"s", "Feed URL"}, {"s", "uuid"}), NULL, _dbus_feed_item_unread_cb, 0},
227 {NULL, NULL, NULL, NULL, 0}
228};
229
230/////////////////// SIGNALS ///////////////////////////////////////
231
232
233static const EDBus_Signal feed_signals[] =
234{
235 [ERSSD_SIGNAL_FEED_ADD] = {"Add", EDBUS_ARGS({"s", "Feed URL"}), 0},
236 [ERSSD_SIGNAL_FEED_DEL] = {"Del", EDBUS_ARGS({"s", "Feed URL"}), 0},
237 [ERSSD_SIGNAL_FEED_UPDATED] = {"Updated", EDBUS_ARGS({"s", "Feed URL"}, {"u", "New item count"}), 0},
238 [ERSSD_SIGNAL_FEED_ITEM_READ] = {"ItemRead", EDBUS_ARGS({"s", "Feed URL"}, {"s", "UUID for read item"}), 0},
239 {NULL, NULL, 0}
240};
241
242void
243erssd_dbus_signal_feed_add(const char *url)
244{
245 edbus_service_signal_emit(erssd_feed_iface, ERSSD_SIGNAL_FEED_ADD, url);
246}
247
248void
249erssd_dbus_signal_feed_del(const char *url)
250{
251 edbus_service_signal_emit(erssd_feed_iface, ERSSD_SIGNAL_FEED_DEL, url);
252}
253
254void
255erssd_dbus_signal_feed_item_read(const Rss_Feed *feed, const Azy_Rss_Item *item)
256{
257 edbus_service_signal_emit(erssd_feed_iface, ERSSD_SIGNAL_FEED_ITEM_READ, feed->url, azy_rss_item_uuid_get(item));
258}
259
260void
261erssd_dbus_signal_feed_updated(const Rss_Feed *feed, unsigned int new_items)
262{
263 edbus_service_signal_emit(erssd_feed_iface, ERSSD_SIGNAL_FEED_UPDATED, feed->url, new_items);
264}
265
266////////////// INIT ///////////////////////////////
267static const EDBus_Service_Interface_Desc feed_desc =
268{
269 ERSSD_FEED_INTERFACE, feed_methods, feed_signals, NULL, NULL, NULL
270};
271
272static void
273_nameowned(void *data EINA_UNUSED, const EDBus_Message *msg, EDBus_Pending *pending EINA_UNUSED)
274{
275 unsigned int reply;
276 if (edbus_message_error_get(msg, NULL, NULL))
277 {
278 ERR("name request fail!");
279 return;
280 }
281
282 if (!edbus_message_arguments_get(msg, "u", &reply))
283 {
284 ERR("name request fail #2!");
285 return;
286 }
287
288 if (reply != EDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER)
289 {
290 ERR("org.erssd already in use!");
291 return;
292 }
293}
294
295Eina_Bool
296erssd_dbus_init(void)
297{
298 EDBus_Service_Interface *iface;
299
300 if (!edbus_init()) return EINA_FALSE;
301
302 if (erssd_cf->system)
303 erssd_dbus_conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SYSTEM);
304 else
305 erssd_dbus_conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
306 if (!erssd_dbus_conn) return EINA_FALSE;
307
308 erssd_base_iface = iface = edbus_service_interface_register(erssd_dbus_conn, ERSSD_OBJECT, &base_desc);
309 edbus_name_request(erssd_dbus_conn, ERSSD_INTERFACE, EDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE,
310 _nameowned, iface);
311
312 if (!iface) return EINA_FALSE;
313
314 erssd_feed_iface = edbus_service_interface_register(erssd_dbus_conn, ERSSD_OBJECT, &feed_desc);
315 return EINA_TRUE;
316}
317
318void
319erssd_dbus_shutdown(void)
320{
321 if (erssd_dbus_conn) edbus_connection_unref(erssd_dbus_conn);
322 erssd_dbus_conn = NULL;
323 erssd_base_iface = NULL;
324 edbus_shutdown();
325}
diff --git a/src/bin/eet.c b/src/bin/eet.c
new file mode 100644
index 0000000..ca430a8
--- /dev/null
+++ b/src/bin/eet.c
@@ -0,0 +1,327 @@
1#include "erssd.h"
2
3#include <Eet.h>
4
5static Eet_File *ef_config = NULL;
6static Eet_File *ef_cache = NULL;
7static Eet_Data_Descriptor *feed_edd = NULL;
8static Eet_Data_Descriptor *feed_config_edd = NULL;
9static Eet_Data_Descriptor *feed_cache_edd = NULL;
10
11static Eina_List *cache_queue = NULL;
12
13static void
14_eet_feed_cache_edd_init(void)
15{
16 Eet_Data_Descriptor_Class eddc;
17
18 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Feed_Cache);
19 feed_cache_edd = eet_data_descriptor_stream_new(&eddc);
20
21 EET_DATA_DESCRIPTOR_ADD_LIST(feed_cache_edd, Feed_Cache, "feeds", feeds, azy_rss_item_edd_get());
22}
23
24static void
25_eet_feed_edd_init(void)
26{
27 Eet_Data_Descriptor_Class eddc;
28
29 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Rss_Feed);
30 feed_edd = eet_data_descriptor_stream_new(&eddc);
31
32#define ADD(name, type) \
33 EET_DATA_DESCRIPTOR_ADD_BASIC(feed_edd, Rss_Feed, #name, name, EET_T_##type)
34
35 ADD(url, INLINED_STRING);
36 ADD(update.last, ULONG_LONG);
37 ADD(update.next, ULONG_LONG);
38
39#undef ADD
40}
41
42static void
43_eet_feed_config_edd_init(void)
44{
45 Eet_Data_Descriptor_Class eddc;
46
47 _eet_feed_edd_init();
48 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Feed_Config);
49 feed_config_edd = eet_data_descriptor_stream_new(&eddc);
50
51 EET_DATA_DESCRIPTOR_ADD_BASIC(feed_config_edd, Feed_Config, "version", version, EET_T_UINT);
52 EET_DATA_DESCRIPTOR_ADD_HASH(feed_config_edd, Feed_Config, "feeds", feeds, feed_edd);
53}
54
55static void
56_eet_feed_cache_write(Rss_Feed *feed)
57{
58 Feed_Cache fc;
59 char buf[4096];
60
61 if (!feed->cache_queue) return;
62 if (feed->cache_queue & RSS_FEED_SAVE_MODE_RSS)
63 {
64 if (!eet_data_write(ef_cache, azy_rss_edd_get(), feed->url, feed->rss.rss, 1))
65 ERR("Failed to update feed cache for feed '%s'", feed->url);
66 feed->cache_queue &= ~RSS_FEED_SAVE_MODE_RSS;
67 }
68 if (feed->cache_queue & RSS_FEED_SAVE_MODE_READ)
69 {
70 fc.feeds = feed->rss.read;
71 snprintf(buf, sizeof(buf), "%s/read", feed->url);
72 if (!eet_data_write(ef_cache, feed_cache_edd, buf, &fc, 1))
73 ERR("Failed to update feed read_item cache for feed '%s'", feed->url);
74 feed->cache_queue &= ~RSS_FEED_SAVE_MODE_READ;
75 }
76 if (feed->cache_queue & RSS_FEED_SAVE_MODE_UNREAD)
77 {
78 fc.feeds = feed->rss.unread;
79 snprintf(buf, sizeof(buf), "%s/unread", feed->url);
80 if (!eet_data_write(ef_cache, feed_cache_edd, buf, &fc, 1))
81 ERR("Failed to update feed unread_item cache for feed '%s'", feed->url);
82 feed->cache_queue &= ~RSS_FEED_SAVE_MODE_UNREAD;
83 }
84}
85
86static Eina_Bool
87_eet_feed_cache_read_cb(const Eina_Hash *hash EINA_UNUSED, const char *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED)
88{
89 Azy_Rss *rss;
90 Azy_Rss_Item *item;
91 Eina_List *l;
92 Rss_Feed *feed = data;
93
94 erssd_feed_timer_update(feed, 0.0);
95 feed->rss.items = eina_hash_string_superfast_new(NULL);
96 rss = erssd_util_eet_feed_get(ef_cache, feed->url);
97 if (!rss) return EINA_TRUE;
98 feed->rss.rss = rss;
99 feed->rss.read = erssd_util_eet_feed_read_get(ef_cache, feed->url);
100 feed->rss.unread = erssd_util_eet_feed_unread_get(ef_cache, feed->url);
101 EINA_LIST_FOREACH(feed->rss.read, l, item)
102 eina_hash_direct_add(feed->rss.items, azy_rss_item_uuid_get(item), item);
103 EINA_LIST_FOREACH(feed->rss.unread, l, item)
104 eina_hash_direct_add(feed->rss.items, azy_rss_item_uuid_get(item), item);
105 return EINA_TRUE;
106}
107
108static Eina_Bool
109_eet_feed_config_update(Feed_Config *cf)
110{
111 switch (ERSSD_CONFIG_FEEDS_VERSION - cf->version)
112 {
113 default: break;
114 }
115 return EINA_TRUE;
116}
117
118static Eet_File *
119_eet_feed_file_open(const char *dir, Eina_Bool make_path, Eina_Bool perms, Eina_Bool cache)
120{
121 char buf[PATH_MAX];
122 Eet_File *ef;
123 const char *filename = cache ? ERSSD_CACHE_FEEDS_FILENAME : ERSSD_CONFIG_FEEDS_FILENAME;
124
125 if (make_path)
126 {
127 if (!ecore_file_is_dir(dir))
128 {
129 if (!ecore_file_mkpath(dir))
130 {
131 ERR("Could not create directory for config file: %s", dir);
132 return NULL;
133 }
134 }
135 }
136 snprintf(buf, sizeof(buf), "%s/%s", dir, filename);
137 ef = eet_open(buf, EET_FILE_MODE_READ_WRITE);
138 if (!ef)
139 {
140 ERR("Could not open feed config file: %s", buf);
141 return NULL;
142 }
143
144 /* only set perms on new files */
145 if (perms && (!eet_num_entries(ef)))
146 {
147 /* seems weird that we don't have anything for this in EFL yet... */
148 errno = 0;
149 /* set perms to allow read by others: eet default perms do not allow this */
150 if (chmod(eet_file_get(ef), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))
151 ERR("Could not change permissions on feed config file: %s", strerror(errno));
152 }
153 return ef;
154}
155
156Eina_Bool
157erssd_eet_init(void)
158{
159 Feed_Config *cf;
160 const char *dir;
161
162 eet_init();
163
164 if (erssd_cf->cfg_dir)
165 {
166 ef_config = _eet_feed_file_open(erssd_cf->cfg_dir, !erssd_cf->system, erssd_cf->system, EINA_FALSE);
167 if (!ef_config) return EINA_FALSE;
168 ef_cache = _eet_feed_file_open(erssd_cf->cfg_dir, !erssd_cf->system, erssd_cf->system, EINA_TRUE);
169 if (!ef_cache) return EINA_FALSE;
170 }
171 else
172 {
173 if (erssd_cf->system)
174 {
175 dir = "/etc/erssd";
176 }
177 else
178 {
179 char buf[PATH_MAX];
180
181 dir = efreet_config_home_get();
182 if (dir)
183 snprintf(buf, sizeof(buf), "%s/erssd", dir);
184 else
185 snprintf(buf, sizeof(buf), "%s/.config/erssd", getenv("HOME"));
186 dir = buf;
187 }
188 /* if we're in autodetection system mode, we avoid creating directories
189 * to lessen the chance of fucking something up
190 */
191 ef_config = _eet_feed_file_open(dir, !erssd_cf->system, erssd_cf->system, EINA_FALSE);
192 if (!ef_config) return EINA_FALSE;
193 ef_cache = _eet_feed_file_open(dir, !erssd_cf->system, erssd_cf->system, EINA_TRUE);
194 if (!ef_cache) return EINA_FALSE;
195 }
196
197 _eet_feed_config_edd_init();
198 _eet_feed_cache_edd_init();
199 cf = eet_data_read(ef_config, feed_config_edd, ERSSD_CONFIG_FEEDS_KEY);
200 if (cf)
201 {
202 if (cf->version < ERSSD_CONFIG_FEEDS_VERSION)
203 {
204 if (!_eet_feed_config_update(cf))
205 {
206 free(cf);
207 ERR("Failed to upgrade feed config! Submit a bug report!");
208 return EINA_FALSE;
209 }
210 }
211 else if (cf->version > ERSSD_CONFIG_FEEDS_VERSION)
212 {
213 /* TODO: log/notify user that their shit is out of date and they should upgrade */
214 }
215 erssd_feeds = cf->feeds;
216 free(cf);
217 if (!erssd_feeds) return EINA_TRUE;
218 eina_hash_free_cb_set(erssd_feeds, (Eina_Free_Cb)erssd_feed_free);
219 eina_hash_foreach(erssd_feeds, (Eina_Hash_Foreach)_eet_feed_cache_read_cb, NULL);
220 }
221 return EINA_TRUE;
222}
223
224void
225erssd_eet_shutdown(void)
226{
227 if (ef_config) eet_close(ef_config);
228 if (ef_cache) eet_close(ef_cache);
229 eina_list_free(cache_queue);
230 eet_shutdown();
231}
232
233void
234erssd_eet_cache_save_queue(Rss_Feed *feed, double now, Rss_Feed_Save_Mode mode)
235{
236 long t;
237 Rss_Feed *f;
238
239 if (!now) now = ecore_time_unix_get();
240 t = lround(now);
241 feed->cache_queue |= mode;
242 EINA_INLIST_FOREACH(erssd_feed_list, f)
243 {
244 /* TODO: this can probably be batched even more to
245 * account for read flags being set and such */
246 if (f->update.next - t <= ERSSD_CONFIG_SAVE_THRESHOLD)
247 {
248 if (!feed->cache_queue)
249 cache_queue = eina_list_append(cache_queue, feed);
250 return;
251 }
252 break;
253 }
254 _eet_feed_cache_write(feed);
255 EINA_LIST_FREE(cache_queue, f)
256 _eet_feed_cache_write(f);
257 eet_sync(ef_cache);
258}
259
260void
261erssd_eet_cache_save_unqueue(Rss_Feed *feed)
262{
263 cache_queue = eina_list_remove(cache_queue, feed);
264 feed->cache_queue = 0;
265}
266
267void
268erssd_eet_config_save(double now)
269{
270 Feed_Config cf;
271 Rss_Feed *feed;
272 long t;
273
274 if (!now) now = ecore_time_unix_get();
275 t = lround(now);
276 EINA_INLIST_FOREACH(erssd_feed_list, feed)
277 {
278 if (feed->update.next - t <= ERSSD_CONFIG_SAVE_THRESHOLD) return;
279 break;
280 }
281 cf.feeds = erssd_feeds;
282 cf.version = ERSSD_CONFIG_FEEDS_VERSION;
283 /* here we rely on the fact that we are not going to be stupid and call this function unnecessarily,
284 * so we should only write+sync after we have adequately batched those operations
285 */
286 if (eet_data_write(ef_config, feed_config_edd, ERSSD_CONFIG_FEEDS_KEY, &cf, 1))
287 eet_sync(ef_config);
288 else
289 ERR("Failed to write feed config!");
290}
291
292void
293erssd_eet_feed_del(const char *url)
294{
295 char buf[4096];
296 Eina_Stringshare *f;
297 char *p;
298
299 eet_delete(ef_cache, url);
300 snprintf(buf, sizeof(buf), "%s/read", url);
301 eet_delete(ef_cache, buf);
302 snprintf(buf, sizeof(buf), "%s/unread", url);
303 eet_delete(ef_cache, buf);
304
305 if (eet_num_entries(ef_cache)) return;
306 /* work around weird eet bug when last key gets deleted... */
307 f = eina_stringshare_ref(eet_file_get(ef_cache));
308 eet_close(ef_cache);
309 ecore_file_remove(f);
310 snprintf(buf, sizeof(buf), "%s", f);
311 p = strrchr(buf, '/');
312 if (p) p[0] = 0;
313 ef_cache = _eet_feed_file_open(buf, !erssd_cf->system, erssd_cf->system, EINA_TRUE);
314 eina_stringshare_del(f);
315}
316
317Eina_Stringshare *
318erssd_eet_feed_cfgfile_get(void)
319{
320 return eet_file_get(ef_config);
321}
322
323Eina_Stringshare *
324erssd_eet_feed_cachefile_get(void)
325{
326 return eet_file_get(ef_cache);
327}
diff --git a/src/bin/erssd.h b/src/bin/erssd.h
new file mode 100644
index 0000000..a35eb37
--- /dev/null
+++ b/src/bin/erssd.h
@@ -0,0 +1,109 @@
1#ifndef ERSSD_H
2#define ERSSD_H
3
4#include "erssd_private.h"
5#include <Ecore.h>
6#include <Ecore_File.h>
7#include <Efreet.h>
8#include <math.h>
9
10#define DBG(...) EINA_LOG_DOM_DBG(erssd_log_dom, __VA_ARGS__)
11#define INF(...) EINA_LOG_DOM_INFO(erssd_log_dom, __VA_ARGS__)
12#define WRN(...) EINA_LOG_DOM_WARN(erssd_log_dom, __VA_ARGS__)
13#define ERR(...) EINA_LOG_DOM_ERR(erssd_log_dom, __VA_ARGS__)
14#define CRI(...) EINA_LOG_DOM_CRIT(erssd_log_dom, __VA_ARGS__)
15
16#define ERSSD_CONFIG_FEEDS_VERSION 1
17#define ERSSD_CACHE_FEEDS_VERSION 1
18
19/* this is the fuzziness for batching saves to avoid excessive disk writing:
20 *
21 * if a config save is requested and there is another feed timer set to expire
22 * within this many seconds, we wait for the next feed before saving
23 */
24#define ERSSD_CONFIG_SAVE_THRESHOLD 30
25
26/* this is the default filename for server configuration */
27#define ERSSD_CONFIG_FILENAME "erssd.conf"
28
29typedef enum
30{
31 RSS_FEED_SAVE_MODE_RSS = (1 << 0),
32 RSS_FEED_SAVE_MODE_READ = (1 << 1),
33 RSS_FEED_SAVE_MODE_UNREAD = (1 << 2)
34} Rss_Feed_Save_Mode;
35
36typedef struct Config_File //global
37{
38 char *cfg_file; //plaintext server config file
39 char *cfg_dir; //dir containing eet files
40 char *pid_file; //where to create pidfile
41 Eina_Log_Level log_level;
42 unsigned int feed_interval; //base interval on which to refresh
43 Eina_Bool daemonize : 1; //whether to daemonize
44 Eina_Bool system : 1; //whether to run system-wide
45 Eina_Bool offline : 1; //whether to be "offline"
46} Config_File;
47
48typedef struct Rss_Feed
49{
50 EINA_INLIST;
51 Eina_Stringshare *url;
52 struct
53 {
54 time_t next; //absolute time at which to refresh
55 time_t last; //absolute time which feed was last successfully fetched
56 } update;
57 struct
58 {
59 Azy_Rss *rss; //latest rss CACHEFILE
60 Eina_List *read; //Azy_Rss_Item CACHEFILE
61 Eina_List *unread; //Azy_Rss_Item CACHEFILE
62 Eina_Hash *items; //uuid:item NOT SAVED
63 } rss;
64 Azy_Client *cli;
65 Ecore_Timer *timer;
66 unsigned int cache_queue; //when feed has a cache write queued, Rss_Feed_Save_Mode
67 Eina_Bool in_list : 1; //feed is in erssd_feed_list
68 Eina_Bool first_fetch : 1; //feed is being fetched for the first time
69} Rss_Feed;
70
71extern int erssd_log_dom;
72extern Config_File *erssd_cf;
73extern Eina_Hash *erssd_feeds; //url:Rss_Feed
74extern Eina_Inlist *erssd_feed_list; //feeds that have timers
75
76void erssd_exit(int code);
77
78void erssd_getopt_parse(int argc, char *argv[], Config_File *cf, Eina_List **add, Eina_List **del);
79
80void erssd_config_file_read(const char *file);
81
82Eina_Bool erssd_eet_init(void);
83void erssd_eet_shutdown(void);
84void erssd_eet_config_save(double now);
85void erssd_eet_cache_save_queue(Rss_Feed *feed, double now, Rss_Feed_Save_Mode mode);
86void erssd_eet_cache_save_unqueue(Rss_Feed *feed);
87void erssd_eet_feed_del(const char *url);
88Eina_Stringshare *erssd_eet_feed_cfgfile_get(void);
89Eina_Stringshare *erssd_eet_feed_cachefile_get(void);
90
91Eina_Bool erssd_feed_fetch_cb_setup(Rss_Feed *feed);
92Eina_Bool erssd_feed_add_by_url(const char *url);
93Eina_Bool erssd_feed_del_by_url(const char *url);
94void erssd_feed_free(Rss_Feed *feed);
95void erssd_feed_clear_read(Rss_Feed *feed);
96void erssd_feed_read(Rss_Feed *feed);
97void erssd_feed_item_add(Rss_Feed *feed, const Azy_Rss_Item *item);
98Eina_Bool erssd_feed_item_read_set(Rss_Feed *feed, const char *uuid, Eina_Bool is_read);
99void erssd_feed_cache_update(Rss_Feed *feed, double now);
100void erssd_feed_timer_update(Rss_Feed *feed, double now);
101
102void erssd_dbus_signal_feed_add(const char *url);
103void erssd_dbus_signal_feed_del(const char *url);
104void erssd_dbus_signal_feed_item_read(const Rss_Feed *feed, const Azy_Rss_Item *item);
105void erssd_dbus_signal_feed_updated(const Rss_Feed *feed, unsigned int new_items);
106Eina_Bool erssd_dbus_init(void);
107void erssd_dbus_shutdown(void);
108
109#endif
diff --git a/src/bin/feed.c b/src/bin/feed.c
new file mode 100644
index 0000000..7194a0f
--- /dev/null
+++ b/src/bin/feed.c
@@ -0,0 +1,465 @@
1#include "erssd.h"
2
3static Eina_Error
4_feed_transfer_done_cb(Azy_Client *cli, Azy_Content *ret_content, Azy_Rss *rss)
5{
6 Eina_Bool is_rss;
7 Rss_Feed *feed;
8 double now = 0;
9
10 /* FIXME: check http return code and redirect */
11
12 azy_content_return_get(ret_content, &is_rss);
13 feed = azy_client_data_get(cli);
14 azy_client_free(cli);
15 feed->cli = NULL;
16 /* FIXME: handle failure */
17 /* ALSO FIXME: this return is stupid */
18 if (!is_rss) return AZY_ERROR_NONE;
19 now = ecore_time_unix_get();
20 feed->update.last = lround(now);
21 feed->update.next = 0;
22 if (feed->rss.rss)
23 {
24 time_t t;
25
26 /* feed hasn't been changed since last fetch:
27 * [] skip all caching steps
28 * [] go directly to setting up next timer
29 */
30 t = azy_rss_updated_get(feed->rss.rss);
31 if (t && (t == azy_rss_updated_get(rss)))
32 {
33 erssd_dbus_signal_feed_updated(feed, 0);
34 goto out;
35 }
36 azy_rss_free(feed->rss.rss);
37 }
38 if (feed->first_fetch)
39 erssd_dbus_signal_feed_add(feed->url);
40 feed->rss.rss = rss;
41
42 erssd_feed_cache_update(feed, now);
43out:
44 erssd_feed_timer_update(feed, now);
45 return AZY_ERROR_NONE;
46}
47
48static Eina_Bool
49_feed_timer_cb(Rss_Feed *feed)
50{
51 feed->timer = NULL;
52 /* FIXME: how to handle offline mode... */
53 feed->cli = azy_client_util_connect(feed->url);
54 EINA_SAFETY_ON_NULL_RETURN_VAL(feed->cli, EINA_FALSE);
55 azy_client_blank(feed->cli, AZY_NET_TYPE_GET, NULL, NULL, NULL);
56 if (feed->cli)
57 erssd_feed_fetch_cb_setup(feed);
58 return EINA_FALSE;
59}
60
61static void
62_feed_list_merge(Rss_Feed *feed, Eina_List *items, unsigned int *num)
63{
64 Eina_List *ul;
65 Azy_Rss_Item *i, *r, *u;
66 Eina_Bool read_done = EINA_FALSE, unread_done = EINA_FALSE;
67 time_t rt, ut;
68 Eina_Stringshare *title, *desc, *rtitle, *rdesc, *utitle, *udesc;
69
70 r = eina_list_data_get(feed->rss.read);
71 if (r)
72 {
73 rt = azy_rss_item_pubdate_get(r);
74 rtitle = azy_rss_item_title_get(r);
75 rdesc = azy_rss_item_desc_get(r);
76 }
77 else
78 read_done = EINA_TRUE;
79
80 ul = feed->rss.unread;
81 u = eina_list_data_get(feed->rss.unread);
82 if (u)
83 {
84 ut = azy_rss_item_pubdate_get(u);
85 utitle = azy_rss_item_title_get(u);
86 udesc = azy_rss_item_desc_get(u);
87 }
88 else
89 unread_done = EINA_TRUE;
90
91 *num = 0;
92 EINA_LIST_FREE(items, i)
93 {
94 time_t t;
95
96 t = azy_rss_item_pubdate_get(i);
97 title = azy_rss_item_title_get(i);
98 desc = azy_rss_item_desc_get(i);
99 if (!read_done)
100 {
101 /* if current item matches the first previously-read item:
102 * [] set both done flags
103 * [] stop matching
104 */
105 if (rt && t)
106 {
107 if (t < rt)
108 {
109 read_done = unread_done = EINA_TRUE;
110 }
111 }
112 if (rt == t)
113 {
114 if (
115 ((title || rtitle) && (title == rtitle)) ||
116 ((desc || rdesc) && (desc == rdesc))
117 )
118 {
119 read_done = unread_done = EINA_TRUE;
120 }
121 }
122 }
123 if (!unread_done)
124 {
125 if (ut && t)
126 {
127 if (t > ut)
128 {
129 /* an item that's newer than our most-recent cached unread item */
130 feed->rss.unread = eina_list_prepend_relative_list(feed->rss.unread, i, ul);
131 erssd_feed_item_add(feed, i);
132 (*num)++;
133 continue;
134 }
135 }
136 if (ut == t)
137 {
138 if (
139 ((title || utitle) && (title == utitle)) ||
140 ((desc || udesc) && (desc == udesc))
141 )
142 {
143 read_done = unread_done = EINA_TRUE;
144 }
145 }
146 }
147 azy_rss_item_free(i);
148 }
149}
150
151static int
152_feed_list_sort_cb(const Rss_Feed *a, const Rss_Feed *b)
153{
154 if (a->update.next < b->update.next) return -1;
155 if (a->update.next > b->update.next) return 1;
156 return 0;
157}
158
159static int
160_feed_item_list_sort_cb(const Azy_Rss_Item *a, const Azy_Rss_Item *b)
161{
162 time_t ta, tb;
163
164 ta = azy_rss_item_pubdate_get(a);
165 tb = azy_rss_item_pubdate_get(b);
166 if (ta < tb) return -1;
167 if (ta > tb) return 1;
168 return 0;
169}
170
171static void
172_feed_timer_update(Rss_Feed *feed, double interval)
173{
174 if (interval < 0.0 + __DBL_EPSILON__)
175 {
176 INF("NEXT UPDATE NOW: %s", feed->url);
177 _feed_timer_cb(feed);
178 return;
179 }
180 if (feed->timer)
181 {
182 ecore_timer_interval_set(feed->timer, interval);
183 ecore_timer_reset(feed->timer);
184 }
185 else
186 feed->timer = ecore_timer_add(interval, (Ecore_Task_Cb)_feed_timer_cb, feed);
187 if (eina_log_domain_level_check(erssd_log_dom, EINA_LOG_LEVEL_INFO))
188 {
189 char buf[1024];
190 struct tm *t;
191
192 t = localtime(&feed->update.next);
193 strftime(buf, sizeof(buf), "%FT%TZ", t);
194 INF("NEXT UPDATE %s: %s", buf, feed->url);
195 }
196 erssd_feed_list = eina_inlist_sorted_insert(erssd_feed_list, EINA_INLIST_GET(feed), (Eina_Compare_Cb)_feed_list_sort_cb);
197 feed->in_list = 1;
198}
199
200Eina_Bool
201erssd_feed_fetch_cb_setup(Rss_Feed *feed)
202{
203 Azy_Client_Call_Id id;
204
205 if (!feed->cli) return EINA_FALSE;
206 id = azy_client_current(feed->cli);
207 if (!id) return EINA_FALSE;
208 INF("updating feed: %s", feed->url);
209 azy_client_data_set(feed->cli, feed);
210 azy_client_callback_set(feed->cli, id, (Azy_Client_Transfer_Complete_Cb)_feed_transfer_done_cb);
211 return EINA_TRUE;
212}
213
214Eina_Bool
215erssd_feed_add_by_url(const char *url)
216{
217 Rss_Feed *feed;
218
219 if (eina_hash_find(erssd_feeds, url)) return EINA_FALSE;
220 INF("Adding feed: %s", url);
221 feed = calloc(1, sizeof(Rss_Feed));
222 feed->rss.items = eina_hash_string_superfast_new(NULL);
223 feed->url = eina_stringshare_add(url);
224 eina_hash_direct_add(erssd_feeds, feed->url, feed);
225 if (erssd_cf->offline) return EINA_TRUE;
226 feed->cli = azy_client_util_connect(url);
227 azy_client_blank(feed->cli, AZY_NET_TYPE_GET, NULL, NULL, NULL);
228 if (erssd_feed_fetch_cb_setup(feed))
229 feed->first_fetch = 1;
230 return EINA_TRUE;
231}
232
233Eina_Bool
234erssd_feed_del_by_url(const char *url)
235{
236 Eina_Bool ret;
237 if ((!url) || (!url[0])) return EINA_FALSE;
238 INF("Deleting feed: %s", url);
239 ret = eina_hash_del_by_key(erssd_feeds, url);
240 if (ret)
241 {
242 erssd_eet_feed_del(url);
243 erssd_dbus_signal_feed_del(url);
244 erssd_eet_config_save(0);
245 }
246 return ret;
247}
248
249void
250erssd_feed_free(Rss_Feed *feed)
251{
252 if (!feed) return;
253 if (feed->in_list)
254 erssd_feed_list = eina_inlist_remove(erssd_feed_list, EINA_INLIST_GET(feed));
255 if (feed->cache_queue)
256 erssd_eet_cache_save_unqueue(feed);
257 eina_list_free(feed->rss.read);
258 eina_list_free(feed->rss.unread);
259 eina_hash_free(feed->rss.items);
260 azy_rss_free(feed->rss.rss);
261 eina_stringshare_del(feed->url);
262 if (feed->timer) ecore_timer_del(feed->timer);
263 azy_client_free(feed->cli);
264 free(feed);
265}
266
267void
268erssd_feed_cache_update(Rss_Feed *feed, double now)
269{
270 unsigned int num, flags = RSS_FEED_SAVE_MODE_RSS;
271 Eina_List *items;
272
273 items = azy_rss_items_steal(feed->rss.rss);
274 if (items)
275 {
276 if (feed->rss.unread)
277 {
278 _feed_list_merge(feed, items, &num);
279 if (num) flags |= RSS_FEED_SAVE_MODE_UNREAD;
280 INF("CACHE UPDATE: %s - %u NEW", feed->url, num);
281 }
282 else
283 {
284 Eina_List *l;
285 Azy_Rss_Item *item;
286
287 feed->rss.unread = items;
288 EINA_LIST_FOREACH(items, l, item)
289 erssd_feed_item_add(feed, item);
290 flags |= RSS_FEED_SAVE_MODE_UNREAD;
291 num = eina_list_count(items);
292 INF("CACHE UPDATE: %s - %u NEW", feed->url, num);
293 }
294 }
295 erssd_dbus_signal_feed_updated(feed, num);
296 erssd_eet_cache_save_queue(feed, now, flags);
297}
298
299void
300erssd_feed_item_add(Rss_Feed *feed, const Azy_Rss_Item *item)
301{
302 eina_hash_direct_add(feed->rss.items, azy_rss_item_uuid_get(item), item);
303}
304
305void
306erssd_feed_item_del_by_uuid(Rss_Feed *feed, const char *uuid)
307{
308 Azy_Rss_Item *item;
309
310 item = eina_hash_set(feed->rss.items, uuid, NULL);
311 if (!item) return;
312 /* FIXME: slow...maybe switch to rbtree */
313 if (azy_rss_item_read_get(item))
314 feed->rss.read = eina_list_remove(feed->rss.read, item);
315 else
316 feed->rss.unread = eina_list_remove(feed->rss.unread, item);
317 azy_rss_item_free(item);
318}
319
320void
321erssd_feed_read(Rss_Feed *feed)
322{
323 Azy_Rss_Item *item;
324
325 EINA_LIST_FREE(feed->rss.unread, item)
326 {
327 azy_rss_item_read_set(item, EINA_TRUE);
328 feed->rss.read = eina_list_sorted_insert(feed->rss.read, (Eina_Compare_Cb)_feed_item_list_sort_cb, item);
329 }
330}
331
332void
333erssd_feed_clear_read(Rss_Feed *feed)
334{
335 Azy_Rss_Item *item;
336
337 EINA_LIST_FREE(feed->rss.read, item)
338 {
339 eina_hash_del_by_key(feed->rss.items, azy_rss_item_uuid_get(item));
340 azy_rss_item_free(item);
341 }
342
343}
344
345Eina_Bool
346erssd_feed_item_read_set(Rss_Feed *feed, const char *uuid, Eina_Bool is_read)
347{
348 Azy_Rss_Item *item;
349
350 item = eina_hash_find(feed->rss.items, uuid);
351 if (!item) return EINA_FALSE;
352 is_read = !!is_read;
353 if (is_read == azy_rss_item_read_get(item)) return EINA_TRUE;
354 /* FIXME: slow...maybe switch to rbtree */
355 if (!is_read)
356 {
357 feed->rss.read = eina_list_remove(feed->rss.read, item);
358 feed->rss.unread = eina_list_sorted_insert(feed->rss.unread, (Eina_Compare_Cb)_feed_item_list_sort_cb, item);
359 }
360 else
361 {
362 feed->rss.unread = eina_list_remove(feed->rss.unread, item);
363 feed->rss.read = eina_list_sorted_insert(feed->rss.read, (Eina_Compare_Cb)_feed_item_list_sort_cb, item);
364 }
365 azy_rss_item_read_set(item, is_read);
366 return EINA_TRUE;
367}
368
369void
370erssd_feed_timer_update(Rss_Feed *feed, double now)
371{
372 unsigned int ttl;
373 time_t next, snext;
374 struct tm *tnext;
375 double interval;
376
377#define MINUTES_IN_DAY (24 * 60)
378
379 if (feed->in_list)
380 {
381 erssd_feed_list = eina_inlist_remove(erssd_feed_list, EINA_INLIST_GET(feed));
382 feed->in_list = 0;
383 }
384 if (!now) now = ecore_time_unix_get();
385 if ((!feed->rss.rss) || (feed->update.next && (feed->update.next < now)))
386 {
387 /* if next update time has not passed yet, reuse that time and ignore all this */
388 _feed_timer_update(feed, feed->update.next - lround(now));
389 return;
390 }
391
392 if (!azy_rss_atom_get(feed->rss.rss))
393 ttl = azy_rss_ttl_get(feed->rss.rss);
394 if (!ttl) ttl = erssd_cf->feed_interval ?: 15; //start at 15 mins if base interval not configured
395 ttl *= 60; // ttl is in minutes
396 /* base for next fetch is update.last + ttl */
397 snext = next = feed->update.last + ttl;
398 tnext = localtime(&next);
399 if (!azy_rss_atom_get(feed->rss.rss))
400 {
401 unsigned int days, hours;
402 int x;
403
404 days = azy_rss_skipdays_get(feed->rss.rss);
405 if (days)
406 {
407 for (x = tnext->tm_wday; x < tnext->tm_wday + 7; x++)
408 {
409 /* if next-day is not a skip day */
410 if (!(days & (1 << (x % 7)))) break;
411 }
412 if (!(days & (1 << (x % 7))))
413 {
414 x -= tnext->tm_wday;
415 /* add in missing skipday minutes */
416 next += (x * MINUTES_IN_DAY);
417 }
418 }
419 hours = azy_rss_skiphours_get(feed->rss.rss);
420 if (hours)
421 {
422 int max;
423
424 if (snext == next)
425 x = tnext->tm_hour;
426 else
427 x = 0;
428 max = x + 24;
429 for (; x < max; x++)
430 {
431 /* if next-hour is not a skip hour */
432 if (!(hours & (1 << (x % 24)))) break;
433 }
434 if (!(hours & (1 << (x % 24))))
435 {
436 x %= 24;
437 /* subtract unneeded minutes */
438 next -= tnext->tm_min;
439 if (snext == next)
440 {
441 /* no skipday adjustment, so we're only going to be going forward */
442 if (x < tnext->tm_hour)
443 next += ((24 - tnext->tm_hour) + x) * 60;
444 else
445 next += (x - tnext->tm_hour) * 60;
446 }
447 else
448 {
449 /* if day has changed, move as close to midnight as possible */
450 if (x < tnext->tm_hour)
451 next -= (tnext->tm_hour - x) * 60;
452 else
453 next += (x - tnext->tm_hour) * 60;
454 }
455 }
456 }
457 }
458 /* ensure we don't violate ttl/delay */
459 if (next < snext) next = snext;
460 feed->update.next = next;
461
462 interval = (double)next - now;
463 erssd_eet_config_save(now);
464 _feed_timer_update(feed, interval);
465}
diff --git a/src/bin/getopt.c b/src/bin/getopt.c
new file mode 100644
index 0000000..38dc5a5
--- /dev/null
+++ b/src/bin/getopt.c
@@ -0,0 +1,74 @@
1#include "erssd.h"
2#include <Ecore_Getopt.h>
3
4static const Ecore_Getopt main_opts =
5{
6 "erssd",
7 "erssd [command [options]]",
8 "1",
9 "(C) 2013 Mike Blumenkrantz",
10 "LGPL-2",
11 "RSS Daemon"
12 ,
13 EINA_TRUE, /* strict checking; fail on errors */
14 {
15 ECORE_GETOPT_STORE_TRUE('v', "verbose", "Print runtime logs"),
16 ECORE_GETOPT_STORE_TRUE('q', "quiet", "Print only requested info, no formatting"),
17 ECORE_GETOPT_STORE_TRUE('n', "nodaemon", "Do not daemonize"),
18 ECORE_GETOPT_STORE_STR('c', "cfgfile", "Use config file at this location"),
19 ECORE_GETOPT_STORE_STR('d', "cfgdir", "Use this directory to save encoded feed data"),
20 ECORE_GETOPT_STORE_STR('p', "pidfile", "Create pidfile here"),
21 ECORE_GETOPT_APPEND_METAVAR('a', "add-feeds", "Add feeds for listed URLS",
22 "STRING", ECORE_GETOPT_TYPE_STR),
23 ECORE_GETOPT_APPEND_METAVAR('d', "del-feeds", "Delete feeds for listed URLS (processed after adds)",
24 "STRING", ECORE_GETOPT_TYPE_STR),
25 ECORE_GETOPT_VERSION('V', "version"),
26 ECORE_GETOPT_COPYRIGHT('R', "copyright"),
27 ECORE_GETOPT_LICENSE('L', "license"),
28 ECORE_GETOPT_HELP('h', "help"),
29 ECORE_GETOPT_SENTINEL
30 }
31};
32
33void
34erssd_getopt_parse(int argc, char *argv[], Config_File *cf, Eina_List **add, Eina_List **del)
35{
36 Eina_Bool exit_option = EINA_FALSE;
37 Eina_Bool quiet, verbose, nodaemon;
38 int args;
39
40 cf->cfg_file = NULL;
41 verbose = quiet = nodaemon = EINA_FALSE;
42
43 Ecore_Getopt_Value main_values[] =
44 {
45 ECORE_GETOPT_VALUE_BOOL(verbose),
46 ECORE_GETOPT_VALUE_BOOL(quiet),
47 ECORE_GETOPT_VALUE_BOOL(nodaemon),
48 ECORE_GETOPT_VALUE_STR(cf->cfg_file),
49 ECORE_GETOPT_VALUE_STR(cf->cfg_dir),
50 ECORE_GETOPT_VALUE_STR(cf->pid_file),
51 ECORE_GETOPT_VALUE_LIST(*add),
52 ECORE_GETOPT_VALUE_LIST(*del),
53 ECORE_GETOPT_VALUE_BOOL(exit_option),
54 ECORE_GETOPT_VALUE_BOOL(exit_option),
55 ECORE_GETOPT_VALUE_BOOL(exit_option),
56 ECORE_GETOPT_VALUE_BOOL(exit_option)
57 };
58
59 ecore_app_args_set(argc, (const char **)argv);
60 args = ecore_getopt_parse(&main_opts, main_values, argc, argv);
61
62 if (exit_option) exit(0);
63
64 if (args < 0)
65 {
66 ERR("Invalid args specified!");
67 ecore_getopt_help(stderr, &main_opts);
68 exit(1);
69 }
70
71 if (quiet) cf->log_level = EINA_LOG_LEVEL_UNKNOWN;
72 if (verbose) cf->log_level = EINA_LOG_LEVEL_DBG;
73 if (nodaemon) cf->daemonize = 0;
74}
diff --git a/src/bin/main.c b/src/bin/main.c
new file mode 100644
index 0000000..429f22f
--- /dev/null
+++ b/src/bin/main.c
@@ -0,0 +1,115 @@
1#include "erssd.h"
2#include "Zshare.h"
3
4int erssd_log_dom = -1;
5Config_File *erssd_cf = NULL;
6Eina_Hash *erssd_feeds = NULL;
7Eina_Inlist *erssd_feed_list = NULL;
8
9void
10erssd_exit(int code)
11{
12 INF("shutting down");
13 erssd_dbus_shutdown();
14 erssd_eet_shutdown();
15 INF("deleting pid");
16 zshare_pid_delete();
17 exit(code);
18}
19
20int
21main(int argc, char *argv[])
22{
23 const char *dir, *pid;
24 char *str;
25 char buf[PATH_MAX];
26 Config_File cf;
27 Eina_List *add = NULL, *del = NULL;
28
29 eina_init();
30 efreet_init();
31 azy_init();
32 azy_rpc_log_enable();
33
34 erssd_log_dom = eina_log_domain_register("erssd", EINA_COLOR_CYAN);
35
36 erssd_cf = &cf;
37 memset(&cf, 0, sizeof(Config_File));
38 erssd_cf->log_level = 10;
39 erssd_cf->daemonize = 1;
40
41 erssd_getopt_parse(argc, argv, erssd_cf, &add, &del);
42 erssd_config_file_read(erssd_cf->cfg_file);
43
44 if (erssd_cf->log_level == 10) erssd_cf->log_level = EINA_LOG_LEVEL_WARN;
45 eina_log_domain_level_set("erssd", erssd_cf->log_level);
46
47 if (!erssd_util_init()) exit(1);
48 if (!erssd_eet_init()) exit(1);
49 if (!erssd_dbus_init()) exit(1);
50
51#if (EFREET_VERSION_MAJOR > 1) || (EFREET_VERSION_MINOR >= 8)
52 dir = efreet_runtime_dir_get();
53#else
54 dir = getenv("XDG_RUNTIME_DIR");
55#endif
56 if (!dir)
57 {
58 if (erssd_cf->system) dir = "/var/run";
59 else dir = getenv("HOME");
60 }
61
62 pid = erssd_cf->pid_file;
63 if (!pid)
64 {
65 snprintf(buf, sizeof(buf), "%s/erssd.pid", dir);
66 pid = buf;
67 }
68 if (zshare_pid_check(pid))
69 {
70 ERR("Daemon appears to already be running; pid at %s", pid);
71 exit(1);
72 }
73
74 if (erssd_cf->daemonize)
75 {
76 if (!zshare_daemon_detach(1))
77 exit(1);
78 }
79
80 switch (zshare_pid_create(pid))
81 {
82 case -1:
83 ERR("Could not write pid file. Check permissions and system status.");
84 exit(1);
85 case 0:
86 ERR("Could not write pid file. Daemon already running or previously exited uncleanly.");
87 exit(1);
88 default: break;
89 }
90 INF("created pidfile: %s", pid);
91
92 if (erssd_cf->daemonize && (!zshare_daemon_closefds(0)))
93 {
94 erssd_exit(1);
95 }
96
97 if (!erssd_feeds)
98 erssd_feeds = eina_hash_string_superfast_new((Eina_Free_Cb)erssd_feed_free);
99
100 EINA_LIST_FREE(add, str)
101 {
102 erssd_feed_add_by_url(str);
103 free(str);
104 }
105 EINA_LIST_FREE(del, str)
106 {
107 erssd_feed_del_by_url(str);
108 free(str);
109 }
110
111 ecore_main_loop_begin();
112 erssd_exit(0);
113
114 return 0;
115}
diff --git a/src/bin/zshare_config.c b/src/bin/zshare_config.c
new file mode 100644
index 0000000..91ec460
--- /dev/null
+++ b/src/bin/zshare_config.c
@@ -0,0 +1,156 @@
1/* ZSHARE
2 * Copyright (C) 2011 Mike Blumenkrantz, Zentific LLC
3 *
4 * All rights reserved.
5 * Use is subject to license terms.
6 *
7 * Please visit http://zentific.com for news and updates
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 */
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <sys/mman.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <unistd.h>
27#include "Zshare.h"
28#include <Eina.h>
29#include "erssd.h"
30
31/*
32 * internal function
33 */
34static char *
35strnchr(const char *s,
36 size_t len,
37 int c)
38{
39 if ((!s) || (!len)) return NULL;
40
41 do
42 {
43 if (*s == c) return (char *)s;
44 if (!(*s)) return NULL;
45 s++;
46 } while (--len);
47 return NULL;
48}
49
50/**
51 * @brief Parse a config file, calling a callback for each valid line
52 * @param file The file to parse
53 * @param cb The config parsing callback to call for each valid line
54 * @param data Additional data to send to @p cb
55 * @return 0 on failure, 1 on success
56 * @note Invalid lines will automatically be logged with ERR() if logging is active, or stderr if not
57 */
58int
59zshare_config_parse(const char *file,
60 Zshare_Config_Parse_Cb cb,
61 void *data)
62{
63 char name[1024], value[1024];
64 Eina_File *f;
65 size_t size;
66 const char *newline, *pos;
67 int lineno = 0;
68 char *m;
69
70 f = eina_file_open(file, EINA_FALSE);
71 if (!f) return 0;
72 size = eina_file_size_get(f);
73 if (size < 5) goto error;
74 m = eina_file_map_all(f, EINA_FILE_WILLNEED);
75 if (!m) goto error;
76 for (pos = m, newline = strchr(m, '\n');
77 newline && ((unsigned int)(newline - m + 1) <= size);
78 pos = newline + 1, newline = strchr(newline + 1, '\n')
79 )
80 {
81 const char *eq, *hash;
82 const char *dq, *dqq, *sq, *sqq;
83 // Keep track of line numbers for error reporting
84 lineno++;
85
86 // Make sure that there is a variable assignment in the line
87 eq = strnchr(pos, newline - pos, '=');
88 if (!eq) //line that doesn't set variable
89 continue;
90
91 hash = strnchr(pos, eq - pos, '#');
92 if (hash) //commented line
93 continue;
94
95 sscanf(pos, "%[^=]=%[^\n#]", name, value);
96 sq = strchr(value, '\'');
97 sqq = strrchr(value, '\'');
98 dq = strchr(value, '"');
99 dqq = strrchr(value, '"');
100 if ((!sq) && (!sqq) && (!dq) && (!sqq)); /* no quotes at all */
101 else if (sq && sqq && (!dq)) //if singlequote but not doublequote
102 {
103 if (sq == sqq)
104 {
105 ERR("%s:%d:Skipping invalid value %s in config file at line %d\n\n", file, lineno, value, lineno);
106 continue;
107 }
108 sscanf(value, "'%[^']%*[^\n]\n", value);
109 }
110 else if (dq && dqq && (!sq)) //if doublequote but not singlequote
111 {
112 if (dq == dqq)
113 {
114 ERR("%s:%d:Skipping invalid value %s in config file at line %d\n\n", file, lineno, value, lineno);
115 continue;
116 }
117 sscanf(value, "\"%[^\"]%*[^\n]\n", value);
118 }
119 else //if both types of quotes
120 {
121 if (sq - dq > 0) //if doublequote first
122 {
123 if (sqq - dqq > 0) //if it ends in singlequote
124 {
125 ERR("%s:%d:Skipping invalid value %s\n", file, lineno, value);
126 continue;
127 }
128 sscanf(value, "'%[^']%*[^\n]\n", value);
129 }
130 else //if singlequote first
131 {
132 if (dqq - sqq > 0) //if it ends in doublequote
133 {
134 ERR("%s:%d:Skipping invalid value %s\n", file, lineno, value);
135 continue;
136 }
137 sscanf(value, "\"%[^\"]%*[^\n]\n", value);
138 }
139 }
140
141 if (!name[0])
142 continue;
143
144 if (!cb(lineno, name, value, data))
145 {
146 ERR("%s:%d:Skipping invalid line %s=%s\n", file, lineno, name, value);
147 }
148 }
149
150 munmap(m, size);
151 return 1;
152error:
153 eina_file_close(f);
154 return 0;
155}
156
diff --git a/src/bin/zshare_daemon.c b/src/bin/zshare_daemon.c
new file mode 100644
index 0000000..1ddff00
--- /dev/null
+++ b/src/bin/zshare_daemon.c
@@ -0,0 +1,178 @@
1/* ZSHARE
2 * Copyright (C) 2011 Mike Blumenkrantz, Zentific LLC
3 *
4 * All rights reserved.
5 * Use is subject to license terms.
6 *
7 * Please visit http://zentific.com for news and updates
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 */
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <fcntl.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <signal.h>
27#include <errno.h>
28#include <dirent.h>
29#include <unistd.h>
30#include "Zshare.h"
31#include "erssd.h"
32
33static int
34closefds_filter(const struct dirent *d)
35{
36 if (d->d_name[0] == '.')
37 return 0;
38
39 return 1;
40}
41
42static int
43closefds(void)
44{
45 int num, i;
46 struct dirent **d;
47
48 num = scandir("/proc/self/fd", &d, closefds_filter, NULL);
49 if (num < 1)
50 {
51 ERR("Error retrieving list of fds: %s\n", strerror(errno));
52 return 0;
53 }
54 for (i = 0; i < num; i++)
55 {
56 int fd;
57 char *p;
58
59 errno = 0;
60 fd = strtol(d[i]->d_name, &p, 10);
61 if (errno || (!p) || p[0])
62 { /* attempt to log even though it might not come out */
63 ERR("Filename %s is not a valid fd number!", d[i]->d_name);
64 goto error;
65 }
66 if (fd < 3) continue; /* std{in,out,err} */
67 if (close(fd) < 0)
68 {
69 ERR("Could not close fd %i: %s\n", fd, strerror(errno));
70 goto error;
71 }
72 free(d[i]);
73 }
74 free(d);
75
76 return 1;
77error:
78 for (; i < num; i++)
79 free(d[i]);
80 free(d);
81 return 0;
82}
83
84/**
85 * @brief Detaches daemon from the terminal and its caller
86 *
87 * @param ignsigcld 0 if we want to pay attention to child deaths, 1 to ignore.
88 * @return 0 on failure, 1 on success
89 */
90int
91zshare_daemon_detach(int ignsigcld)
92{
93 int childpid;
94
95 // If we are a child of init, then we don't need to break out any further
96 if (getppid() != 1)
97 {
98 // Ignore most signals that would make us exit
99 signal(SIGTTOU, SIG_IGN);
100 signal(SIGTTIN, SIG_IGN);
101 signal(SIGTSTP, SIG_IGN);
102 signal(SIGTERM, SIG_IGN);
103
104 childpid = fork();
105 // Fork and kill the parent - makes sure we aren't a process group leader
106 if (childpid < 0)
107 {
108 ERR("Forking failed: %s\n", strerror(errno));
109 return 0;
110 }
111 else if (childpid > 0)
112 exit(0);
113
114 // Disassociate from controlling terminal and group
115 if (setpgrp() < 0)
116 {
117 ERR("Could not become process group leader: %s\n", strerror(errno));
118 return 0;
119 }
120
121 // ignore group leader death
122 signal(SIGHUP, SIG_IGN);
123
124 // fork and kill parent again - makes sure we can't reaquire a command terminal
125 childpid = fork();
126 if (childpid < 0)
127 {
128 ERR("Forking failed: %s\n", strerror(errno));
129 return 0;
130 }
131 else if (childpid > 0)
132 exit(0);
133 }
134
135 // mark no errors so far
136 errno = 0;
137
138 // set file creation
139 umask(027);
140 if (chdir("/") < 0) return 0;
141
142 // Check if we want to ignore children exit statuses
143 if (ignsigcld) signal(SIGCLD, SIG_IGN);
144
145 return 1;
146}
147
148/**
149 * @brief Closes fds on current process
150 * @param all If 0 only std{in,out,err} are closed, else all fds are closed
151 * @return 0 on failure, 1 on success
152 */
153int
154zshare_daemon_closefds(int all)
155{
156 int devnull;
157 // if pidfile is to be generated, do so before calling this function
158 // (needs stderr to still be open)
159 if (all)
160 if (!closefds()) return 0;
161
162 /* redirect fd 0,1,2 to /dev/null */
163 devnull = open("/dev/null", O_RDWR);
164 if (devnull < 0)
165 {
166 ERR("Could not close fds: %s\n", strerror(errno));
167 return 0;
168 }
169
170 dup2(devnull, STDIN_FILENO);
171 dup2(devnull, STDOUT_FILENO);
172 dup2(devnull, STDERR_FILENO);
173
174 close(devnull);
175
176 return 1;
177}
178
diff --git a/src/bin/zshare_pid.c b/src/bin/zshare_pid.c
new file mode 100644
index 0000000..ca91319
--- /dev/null
+++ b/src/bin/zshare_pid.c
@@ -0,0 +1,92 @@
1/* ZSHARE
2 * Copyright (C) 2011 Mike Blumenkrantz, Zentific LLC
3 *
4 * All rights reserved.
5 * Use is subject to license terms.
6 *
7 * Please visit http://zentific.com for news and updates
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 */
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <fcntl.h>
26#include <unistd.h>
27#include "Zshare.h"
28#include "erssd.h"
29#ifndef O_CLOEXEC
30# define O_CLOEXEC 0
31#endif
32
33static char *file;
34
35/**
36 * @brief Check if @p pid_file exists
37 * @param pid_file The full path to the pid file
38 * @return 1 if the file exists, else 0
39 */
40int
41zshare_pid_check(const char *pid_file)
42{
43 struct stat s;
44
45 if (stat(pid_file, &s)) return 0;
46
47 return 1;
48}
49
50/**
51 * @brief Create a PID file for the process, storing the filename
52 * @param pid_file The full path to the pid_file
53 * @return 1 on success, -1 on successful write but unsuccessful filename store, 0 on failure
54 */
55int
56zshare_pid_create(const char *pid_file)
57{
58 int fd, ret = 1;
59 FILE *f;
60
61 if (file || (!pid_file)) return 0;
62 fd = open(pid_file, O_CLOEXEC | O_WRONLY | O_EXCL | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
63 if (!fd) return 0;
64 f = fdopen(fd, "w");
65 if (!f) return 0;
66
67 if (lockf(fd, F_TLOCK, 0) < 0)
68 ret = -1;
69 if (fprintf(f, "%d", getpid()) < 1)
70 ret = 0;
71 lockf(fd, F_ULOCK, 0);
72
73 fclose(f);
74 close(fd);
75
76 file = strdup(pid_file);
77 if (!file) return -1; /* realistically, a program should just exit here */
78
79 return ret;
80}
81
82/**
83 * Remove PID file for this process from previously stored filename, freeing stored filename
84 */
85void
86zshare_pid_delete(void)
87{
88 unlink(file);
89 free(file);
90 file = NULL;
91}
92
diff --git a/src/bin/zshare_private.h b/src/bin/zshare_private.h
new file mode 100644
index 0000000..866a3a7
--- /dev/null
+++ b/src/bin/zshare_private.h
@@ -0,0 +1,32 @@
1/* ZSHARE
2 * Copyright (C) 2011 Mike Blumenkrantz, Zentific LLC
3 *
4 * All rights reserved.
5 * Use is subject to license terms.
6 *
7 * Please visit http://zentific.com for news and updates
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 */
19#ifndef ZSHARE_PRIVATE_H
20#define ZSHARE_PRIVATE_H
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <unistd.h>
25
26#define ERR(...) \
27 if (zshare_log_active()) \
28 zshare_log_msg(ZSHARE_LOG_LEVEL_ERROR, __VA_ARGS__); \
29 else \
30 fprintf(stderr, __VA_ARGS__)
31
32#endif
diff --git a/src/lib/Erssd.h b/src/lib/Erssd.h
new file mode 100644
index 0000000..53f1314
--- /dev/null
+++ b/src/lib/Erssd.h
@@ -0,0 +1,61 @@
1#ifndef ERSSD_UTIL_H
2#define ERSSD_UTIL_H
3
4#ifdef HAVE_CONFIG_H
5# include "config.h"
6#endif
7
8#include <Azy.h>
9
10#define ERSSD_BUS "org.erssd"
11#define ERSSD_OBJECT "/org/erssd"
12#define ERSSD_INTERFACE "org.erssd"
13#define ERSSD_FEED_INTERFACE "org.erssd.Feed"
14
15typedef enum
16{
17 ERSSD_SIGNAL_FEED_ADD, /**< Returns URL string for new feed "s"*/
18 ERSSD_SIGNAL_FEED_DEL, /**< Returns URL string for deleted feed "s */
19 ERSSD_SIGNAL_FEED_UPDATED, /**< Returns feed URL string and number of new items "su" */
20 ERSSD_SIGNAL_FEED_ITEM_READ, /**< Returns feed URL string and feed item uuid string "ss" */
21 ERSSD_SIGNAL_LAST, /**< Placeholder for iterating */
22} Erssd_Signals;
23
24typedef void (*Erssd_Util_Data_Cb)(); /**< first param is always user data, other params depend on method/signal */
25typedef void (*Erssd_Util_Void_Cb)(void *data);
26
27EAPI int erssd_util_init(void);
28EAPI void erssd_util_shutdown(void);
29
30EAPI Eina_List *erssd_util_eet_feed_read_get(Eet_File *ef, const char *feed_url);
31EAPI Eina_List *erssd_util_eet_feed_unread_get(Eet_File *ef, const char *feed_url);
32EAPI Azy_Rss *erssd_util_eet_feed_get(Eet_File *ef, const char *feed_url);
33
34/** callback returns cfgfile string */
35EAPI Eina_Bool erssd_util_feed_cfgfile_get(Eina_Bool system_bus, Erssd_Util_Data_Cb cb, const void *data);
36/** callback returns cachefile string */
37EAPI Eina_Bool erssd_util_feed_cachefile_get(Eina_Bool system_bus, Erssd_Util_Data_Cb cb, const void *data);
38/** callback returns void */
39EAPI Eina_Bool erssd_util_quit(Eina_Bool system_bus, Erssd_Util_Void_Cb cb, const void *data);
40
41/** callback returns bool */
42EAPI Eina_Bool erssd_util_feed_add(Eina_Bool system_bus, const char *feed_url, Erssd_Util_Data_Cb cb, const void *data);
43/** callback returns bool */
44EAPI Eina_Bool erssd_util_feed_del(Eina_Bool system_bus, const char *feed_url, Erssd_Util_Data_Cb cb, const void *data);
45/** callback returns Eina_List<Eina_Stringshare*> */
46EAPI Eina_Bool erssd_util_feeds_list(Eina_Bool system_bus, Erssd_Util_Data_Cb cb, const void *data);
47/** callback returns void */
48EAPI Eina_Bool erssd_util_feed_item_read(Eina_Bool system_bus, const char *feed_url, const char *uuid, Erssd_Util_Void_Cb cb, const void *data);
49/** callback returns void */
50EAPI Eina_Bool erssd_util_feed_item_unread(Eina_Bool system_bus, const char *feed_url, const char *uuid, Erssd_Util_Void_Cb cb, const void *data);
51/** callback returns void */
52EAPI Eina_Bool erssd_util_feed_readall(Eina_Bool system_bus, const char *feed_url, Erssd_Util_Void_Cb cb, const void *data);
53/** callback returns void */
54EAPI Eina_Bool erssd_util_feed_clear_read(Eina_Bool system_bus, const char *feed_url, Erssd_Util_Void_Cb cb, const void *data);
55
56/** callback returns bool: true if erssd is running on that bus, else false */
57EAPI void erssd_util_nameowner_cb_set(Eina_Bool system_bus, Erssd_Util_Data_Cb cb, const void *data);
58
59/** callback params/types depend on signal type; strings are always stringshared */
60EAPI void erssd_util_feed_signal_cb_set(Eina_Bool system_bus, Erssd_Signals signal, Erssd_Util_Data_Cb cb, const void *data);
61#endif
diff --git a/src/lib/Makefile.mk b/src/lib/Makefile.mk
new file mode 100644
index 0000000..bf27d11
--- /dev/null
+++ b/src/lib/Makefile.mk
@@ -0,0 +1,21 @@
1EXTRA_DIST += \
2src/lib/erssd_private.h
3
4erssd_HEADERS = src/lib/Erssd.h
5erssddir = $(pkgincludedir)-$(VMAJ)
6
7lib_LTLIBRARIES = src/lib/liberssd_util.la
8
9src_lib_liberssd_util_la_LIBADD = @ERSSD_UTIL_LIBS@
10
11src_lib_liberssd_util_la_LDFLAGS = -version-info @version_info@ -no-undefined
12
13src_lib_liberssd_util_la_CPPFLAGS = \
14-I$(top_srcdir) \
15-DBUILDING_LIB \
16@ERSSD_UTIL_CFLAGS@
17
18src_lib_liberssd_util_la_SOURCES = \
19src/lib/erssd_dbus.c \
20src/lib/erssd_eet.c \
21src/lib/erssd_lib.c
diff --git a/src/lib/erssd_dbus.c b/src/lib/erssd_dbus.c
new file mode 100644
index 0000000..b5c4968
--- /dev/null
+++ b/src/lib/erssd_dbus.c
@@ -0,0 +1,408 @@
1#include "erssd_private.h"
2
3typedef struct CB_Data
4{
5 void *cb;
6 void *data;
7} CB_Data;
8
9enum
10{
11 CONN_SESSION,
12 CONN_SYSTEM,
13};
14
15static CB_Data nameowner[2];
16
17static CB_Data callbacks[4][2];
18
19static EDBus_Signal_Handler *handlers[4][2] = {{NULL}};
20
21static const char *const signal_members[] =
22{
23 [ERSSD_SIGNAL_FEED_ADD] = "Add",
24 [ERSSD_SIGNAL_FEED_DEL] = "Del",
25 [ERSSD_SIGNAL_FEED_UPDATED] = "Updated",
26 [ERSSD_SIGNAL_FEED_ITEM_READ] = "ItemRead"
27};
28
29static int conn_types[] = {EDBUS_CONNECTION_TYPE_SESSION, EDBUS_CONNECTION_TYPE_SYSTEM};
30
31static EDBus_Connection *erssd_dbus_conn[2] = {NULL};
32
33Eina_Bool
34_dbus_conn_setup(Eina_Bool system_bus)
35{
36 if (!erssd_dbus_conn[system_bus])
37 erssd_dbus_conn[system_bus] = edbus_connection_get(conn_types[system_bus]);
38 return !!erssd_dbus_conn[system_bus];
39}
40
41static void
42_dbus_string_return(void *data, const EDBus_Message *msg, EDBus_Pending *pending EINA_UNUSED)
43{
44 CB_Data *cbd = data;
45 Erssd_Util_Data_Cb cb;
46 char *str;
47 Eina_Stringshare *s = NULL;
48 const char *error_name, *error_text;
49
50 if (edbus_message_error_get(msg, &error_name, &error_text))
51 {
52 ERR("%s: %s", error_name, error_text);
53 }
54 else if (edbus_message_arguments_get(msg, "s", &str))
55 s = eina_stringshare_add(str);
56 cb = cbd->cb;
57 cb(cbd->data, s);
58 free(cbd);
59}
60
61static void
62_dbus_stringlist_return(void *data, const EDBus_Message *msg, EDBus_Pending *pending EINA_UNUSED)
63{
64 CB_Data *cbd = data;
65 Erssd_Util_Data_Cb cb;
66 EDBus_Message_Iter *array;
67 Eina_List *ret = NULL;
68 char *str;
69 const char *error_name, *error_text;
70
71 if (edbus_message_error_get(msg, &error_name, &error_text))
72 {
73 ERR("%s: %s", error_name, error_text);
74 }
75 else if (!edbus_message_arguments_get(msg, "as", &array))
76 ERR("args");
77 else
78 {
79 while (edbus_message_iter_get_and_next(array, 's', &str))
80 ret = eina_list_append(ret, eina_stringshare_add(str));
81 }
82
83 cb = cbd->cb;
84 cb(cbd->data, ret);
85 free(cbd);
86 EINA_LIST_FREE(ret, str)
87 eina_stringshare_del(str);
88}
89
90static void
91_dbus_bool_return(void *data, const EDBus_Message *msg, EDBus_Pending *pending EINA_UNUSED)
92{
93 CB_Data *cbd = data;
94 Erssd_Util_Data_Cb cb;
95 Eina_Bool b = EINA_FALSE;
96 const char *error_name, *error_text;
97
98 if (edbus_message_error_get(msg, &error_name, &error_text))
99 {
100 ERR("%s: %s", error_name, error_text);
101 }
102 else if (!edbus_message_arguments_get(msg, "b", &b))
103 ERR("arg fetching");
104 cb = cbd->cb;
105 if (cb) cb(cbd->data, b);
106 free(cbd);
107}
108
109static void
110_dbus_void_return(void *data, const EDBus_Message *msg, EDBus_Pending *pending EINA_UNUSED)
111{
112 CB_Data *cbd = data;
113 Erssd_Util_Void_Cb cb;
114 const char *error_name, *error_text;
115
116 if (edbus_message_error_get(msg, &error_name, &error_text))
117 {
118 ERR("%s: %s", error_name, error_text);
119 }
120 cb = cbd->cb;
121 cb(cbd->data);
122 free(cbd);
123}
124
125static void
126_dbus_signal_feed_add(void *data, const EDBus_Message *msg)
127{
128 char *url;
129 Eina_Stringshare *s = NULL;
130 CB_Data *cbd = data;
131 Erssd_Util_Data_Cb cb;
132
133 if (edbus_message_arguments_get(msg, "s", &url))
134 s = eina_stringshare_add(url);
135
136 cb = cbd->cb;
137 cb(cbd->data, s);
138 eina_stringshare_del(s);
139}
140
141static void
142_dbus_signal_feed_del(void *data, const EDBus_Message *msg)
143{
144 char *url;
145 Eina_Stringshare *s = NULL;
146 CB_Data *cbd = data;
147 Erssd_Util_Data_Cb cb;
148
149 if (edbus_message_arguments_get(msg, "s", &url))
150 s = eina_stringshare_add(url);
151
152 cb = cbd->cb;
153 cb(cbd->data, s);
154 eina_stringshare_del(s);
155}
156
157static void
158_dbus_signal_feed_updated(void *data, const EDBus_Message *msg)
159{
160 char *url;
161 Eina_Stringshare *s = NULL;
162 unsigned int u;
163 CB_Data *cbd = data;
164 Erssd_Util_Data_Cb cb;
165
166 if (edbus_message_arguments_get(msg, "su", &url, &u))
167 s = eina_stringshare_add(url);
168
169 cb = cbd->cb;
170 cb(cbd->data, s, u);
171 eina_stringshare_del(s);
172}
173
174static void
175_dbus_signal_feed_item_read(void *data, const EDBus_Message *msg)
176{
177 char *url, *uuid;
178 Eina_Stringshare *s = NULL, *ss = NULL;
179 CB_Data *cbd = data;
180 Erssd_Util_Data_Cb cb;
181
182 if (edbus_message_arguments_get(msg, "ss", &url, &uuid))
183 {
184 s = eina_stringshare_add(url);
185 ss = eina_stringshare_add(uuid);
186 }
187
188 cb = cbd->cb;
189 cb(cbd->data, s, ss);
190 eina_stringshare_del(s);
191 eina_stringshare_del(ss);
192}
193
194static Eina_Bool
195_dbus_call_helper(Eina_Bool system_bus, const char *method, void *cb, const void *data, EDBus_Message_Cb retcb)
196{
197 EDBus_Message *msg;
198 CB_Data *cbd;
199 Eina_Bool ret;
200
201 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_dbus_conn_setup(system_bus), EINA_FALSE);
202
203 msg = edbus_message_method_call_new(ERSSD_BUS, ERSSD_OBJECT, ERSSD_INTERFACE, method);
204 EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE);
205 cbd = malloc(sizeof(CB_Data));
206 cbd->cb = cb;
207 cbd->data = (void*)data;
208 ret = !!edbus_connection_send(erssd_dbus_conn[system_bus], msg, retcb, cbd, -1);
209 if (!ret) free(cbd);
210 return ret;
211}
212
213static Eina_Bool
214_dbus_feed_call_helper(Eina_Bool system_bus, const char *method, const char *feed_url, void *cb, const void *data, EDBus_Message_Cb retcb)
215{
216 EDBus_Message *msg;
217 CB_Data *cbd;
218 Eina_Bool ret;
219
220 if (strcmp(method, "List"))
221 {
222 EINA_SAFETY_ON_NULL_RETURN_VAL(feed_url, EINA_FALSE);
223 }
224 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_dbus_conn_setup(system_bus), EINA_FALSE);
225
226 msg = edbus_message_method_call_new(ERSSD_BUS, ERSSD_OBJECT, ERSSD_FEED_INTERFACE, method);
227 EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE);
228 if (feed_url)
229 edbus_message_arguments_append(msg, "s", feed_url);
230 cbd = malloc(sizeof(CB_Data));
231 cbd->cb = cb;
232 cbd->data = (void*)data;
233 ret = !!edbus_connection_send(erssd_dbus_conn[system_bus], msg, retcb, cbd, -1);
234 if (!ret) free(cbd);
235 return ret;
236}
237
238static Eina_Bool
239_dbus_feed_item_call_helper(Eina_Bool system_bus, const char *method, const char *feed_url, const char *item_uuid, void *cb, const void *data, EDBus_Message_Cb retcb)
240{
241 EDBus_Message *msg;
242 CB_Data *cbd;
243 Eina_Bool ret;
244
245 EINA_SAFETY_ON_NULL_RETURN_VAL(feed_url, EINA_FALSE);
246 EINA_SAFETY_ON_NULL_RETURN_VAL(item_uuid, EINA_FALSE);
247 EINA_SAFETY_ON_TRUE_RETURN_VAL(!_dbus_conn_setup(system_bus), EINA_FALSE);
248
249 msg = edbus_message_method_call_new(ERSSD_BUS, ERSSD_OBJECT, ERSSD_FEED_INTERFACE, method);
250
251 edbus_message_arguments_append(msg, "ss", feed_url, item_uuid);
252 EINA_SAFETY_ON_NULL_RETURN_VAL(msg, EINA_FALSE);
253 cbd = malloc(sizeof(CB_Data));
254 cbd->cb = cb;
255 cbd->data = (void*)data;
256 ret = !!edbus_connection_send(erssd_dbus_conn[system_bus], msg, retcb, cbd, -1);
257 if (!ret) free(cbd);
258 return ret;
259}
260
261static void
262_dbus_nameowner_cb(void *data, const char *bus EINA_UNUSED, const char *old EINA_UNUSED, const char *id)
263{
264 CB_Data *cbd = data;
265 Erssd_Util_Data_Cb cb;
266
267 cb = cbd->cb;
268 if (cb) cb(cbd->data, id && id[0]);
269}
270
271
272Eina_Bool
273erssd_util_dbus_init(void)
274{
275 if (!edbus_init()) return EINA_FALSE;
276
277 return EINA_TRUE;
278}
279
280void
281erssd_util_dbus_shutdown(void)
282{
283 unsigned int x, y;
284
285 for (x = 0; x < 2; x++)
286 {
287 if (erssd_dbus_conn[x])
288 edbus_connection_unref(erssd_dbus_conn[x]);
289 erssd_dbus_conn[x] = NULL;
290 nameowner[x].cb = NULL;
291 nameowner[x].data = NULL;
292 }
293 for (x = 0; x < ERSSD_SIGNAL_LAST; x++)
294 {
295 for (y = 0; y < 2; y++)
296 {
297 handlers[x][y] = NULL;
298 callbacks[x][y].cb = NULL;
299 callbacks[x][y].data = NULL;
300 }
301 }
302 edbus_shutdown();
303}
304
305/////////////////////////////////////////////////////////////
306
307Eina_Bool
308erssd_util_feed_cfgfile_get(Eina_Bool system_bus, Erssd_Util_Data_Cb cb, const void *data)
309{
310 EINA_SAFETY_ON_NULL_RETURN_VAL(cb, EINA_FALSE);
311 return _dbus_call_helper(system_bus, "FeedConfigFile", cb, data, _dbus_string_return);
312}
313
314Eina_Bool
315erssd_util_feed_cachefile_get(Eina_Bool system_bus, Erssd_Util_Data_Cb cb, const void *data)
316{
317 EINA_SAFETY_ON_NULL_RETURN_VAL(cb, EINA_FALSE);
318 return _dbus_call_helper(system_bus, "FeedCacheFile", cb, data, _dbus_string_return);
319}
320
321Eina_Bool
322erssd_util_quit(Eina_Bool system_bus, Erssd_Util_Void_Cb cb, const void *data)
323{
324 return _dbus_call_helper(system_bus, "Shutdown", cb, data, _dbus_void_return);
325}
326
327Eina_Bool
328erssd_util_feed_add(Eina_Bool system_bus, const char *feed_url, Erssd_Util_Data_Cb cb, const void *data)
329{
330 return _dbus_feed_call_helper(system_bus, "Add", feed_url, cb, data, _dbus_bool_return);
331}
332
333Eina_Bool
334erssd_util_feed_del(Eina_Bool system_bus, const char *feed_url, Erssd_Util_Data_Cb cb, const void *data)
335{
336 return _dbus_feed_call_helper(system_bus, "Del", feed_url, cb, data, _dbus_bool_return);
337}
338
339Eina_Bool
340erssd_util_feeds_list(Eina_Bool system_bus, Erssd_Util_Data_Cb cb, const void *data)
341{
342 return _dbus_feed_call_helper(system_bus, "List", NULL, cb, data, _dbus_stringlist_return);
343}
344
345Eina_Bool
346erssd_util_feed_item_read(Eina_Bool system_bus, const char *feed_url, const char *uuid, Erssd_Util_Void_Cb cb, const void *data)
347{
348 return _dbus_feed_item_call_helper(system_bus, "ReadItem", feed_url, uuid, cb, data, _dbus_void_return);
349}
350
351Eina_Bool
352erssd_util_feed_item_unread(Eina_Bool system_bus, const char *feed_url, const char *uuid, Erssd_Util_Void_Cb cb, const void *data)
353{
354 return _dbus_feed_item_call_helper(system_bus, "UnreadItem", feed_url, uuid, cb, data, _dbus_void_return);
355}
356
357Eina_Bool
358erssd_util_feed_readall(Eina_Bool system_bus, const char *feed_url, Erssd_Util_Void_Cb cb, const void *data)
359{
360 return _dbus_feed_call_helper(system_bus, "ReadAll", feed_url, cb, data, _dbus_void_return);
361}
362
363Eina_Bool
364erssd_util_feed_clear_read(Eina_Bool system_bus, const char *feed_url, Erssd_Util_Void_Cb cb, const void *data)
365{
366 return _dbus_feed_call_helper(system_bus, "ClearRead", feed_url, cb, data, _dbus_void_return);
367}
368
369void
370erssd_util_nameowner_cb_set(Eina_Bool system_bus, Erssd_Util_Data_Cb cb, const void *data)
371{
372 EINA_SAFETY_ON_NULL_RETURN(cb);
373 EINA_SAFETY_ON_TRUE_RETURN(!_dbus_conn_setup(system_bus));
374 if (!nameowner[system_bus].cb)
375 edbus_name_owner_changed_callback_add(erssd_dbus_conn[system_bus], ERSSD_BUS, _dbus_nameowner_cb, &nameowner[system_bus], EINA_TRUE);
376 nameowner[system_bus].cb = cb, nameowner[system_bus].data = (void*)data;
377}
378
379void
380erssd_util_feed_signal_cb_set(Eina_Bool system_bus, Erssd_Signals signal, Erssd_Util_Data_Cb cb, const void *data)
381{
382 EDBus_Signal_Cb sig_cb;
383
384 EINA_SAFETY_ON_NULL_RETURN(cb);
385 EINA_SAFETY_ON_TRUE_RETURN(signal >= ERSSD_SIGNAL_LAST);
386
387 switch (signal)
388 {
389 case ERSSD_SIGNAL_FEED_ADD:
390 sig_cb = _dbus_signal_feed_add;
391 break;
392 case ERSSD_SIGNAL_FEED_DEL:
393 sig_cb = _dbus_signal_feed_del;
394 break;
395 case ERSSD_SIGNAL_FEED_UPDATED:
396 sig_cb = _dbus_signal_feed_updated;
397 break;
398 case ERSSD_SIGNAL_FEED_ITEM_READ:
399 sig_cb = _dbus_signal_feed_item_read;
400 break;
401 default: break;
402 }
403 if (handlers[signal][system_bus]) edbus_signal_handler_unref(handlers[signal][system_bus]);
404 callbacks[signal][system_bus].cb = cb;
405 callbacks[signal][system_bus].data = (void*)data;
406 handlers[signal][system_bus] = edbus_signal_handler_add(erssd_dbus_conn[system_bus],
407 ERSSD_BUS, ERSSD_OBJECT, ERSSD_FEED_INTERFACE, signal_members[signal], sig_cb, &callbacks[signal][system_bus]);
408}
diff --git a/src/lib/erssd_eet.c b/src/lib/erssd_eet.c
new file mode 100644
index 0000000..ba73b13
--- /dev/null
+++ b/src/lib/erssd_eet.c
@@ -0,0 +1,154 @@
1#include "erssd_private.h"
2
3static Eet_Data_Descriptor *feed_edd = NULL;
4static Eet_Data_Descriptor *feed_config_edd = NULL;
5static Eet_Data_Descriptor *feed_cache_edd = NULL;
6
7/* shorter version of Rss_Feed struct so we can free it properly */
8typedef struct Rss_Feed
9{
10 EINA_INLIST;
11 Eina_Stringshare *url;
12} Rss_Feed;
13
14static void
15_eet_rss_feed_free(Rss_Feed *feed)
16{
17 eina_stringshare_del(feed->url);
18 free(feed);
19}
20
21Eina_List *
22_eet_cache_items_get(Eet_File *ef, const char *url, Eina_Bool unread)
23{
24 Eina_List *ret = NULL;
25 Feed_Cache *fc;
26 char buf[4096];
27
28 if (unread)
29 snprintf(buf, sizeof(buf), "%s/unread", url);
30 else
31 snprintf(buf, sizeof(buf), "%s/read", url);
32 fc = eet_data_read(ef, feed_cache_edd, buf);
33 if (fc)
34 {
35 ret = fc->feeds;
36 free(fc);
37 }
38 return ret;
39}
40
41static void
42_eet_feed_cache_edd_init(void)
43{
44 Eet_Data_Descriptor_Class eddc;
45
46 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Feed_Cache);
47 feed_cache_edd = eet_data_descriptor_stream_new(&eddc);
48
49 EET_DATA_DESCRIPTOR_ADD_LIST(feed_cache_edd, Feed_Cache, "feeds", feeds, azy_rss_item_edd_get());
50}
51
52static void
53_eet_feed_edd_init(void)
54{
55 Eet_Data_Descriptor_Class eddc;
56
57 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Rss_Feed);
58 feed_edd = eet_data_descriptor_stream_new(&eddc);
59
60#define ADD(name, type) \
61 EET_DATA_DESCRIPTOR_ADD_BASIC(feed_edd, Rss_Feed, #name, name, EET_T_##type)
62
63 ADD(url, INLINED_STRING);
64
65#undef ADD
66}
67
68static void
69_eet_feed_config_edd_init(void)
70{
71 Eet_Data_Descriptor_Class eddc;
72
73 _eet_feed_edd_init();
74 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Feed_Config);
75 feed_config_edd = eet_data_descriptor_stream_new(&eddc);
76
77 EET_DATA_DESCRIPTOR_ADD_BASIC(feed_config_edd, Feed_Config, "version", version, EET_T_UINT);
78 EET_DATA_DESCRIPTOR_ADD_HASH(feed_config_edd, Feed_Config, "feeds", feeds, feed_edd);
79}
80
81//////////////////////////////////////////////////////
82
83Eina_Bool
84erssd_util_eet_init(void)
85{
86 if (!eet_init()) return EINA_FALSE;
87 EINA_SAFETY_ON_TRUE_GOTO(!azy_init(), azy_fail);
88 _eet_feed_config_edd_init();
89 _eet_feed_cache_edd_init();
90
91 return EINA_TRUE;
92azy_fail:
93 eet_shutdown();
94 return EINA_FALSE;
95}
96
97void
98erssd_util_eet_shutdown(void)
99{
100 azy_shutdown();
101 eet_shutdown();
102}
103
104static Eina_Bool
105_eet_feed_hash_iterator(const Eina_Hash *hash EINA_UNUSED, const char *key, void *data EINA_UNUSED, void *fdata)
106{
107 Eina_List **ret = fdata;
108 *ret = eina_list_append(*ret, eina_stringshare_add(key));
109 return EINA_TRUE;
110}
111
112//////////////////////////////////////////////////////
113
114Eina_List *
115erssd_eet_feeds_get(Eet_File *ef)
116{
117 Feed_Config *cf;
118 Eina_List *ret = NULL;
119
120 cf = eet_data_read(ef, feed_config_edd, ERSSD_CONFIG_FEEDS_KEY);
121 if (!cf) return NULL;
122 if (cf->feeds)
123 {
124 eina_hash_foreach(cf->feeds, (Eina_Hash_Foreach)_eet_feed_hash_iterator, &ret);
125 eina_hash_free_cb_set(cf->feeds, (Eina_Free_Cb)_eet_rss_feed_free);
126 eina_hash_free(cf->feeds);
127 }
128 free(cf);
129 return ret;
130}
131
132Eina_List *
133erssd_util_eet_feed_read_get(Eet_File *ef, const char *feed_url)
134{
135 EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
136 EINA_SAFETY_ON_NULL_RETURN_VAL(feed_url, NULL);
137 return _eet_cache_items_get(ef, feed_url, EINA_FALSE);
138}
139
140Eina_List *
141erssd_util_eet_feed_unread_get(Eet_File *ef, const char *feed_url)
142{
143 EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
144 EINA_SAFETY_ON_NULL_RETURN_VAL(feed_url, NULL);
145 return _eet_cache_items_get(ef, feed_url, EINA_TRUE);
146}
147
148Azy_Rss *
149erssd_util_eet_feed_get(Eet_File *ef, const char *feed_url)
150{
151 EINA_SAFETY_ON_NULL_RETURN_VAL(ef, NULL);
152 EINA_SAFETY_ON_NULL_RETURN_VAL(feed_url, NULL);
153 return eet_data_read(ef, azy_rss_edd_get(), feed_url);
154}
diff --git a/src/lib/erssd_lib.c b/src/lib/erssd_lib.c
new file mode 100644
index 0000000..78f35a7
--- /dev/null
+++ b/src/lib/erssd_lib.c
@@ -0,0 +1,39 @@
1#include "erssd_private.h"
2
3static int _erssd_init_count = 0;
4int erssd_util_log_dom = -1;
5
6int
7erssd_util_init(void)
8{
9 if (++_erssd_init_count != 1) return _erssd_init_count;
10
11 if (!eina_init()) return --_erssd_init_count;
12 erssd_util_log_dom = eina_log_domain_register("erssd_util", EINA_COLOR_ORANGE);
13 EINA_SAFETY_ON_TRUE_GOTO(erssd_util_log_dom < 0, eina_fail);
14
15 EINA_SAFETY_ON_TRUE_GOTO(!erssd_util_eet_init(), eet_fail);
16 EINA_SAFETY_ON_TRUE_GOTO(!erssd_util_dbus_init(), edbus_fail);
17
18 return _erssd_init_count;
19edbus_fail:
20 erssd_util_eet_shutdown();
21eet_fail:
22 eina_log_domain_unregister(erssd_util_log_dom);
23 erssd_util_log_dom = -1;
24eina_fail:
25 eina_shutdown();
26 return --_erssd_init_count;
27}
28
29void
30erssd_util_shutdown(void)
31{
32 if (!_erssd_init_count) return;
33 if (--_erssd_init_count) return;
34 erssd_util_dbus_shutdown();
35 erssd_util_eet_shutdown();
36 eina_log_domain_unregister(erssd_util_log_dom);
37 erssd_util_log_dom = -1;
38 eina_shutdown();
39}
diff --git a/src/lib/erssd_private.h b/src/lib/erssd_private.h
new file mode 100644
index 0000000..adc43aa
--- /dev/null
+++ b/src/lib/erssd_private.h
@@ -0,0 +1,43 @@
1#ifndef ERSSD_PRIVATE_H
2#define ERSSD_PRIVATE_H
3
4#include "Erssd.h"
5#include <EDBus.h>
6#include <ctype.h>
7
8/* this is the filename which we save feed configs to */
9#define ERSSD_CONFIG_FEEDS_FILENAME "erssd_feed_config.eet"
10
11/* this is the filename which we save feed cache data to */
12#define ERSSD_CACHE_FEEDS_FILENAME "erssd_feed_cache.eet"
13
14#define ERSSD_CONFIG_FEEDS_KEY "feeds"
15
16typedef struct Feed_Config
17{
18 unsigned int version;
19 Eina_Hash *feeds;
20} Feed_Config;
21
22typedef struct Feed_Cache
23{
24 Eina_List *feeds;
25} Feed_Cache;
26
27Eina_Bool erssd_util_dbus_init(void);
28void erssd_util_dbus_shutdown(void);
29
30Eina_Bool erssd_util_eet_init(void);
31void erssd_util_eet_shutdown(void);
32
33# ifdef BUILDING_LIB
34extern int erssd_util_log_dom;
35
36#define DBG(...) EINA_LOG_DOM_DBG(erssd_util_log_dom, __VA_ARGS__)
37#define INF(...) EINA_LOG_DOM_INFO(erssd_util_log_dom, __VA_ARGS__)
38#define WRN(...) EINA_LOG_DOM_WARN(erssd_util_log_dom, __VA_ARGS__)
39#define ERR(...) EINA_LOG_DOM_ERR(erssd_util_log_dom, __VA_ARGS__)
40#define CRI(...) EINA_LOG_DOM_CRIT(erssd_util_log_dom, __VA_ARGS__)
41#endif
42
43#endif
diff --git a/src/utils/Makefile.mk b/src/utils/Makefile.mk
new file mode 100644
index 0000000..1d40fe8
--- /dev/null
+++ b/src/utils/Makefile.mk
@@ -0,0 +1,14 @@
1bin_PROGRAMS += src/utils/erssd-config
2
3src_utils_erssd_config_CPPFLAGS = \
4-I$(top_srcdir) \
5-I$(top_srcdir)/src/lib \
6@ERSSD_UTIL_CFLAGS@ \
7@CONFIG_CFLAGS@
8
9src_utils_erssd_config_LDADD = \
10@ERSSD_UTIL_LIBS@ \
11@CONFIG_LIBS@ \
12$(top_builddir)/src/lib/liberssd_util.la
13
14src_utils_erssd_config_SOURCES = src/utils/erssd-config.c
diff --git a/src/utils/erssd-config.c b/src/utils/erssd-config.c
new file mode 100644
index 0000000..3d420d0
--- /dev/null
+++ b/src/utils/erssd-config.c
@@ -0,0 +1,507 @@
1#include <Erssd.h>
2#include <Elementary.h>
3
4/* this is a VERY simple client for configurating eRSSd.
5 * it is not meant to be a showcase of toolkits, merely an
6 * example for how to use the erssd_util api.
7 */
8
9#define WEIGHT evas_object_size_hint_weight_set
10#define ALIGN evas_object_size_hint_align_set
11#define EXPAND(X) WEIGHT((X), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND)
12#define FILL(X) ALIGN((X), EVAS_HINT_FILL, EVAS_HINT_FILL)
13
14typedef struct Rss_Feed
15{
16 int conn;
17 Eina_Stringshare *url;
18 Eina_Stringshare *img_url;
19 Eina_Binbuf *img_data;
20 Azy_Rss *rss;
21 Azy_Client *cli;
22 Eina_Hash *read_items;
23 Eina_Hash *unread_items;
24 Elm_Object_Item *list_item;
25} Rss_Feed;
26
27static long dbus_view = 0;
28static Eina_Stringshare *cachefile[2];
29static Eet_File *ef_cache[2];
30static Eina_Bool dbus_connected[2];
31
32static Eina_Hash *feeds[2];
33
34static Evas_Object *feed_list;
35static Evas_Object *button_add, *button_del;
36static Evas_Object *radios[2];
37
38static Elm_Genlist_Item_Class feed_itc;
39//static Elm_Genlist_Item_Class feed_item_itc;
40
41static void
42_cache_refresh(int conn)
43{
44 if (ef_cache[conn]) eet_close(ef_cache[conn]);
45 ef_cache[conn] = eet_open(cachefile[conn], EET_FILE_MODE_READ);
46}
47
48static void
49_feed_selected_cb(void *data EINA_UNUSED /* Rss_Feed */, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
50{
51 elm_object_disabled_set(button_del, 0);
52}
53
54
55static Eina_Error
56_feed_image_cb(Azy_Client *cli, Azy_Content *content, Eina_Binbuf *buf)
57{
58 Rss_Feed *feed;
59 Azy_Net *net;
60 Eina_Stringshare *content_type;
61
62 feed = azy_client_data_get(cli);
63 net = azy_content_net_get(content);
64 content_type = azy_net_header_get(net, "content-type");
65 if (content_type && (!strncmp(content_type, "image/", 6)))
66 {
67 size_t size = eina_binbuf_length_get(buf);
68 feed->img_data = eina_binbuf_manage_new_length(eina_binbuf_string_steal(buf), size);
69 if (feed->list_item)
70 elm_genlist_item_fields_update(feed->list_item, "elm.swallow.icon", ELM_GENLIST_ITEM_FIELD_CONTENT);
71 }
72 azy_client_free(cli);
73 feed->cli = NULL;
74 return AZY_ERROR_NONE;
75}
76
77static void
78_feed_update(Rss_Feed *feed, Eina_Bool refresh)
79{
80 azy_rss_free(feed->rss);
81 feed->rss = erssd_util_eet_feed_get(ef_cache[feed->conn], feed->url);
82 if (feed->rss)
83 {
84 if (eina_stringshare_replace(&feed->img_url, azy_rss_img_url_get(feed->rss)) && feed->img_url)
85 {
86 feed->cli = azy_client_util_connect(azy_rss_img_url_get(feed->rss));
87 azy_client_callback_set(feed->cli, azy_client_current(feed->cli), (Azy_Client_Transfer_Complete_Cb)_feed_image_cb);
88 azy_client_data_set(feed->cli, feed);
89 }
90 }
91 if (feed->list_item && refresh) elm_genlist_item_update(feed->list_item);
92}
93
94static void
95_feed_items_update(Rss_Feed *feed)
96{
97 Eina_List *l;
98 Azy_Rss_Item *item;
99
100 eina_hash_free_buckets(feed->read_items);
101 eina_hash_free_buckets(feed->unread_items);
102 l = erssd_util_eet_feed_read_get(ef_cache[feed->conn], feed->url);
103 EINA_LIST_FREE(l, item)
104 eina_hash_direct_add(feed->read_items, azy_rss_item_uuid_get(item), item);
105 l = erssd_util_eet_feed_unread_get(ef_cache[feed->conn], feed->url);
106 EINA_LIST_FREE(l, item)
107 eina_hash_direct_add(feed->unread_items, azy_rss_item_uuid_get(item), item);
108}
109
110static Rss_Feed *
111_feed_new(Eina_Stringshare *url, int conn)
112{
113 Rss_Feed *feed;
114
115 feed = calloc(1, sizeof(Rss_Feed));
116 feed->url = eina_stringshare_ref(url);
117 feed->read_items = eina_hash_stringshared_new((Eina_Free_Cb)azy_rss_item_free);
118 feed->unread_items = eina_hash_stringshared_new((Eina_Free_Cb)azy_rss_item_free);
119 eina_hash_direct_add(feeds[conn], feed->url, feed);
120 if (ef_cache[conn])
121 {
122 _feed_items_update(feed);
123 _feed_update(feed, 0);
124 }
125 feed->list_item = elm_genlist_item_append(feed_list, &feed_itc, feed, NULL, 0, _feed_selected_cb, feed);
126 feed->conn = conn;
127 return feed;
128}
129
130static void
131_feed_free(Rss_Feed *feed)
132{
133 if (!feed) return;
134 //eina_stringshare_del(feed->url); already deleted
135 eina_stringshare_del(feed->img_url);
136 azy_rss_free(feed->rss);
137 if (feed->list_item) elm_object_item_del(feed->list_item);
138 if (feed->img_data) eina_binbuf_free(feed->img_data);
139 eina_hash_free(feed->read_items);
140 eina_hash_free(feed->unread_items);
141 free(feed);
142}
143
144static char *
145_it_text_get(Rss_Feed *feed, Evas_Object *obj EINA_UNUSED, const char *part)
146{
147 Eina_Stringshare *title = NULL;
148 char buf[4096];
149
150 if (strcmp(part, "elm.text"))
151 {
152 if (!feed->rss) return NULL;
153 title = azy_rss_desc_get(feed->rss);
154 return title ? strdup(title) : NULL;
155 }
156
157 if (feed->rss)
158 {
159 title = azy_rss_title_get(feed->rss);
160 snprintf(buf, sizeof(buf), "(%u unread) %s", eina_hash_population(feed->unread_items), title ?: feed->url);
161 }
162 else
163 snprintf(buf, sizeof(buf), "%s", feed->url);
164
165 return strdup(buf);
166}
167
168static Evas_Object *
169_it_content_get(Rss_Feed *feed, Evas_Object *obj, const char *part EINA_UNUSED)
170{
171 Evas_Object *o;
172 if (!feed->img_data) return NULL;
173 o = elm_image_add(obj);
174 elm_image_memfile_set(o, eina_binbuf_string_get(feed->img_data), eina_binbuf_length_get(feed->img_data), NULL, NULL);
175 evas_object_show(o);
176 return o;
177}
178
179static void
180_it_del(Rss_Feed *feed, Evas_Object *obj EINA_UNUSED)
181{
182 feed->list_item = NULL;
183}
184
185static Eina_Bool
186_feed_foreach_cb(const Eina_Hash *h EINA_UNUSED, const char *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED)
187{
188 //int conn = (long)fdata;
189 Rss_Feed *feed = data;
190
191 if (feed->list_item)
192 elm_genlist_item_update(feed->list_item);
193 else
194 feed->list_item = elm_genlist_item_append(feed_list, &feed_itc, feed, NULL, 0, _feed_selected_cb, feed);
195 return EINA_TRUE;
196}
197
198static void
199_dbus_signal_feed_add(void *data, Eina_Stringshare *url)
200{
201 _cache_refresh((long)data);
202 _feed_new(url, (long)data);
203}
204
205static void
206_dbus_signal_feed_del(void *data, Eina_Stringshare *url)
207{
208 _cache_refresh((long)data);
209 eina_hash_del_by_key(feeds[(long)data], url);
210}
211
212static void
213_dbus_signal_feed_updated(void *data, Eina_Stringshare *url, unsigned int num)
214{
215 long conn = (long)data;
216 Rss_Feed *feed;
217
218 feed = eina_hash_find(feeds[conn], url);
219 if (!feed)
220 {
221 fprintf(stderr, EINA_COLOR_RED "%s not one of our feeds!\n" EINA_COLOR_RESET, url);
222 return;
223 }
224 _cache_refresh((long)data);
225 _feed_update(feed, !!num);
226 if (num) _feed_items_update(feed);
227}
228
229static void
230_dbus_view_change(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
231{
232 /* FIXME: probably want to keep both lists in a naviframe or something */
233 elm_genlist_clear(feed_list);
234 elm_object_disabled_set(button_del, 1);
235 if (feeds[dbus_view])
236 eina_hash_foreach(feeds[dbus_view], (Eina_Hash_Foreach)_feed_foreach_cb, (void*)dbus_view);
237}
238
239static void
240_dbus_feeds_list_cb(void *data, const Eina_List *ret)
241{
242 int conn = (long)data;
243 const Eina_List *l;
244 Eina_Stringshare *url;
245
246 if (feeds[conn]) return;
247 feeds[conn] = eina_hash_string_superfast_new((Eina_Free_Cb)_feed_free);
248 EINA_LIST_FOREACH(ret, l, url)
249 _feed_new(url, conn);
250}
251
252static void
253_list_update(void)
254{
255 if (feeds[dbus_view])
256 eina_hash_foreach(feeds[dbus_view], (Eina_Hash_Foreach)_feed_foreach_cb, (void*)dbus_view);
257 else
258 erssd_util_feeds_list(dbus_view, _dbus_feeds_list_cb, (void*)dbus_view);
259}
260
261static void
262_dbus_cachefile_cb(void *data, Eina_Stringshare *cfile)
263{
264 int conn = (long)data;
265 eina_stringshare_replace(&cachefile[conn], cfile);
266 _cache_refresh(conn);
267 if (dbus_view == conn) _list_update();
268}
269
270static void
271_dbus_nameowner_cb(void *data, Eina_Bool nameowned)
272{
273 int conn = (long)data;
274 dbus_connected[conn] = nameowned;
275 if (dbus_connected[conn])
276 {
277 if (!ef_cache[conn])
278 erssd_util_feed_cachefile_get(conn, _dbus_cachefile_cb, data);
279 }
280 else
281 {
282 if (ef_cache[conn])
283 eet_close(ef_cache[conn]);
284 ef_cache[conn] = NULL;
285 }
286 if (!dbus_connected[dbus_view])
287 {
288 elm_genlist_clear(feed_list);
289 elm_object_disabled_set(button_del, 1);
290 /* FIXME: overlay fade or something */
291 }
292}
293
294static void
295_add_feed_close_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
296{
297 elm_object_disabled_set(feed_list, 0);
298 elm_object_disabled_set(button_add, 0);
299 elm_object_disabled_set(button_del, !elm_genlist_selected_item_get(feed_list));
300 elm_object_disabled_set(radios[0], 0);
301 elm_object_disabled_set(radios[1], 0);
302 evas_object_del(obj);
303}
304
305static void
306_add_feed_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
307{
308 /* FIXME: should probably check return here */
309 erssd_util_feed_add(dbus_view, elm_entry_entry_get(obj), NULL, NULL);
310 elm_ctxpopup_dismiss(data);
311}
312
313static void
314_add_feed_key_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
315{
316 Evas_Event_Key_Down *ev = event_info;
317
318 if (!strcmp(ev->keyname, "Escape")) elm_ctxpopup_dismiss(data);
319}
320
321static void
322_add_feed(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
323{
324 Evas_Object *ctx, *entry, *box, *win;
325 int x, y, w, h;
326
327 win = elm_object_top_widget_get(obj);
328
329 evas_object_geometry_get(win, NULL, NULL, &w, &h);
330 box = elm_box_add(win);
331 edje_extern_object_min_size_set(box, 50, 24);
332 EXPAND(box);
333 FILL(box);
334
335 entry = elm_entry_add(win);
336 elm_entry_line_wrap_set(entry, ELM_WRAP_MIXED);
337 elm_entry_single_line_set(entry, 1);
338 elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
339 EXPAND(entry);
340 FILL(entry);
341 elm_box_pack_end(box, entry);
342 evas_object_show(entry);
343
344 evas_object_show(box);
345
346 ctx = elm_ctxpopup_add(win);
347 evas_object_smart_callback_add(ctx, "dismissed", _add_feed_close_cb, NULL);
348 elm_object_content_set(ctx, box);
349 evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y);
350 evas_object_show(ctx);
351 evas_object_move(ctx, x, y);
352
353 evas_object_smart_callback_add(entry, "activated", _add_feed_cb, ctx);
354 evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, _add_feed_key_cb, ctx);
355
356 elm_object_disabled_set(feed_list, 1);
357 elm_object_disabled_set(button_add, 1);
358 elm_object_disabled_set(button_del, 1);
359 elm_object_disabled_set(radios[0], 1);
360 elm_object_disabled_set(radios[1], 1);
361 elm_object_focus_set(entry, 1);
362}
363
364static void
365_del_feed(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
366{
367 Elm_Object_Item *it;
368 Rss_Feed *feed;
369
370 it = elm_genlist_selected_item_get(feed_list);
371 if (!it) return; //should be impossible here
372 feed = elm_object_item_data_get(it);
373 erssd_util_feed_del(dbus_view, feed->url, NULL, NULL);
374 elm_object_disabled_set(button_del, 1);
375}
376
377static void
378_quit_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
379{
380 ecore_main_loop_quit();
381}
382
383int
384main(int argc, char *argv[])
385{
386 Evas_Object *win, *grp, *hbox, *vbox, *o;
387