1
0

BoilerplateResponder.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "subnode/BoilerplateResponder.h"
  16. #include "util/Identity.h"
  17. struct BoilerplateResponder_pvt
  18. {
  19. struct BoilerplateResponder pub;
  20. struct EncodingScheme* myScheme;
  21. String* mySchemeStr;
  22. Identity
  23. };
  24. void BoilerplateResponder_addBoilerplate(struct BoilerplateResponder* br,
  25. Dict* msgDict,
  26. struct Address* src,
  27. struct Allocator* alloc)
  28. {
  29. struct BoilerplateResponder_pvt* brp = Identity_check((struct BoilerplateResponder_pvt*) br);
  30. Dict_putStringC(msgDict, "es", brp->mySchemeStr, alloc);
  31. int encIdx = EncodingScheme_getFormNum(brp->myScheme, src->path);
  32. Assert_true(encIdx != EncodingScheme_getFormNum_INVALID);
  33. Dict_putIntC(msgDict, "ei", encIdx, alloc);
  34. }
  35. struct BoilerplateResponder* BoilerplateResponder_new(struct EncodingScheme* myScheme,
  36. struct Allocator* allocator)
  37. {
  38. struct Allocator* alloc = Allocator_child(allocator);
  39. struct BoilerplateResponder_pvt* brp =
  40. Allocator_calloc(alloc, sizeof(struct BoilerplateResponder_pvt), 1);
  41. Identity_set(brp);
  42. brp->myScheme = myScheme;
  43. brp->mySchemeStr = EncodingScheme_serialize(myScheme, alloc);
  44. return &brp->pub;
  45. }