{"id":20181430,"url":"https://github.com/ac000/libflate","last_synced_at":"2025-04-10T05:09:42.391Z","repository":{"id":18664141,"uuid":"21872187","full_name":"ac000/libflate","owner":"ac000","description":"A HTML template library for C by Fabien Menemenlis","archived":false,"fork":false,"pushed_at":"2025-03-23T15:30:34.000Z","size":49,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T05:09:37.641Z","etag":null,"topics":["c","html","library","template"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ac000.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-15T19:05:30.000Z","updated_at":"2025-04-09T07:46:28.000Z","dependencies_parsed_at":"2022-07-16T12:54:33.284Z","dependency_job_id":null,"html_url":"https://github.com/ac000/libflate","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac000%2Flibflate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac000%2Flibflate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac000%2Flibflate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ac000%2Flibflate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ac000","download_url":"https://codeload.github.com/ac000/libflate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161273,"owners_count":21057555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","html","library","template"],"created_at":"2024-11-14T02:35:30.517Z","updated_at":"2025-04-10T05:09:42.383Z","avatar_url":"https://github.com/ac000.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"FLATE Library (Fast Template 2.0.2)\nUpdates \u0026 fixes by Andrew Clayton \u003cac@sigsegv.uk\u003e\n\nFLATE Library (Fast Template 2.0.1)\n(c) Fabien MENEMENLIS (nihilist@dead-inside.org)\n\nThis program is released under the LGPL License. For copying information\nsee the file COPYING.\n\n\n1. Description\n\nFLATE is a library used to handle HTML template files outside C code as well as\nbasic CGI input/output such as retrieving variables from HTML forms or cookies.\nTemplate files can be manipulated from the C code with various functions to\nchange variables and display or hide part of the HTML code. The best way to\nsum it up would be that printf(\"\u003chtml\u003ehello\u003c/html\u003e\"); is now history.\n\n\n2. Installation\n\nSimply do a \"make\" in the root directory of the archive. The resulting library\nshould be linked with your C cgi:\ngcc cgi.c -o cgi -L/path/to/Flate -I/path/to/Flate -lflate\n\n\n3. Changes\n\nFlate 2.0 breaks compatibility with version 1.4 as it can now handle more than\na template file in memory at a time. Perl support has also been removed due to\nmy lack of interest for this language.\n\n\n4. Documentation\n\n4.1. HTML Code\n\nA few extensions have been added to the HTML language so that you can easily\nmodify the code from your C application.\n##variable## is a text zone that will be replaced by the value you want when you\ncall flateSetVar(f, \"variable\", \"value\");\n\u003c!-- #BEGINZONE myzone --\u003e\u003chtml code goes here\u003e\u003c!-- #ENDZONE myzone --\u003e is a\nzone that will be hidden until you call flateSetVar(f, \"myzone\", \"\");\n\u003c!-- #BEGINTABLE mytable --\u003e\u003chtml code\u003e\u003c!-- #ENDTABLE mytable --\u003e is a zone\nthat will be displayed as many times as you call the function\nflateDumpTableLine(f, \"mytable\");\n\n\n4.2 Sample HTML code\n\n\u003chtml\u003e\n\u003ch1\u003e\n  ##title##\n\u003c/h1\u003e\n\u003cbody\u003e\n\u003cp\u003e\n\n\u003c!-- let's imagine you either want to show on your page a sun if it's daytime\n     or a moon if it's nighttime --\u003e\n\u003c!-- #BEGINZONE sunzone --\u003e\n  \u003cimg src=\"sun.png\"\u003e\n\u003c!-- #ENDZONE sunzone --\u003e\n\u003c!-- #BEGINZONE moonzone --\u003e\n  \u003cimg src=\"moon.png\"\u003e\n\u003c!-- #ENDZONE moonzone --\u003e\n\n\u003c!-- the following will display a table with 2 columns and will be fed by\n     the CGI --\u003e\n\u003cp\u003e\nThe following events are recorded in your database:\n\u003ctable\u003e\n\u003c!-- #BEGINTABLE dbline --\u003e\n\u003ctr\u003e\n  \u003ctd\u003e\n    ##number##\n  \u003c/td\u003e\n  \u003ctd\u003e\n    ##value##\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003c!-- #ENDTABLE dbline --\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n\n\nYou can nest tables inside tables, variables and zones inside other zones etc.\n\nYou can use the tool \"checktpl\" to check if your HTML template is valid\n(when the code gets complex it's easy to mispell a zone or table name: this\nwould result in the page not being displayed correctly, or even not at all).\n\nYou can also include external template files using\n\u003c!-- #INCLUDEFILE /path/to/otherfile.html --\u003e\nNote that that path is relative to the SERVER_ROOT variable set in your\nApache/web server environment (this wasn't true with Flate 1.4).\n\n\n4.3. Template functions\n\nYou first need to include \"flate.h\" in your program.\nEach template in memory will be allocated in a Flate structure that you have\nto declare:\nFlate *f = NULL;\nIt must be set to NULL, or the function freeing the structure will be called,\nleading to a crash if *f points to a random pointer.\n\nflateSetFile(\u0026f, \"template.html\");\n  will load the file into memory and initialize the f template.\n\nflateSetVar(f, \"variable\", \"value\", fmt_func);\n  will set ##variable## in the HTML template to \"value\". If fmt_func is\n  not NULL, value will be passed to fmt_func and the value returned from\n  fmt_func will be used. This can be used to render XSS attacks void.\n\nflateSetVar(f, \"myzone\", \"\", NULL);\n  will display the block between\n    \u003c!-- #BEGINZONE myzone --\u003e \u003c!-- #ENDZONE myzone --\u003e\n\nflateDumpTableLine(f, \"dbline\");\n  will print the zone between #BEGINTABLE and #ENDTABLE, with the variables\n  set before. Once printed, the variables are set to NULL again, you can\n  reuse flateSetVar(f, \"variable\", \"value\"); to set them for the next\n  flateDumpTableLine(f, \"dbline\");\n\nOnce you're done, you can use:\nflatePrint(f, \"text/html\");\n  this will output the whole page (the result) to stdout with the given content\ntype.\nYou can also populate a buffer with char *buf = flatePage(f);\nthis will dump the output in a buffer pointed by buf. You need to free(buf);\nafter using this function.\n\nflateFreeMem(f);\n  will free all memory used by the f template.\n\n\n4.4. Form reading\n\nFlate 2.0 can easily retrieve variables from HTML Forms passed with the GET or\nPOST method indifferently.\nYou must first declare a FlateForm structure:\nFlateForm *form = NULL;\n\nYou have then two methods to pass the variables you want to retrieve:\n\n- add them one by one with the flateAddForm() function:\n  form = firstfield = flateAddForm(form, \"variable\", 50, isalnum);\n  \"variable\" is the variable name in the HTML Form, 50 the maximum length of\n  the string and isalnum a function called to check the validity of the\n  characters passed in the form, or NULL if you don't want to check the user\n  input.\n  You would add another variable with\n  form = secondfield = flateAddForm(form, \"second\", 30, NULL);\n  (this is a linked list so you need to point flateAddForm() to \"form\" every\n  time you add a variable)\n\n- pass a single string with all the variables:\n  char *s;\n  s = strdup(\"variable,50:second,30\");\n  form = flateSetForm(s);\n  free(s);\n  Note that the s string will be modified by flateSetForm() so you cannot do\n  a simple char *s = \"variable,50:second,30\"; as the string declared this way\n  is read only.\n\nOnce you have set the variables you want to retrieve, call flateReadForm(form);\nto populate the internal buffers with the HTML form values.\n\nTo access the variables values, if you have used flateAddForm() you can\ndirectly access firstfield-\u003evalue for the first variable or second-\u003evalue for\nthe second: they will contain the variables passed with the GET or POST methods\n(as a char * type) or NULL if the form does not contain these variable names.\nIf you have used flateSetForm() you can get the variable value with\nchar *val = flateGetForm(form, \"variable\");\n\n\n4.5. Cookies manipulation\n\nCookies manipulation is really basic but I included these functions for people\nlike me who always forget about the format of HTTP cookies:\n\nflateSetCookie(Flate *f, char *name, char *value, char *domain, time_t expires);\nexpires is in seconds or 0 for a session cookie or -1 to remove it\ncookies are set in the HTTP headers so they will be set when flatePrint() is\ncalled.\n\nflateGetCookie(char *value, int valuesz, char *cookie, check_function);\nwill retrieve the cookie named in \"cookie\" inside the \"value\" buffer if\ncharacters matches the check_function() or NULL when no checking is wanted.\nExample:\nchar cookie[50 + 1];\nflateGetCookie(cookie, 50, \"mycookie\", isdigit);\n\nNote that flateSetCookie() is bound to a Flate structure, so you have to call\nflateSetFile() with a template file first. It might be a problem if you don't\nwant to print anything after you have set a cookie and instead need to do\na redirect, but I've not come accross a better API idea yet.\n\n\n5. Suggestions and bug reports\n\nYou can reach me at the following address: nihilist \u003cat\u003e dead-inside.org if\nyou have any question or want to report a bug.\n\nFabien MENEMENLIS\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fac000%2Flibflate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fac000%2Flibflate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fac000%2Flibflate/lists"}