#include "notificationsimpl.h" #include "wrap/domparser.h" #include "xsltStreamSerializer.h" #include #include #include #include #include #include #define BADCAST(str) reinterpret_cast(str) namespace Gentoo::Service { xmlDocPtr xsltDocLoaderFunc(const xmlChar * URI, xmlDictPtr, int, void *, xsltLoadType) { #define MATCH(name) \ if (xmlStrcmp(URI, BADCAST(#name ".xslt")) == 0) { \ return xmlParseMemory(reinterpret_cast(name##_xslt), static_cast(name##_xslt_len)); \ } MATCH(base) MATCH(news) MATCH(signup) return nullptr; #undef MATCH } Notifications::Notifications() { xsltSetLoaderFunc(&xsltDocLoaderFunc); news = xsltSSPtr(xsltParseStylesheetFile(BADCAST("news.xslt")), xsltFreeStylesheet); signup = xsltSSPtr(xsltParseStylesheetFile(BADCAST("signup.xslt")), xsltFreeStylesheet); xsltSetLoaderFunc(nullptr); } IceTray::Mail::EmailPtr Notifications::getSignup(const Gentoo::NewUserPtr & u) { auto e = basicMail("Welcome", u); Slicer::SerializeAny(u, e, signup.get()); return e; } IceTray::Mail::EmailPtr Notifications::getNews(const Gentoo::UserPtr & u, const Gentoo::NewsContent & c) { auto e = basicMail("Latest updates", u); Slicer::SerializeAny(c, e, news.get()); return e; } IceTray::Mail::EmailPtr Notifications::basicMail(const std::string & subject, const Gentoo::UserPtr & u) { auto e = std::make_shared(); e->subject = "Gentoo Browse: " + subject; e->from.name = "Gentoo Browse"; e->from.address = "noreply@gentoobrowse.randomdan.homeip.net"; e->to.name = u->userrealname; e->to.address = u->useremail; return e; } }