#include #include "dbms/htp.h" #include #include #include "dbms/owa.h" extern "C" { #include "utils/builtins.h" #include "utils/elog.h" #include "mb/pg_wchar.h" #include "lib/stringinfo.h" } static std::string html_buffer{}; bool test_mode = false; namespace htp{ typedef enum StringEscapeFormat{ StringEscapeFormatNone, StringEscapeFormatSpecialChars, // xmlEncodeSpecialChars из libxml2 StringEscapeFormatOracle, // oracle-style from htp StringEscapeFormatOracleFull, // oracle-style + for symbol "<>& - ", &qt; ... etc. StringEscapeLtGtChars // escape only <> symbols (used for tag attributes) } StringEscapeFormat; void html_buffer_add(const char *str){ if (test_mode) { html_buffer.clear(); } html_buffer.append(str); html_buffer.push_back('\n'); ereport(NOTICE, (errmsg("HTML: \n%s", html_buffer.c_str()))); } // Вспомогательная функция для одиночного указателя template static inline void pfree_if_not_null(T*& ptr) { if (ptr != NULL) { pfree(ptr); ptr = NULL; // предотвращает случайное повторное освобождение } } // Вариативный шаблон для произвольного числа аргументов (по ссылке) template static void pfree_all(Args&... args) { (pfree_if_not_null(args), ...); } // латинские буквы, _,-, цифры - оставляем как есть, остальное экранируем // full - смешанный стиль (дополняется тем, что для односимвольного текста стандартное xml экранирование) char * escape_to_numeric_entity(text *input, bool full = false) { const char *data = VARDATA_ANY(input); int len = VARSIZE_ANY_EXHDR(input); StringInfoData result; /* Инициализация буфера для результата */ initStringInfo(&result); if (len == 0) return result.data; int encoding = GetDatabaseEncoding(); int byte_pos = 0; while (byte_pos < len) { int char_len = pg_encoding_mblen(encoding, data + byte_pos); if (char_len <= 0 || byte_pos + char_len > len) break; if (char_len == 1) { unsigned char c = data[byte_pos]; if(full) { if(c == '"'){ appendStringInfo(&result, """); byte_pos += char_len; continue; } if(c == '<'){ appendStringInfo(&result, "<"); byte_pos += char_len; continue; } if(c == '>'){ appendStringInfo(&result, ">"); byte_pos += char_len; continue; } if(c == '&'){ appendStringInfo(&result, "&"); byte_pos += char_len; continue; } if(c<='~'){ appendStringInfoChar(&result, c); byte_pos += char_len; continue; } } if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '-' || c == '.' || c == ',') { appendStringInfoChar(&result, c); byte_pos += char_len; continue; } } /* Для однобайтовых небезопасных и многобайтовых — декодируем */ pg_wchar wc_buf[2]; int conv = pg_mb2wchar_with_len(data + byte_pos, wc_buf, char_len); if (conv > 0){ int digits = 1; unsigned int temp = wc_buf[0]; while (temp > 15) { temp >>= 4; digits++; } // Если цифр нечётное - увеличиваем на 1 (добавим один ведущий ноль) if (digits % 2 != 0) { digits++; } appendStringInfo(&result, "&#x%0*X;", digits, (unsigned int) wc_buf[0]); } else appendStringInfoChar(&result, '?'); byte_pos += char_len; } return result.data; } char *escape_special_chars(text *input){ if(input == NULL) return NULL; char *str = text_to_cstring(input); xmlBufferPtr buf = xmlBufferCreate(); if (!buf) return NULL; xmlOutputBufferPtr out = xmlOutputBufferCreateBuffer(buf, NULL); if (!out) { xmlBufferFree(buf); return NULL; } xmlChar *escaped_code = xmlEncodeSpecialChars(NULL, (xmlChar*)str); xmlOutputBufferWriteString(out, (char*)escaped_code); xmlFree(escaped_code); pfree(str); xmlOutputBufferFlush(out); const xmlChar *content = xmlBufferContent(buf); size_t len = xmlBufferLength(buf); char *result = (char*)palloc(len + 1); if (result) { memcpy(result, content, len); result[len] = '\0'; } xmlOutputBufferClose(out); // также освобождает buf return result; // освобождать через pfree() } char *escape_ltgt_chars(text *input){ if (input == nullptr) { return nullptr; } const char *data = VARDATA_ANY(input); int len = VARSIZE_ANY_EXHDR(input); int byte_pos = 0; StringInfoData result; initStringInfo(&result); if (len == 0) { return result.data; } // processing as ASCII as it is considered to be ASCII (observation from tests) while (byte_pos < len) { if (data[byte_pos] == '<') { appendStringInfo(&result, "<"); } else if (data[byte_pos] == '>') { appendStringInfo(&result, ">"); } else { appendStringInfoChar(&result, data[byte_pos]); } byte_pos++; } return result.data; } char * get_string_argument(FunctionCallInfo fcinfo, int argnum, StringEscapeFormat type = StringEscapeFormatNone) { if (PG_ARGISNULL(argnum)) return NULL; text *arg_txt = PG_GETARG_TEXT_PP(argnum); char *result = NULL; if (VARSIZE_ANY_EXHDR(arg_txt) == 0) return NULL; switch(type){ case StringEscapeFormatSpecialChars: result = escape_special_chars(arg_txt); break; case StringEscapeFormatOracle: result = escape_to_numeric_entity(arg_txt); break; case StringEscapeFormatOracleFull: result = escape_to_numeric_entity(arg_txt, true); break; case StringEscapeLtGtChars: result = escape_ltgt_chars(arg_txt); break; default: result = text_to_cstring(arg_txt); break; } return result; } static char * get_numeric_argument_as_string(FunctionCallInfo fcinfo, int argnum) { /* Проверяем, не NULL ли аргумент */ if (PG_ARGISNULL(argnum)) return NULL; /* Получаем Datum с аргументом типа NUMERIC */ Datum numeric_datum = PG_GETARG_DATUM(argnum); /* Преобразуем NUMERIC в C-строку через выходную функцию типа */ Datum str_datum = DirectFunctionCall1(numeric_out, numeric_datum); /* Возвращаем строку (char* уже в памяти palloc) */ return DatumGetCString(str_datum); } char* generate_applet_tag(const char *code, int width, bool width_is_set, int height, bool height_is_set, const char *other_attrs) { xmlBufferPtr buf = xmlBufferCreate(); if (!buf) return NULL; xmlOutputBufferPtr out = xmlOutputBufferCreateBuffer(buf, NULL); if (!out) { xmlBufferFree(buf); return NULL; } // xmlOutputBufferWriteString(out, ""); xmlOutputBufferFlush(out); const xmlChar *content = xmlBufferContent(buf); size_t len = xmlBufferLength(buf); char *result = (char*)palloc(len + 1); if (result) { memcpy(result, content, len); result[len] = '\0'; } xmlOutputBufferClose(out); // также освобождает buf return result; // освобождать через pfree() } char *generate_blockquote_tag(bool cnowrap, const char *cclear, const char * cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_body_tag(const char *cbackground, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_dlist_tag(const char *cclear, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_form_tag(const char *curl, const char *cmethod, const char *ctarget, const char *cenctype, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_font_tag(const char *ccolor, const char *cface, const char *csize, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_formselect_tag(const char *cname, const char *cprompt, const char *csize, const char *cattributes){ StringInfo result = makeStringInfo(); if(cprompt){ appendStringInfo(result, " %s", cprompt); } appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_textarea_tag(const char *cname, const char *crows, const char *ccols, const char * calign, const char *cattributes, const char *cwrap = NULL){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_frameset_tag(const char *crows, const char *ccols, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_map_tag(const char *cname, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_olist_tag(const char *cclear, const char* cwrap, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_pre_tag(const char *cclear, const char* cwidth, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_table_tag(const char *cborder, const char* calign, const char *cnowrap, const char* cclear, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_tablerow_tag(const char *calign, const char* cvalign, const char *cdp, const char* cnowrap, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_ulist_tag(const char *cclear, const char* cwrap, const char *cdingbat, const char* csrc, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_checkbox_tag(const char *cname, const char *cvalue, const char* cchecked, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } void append_attribute(StringInfo res, const char *name, const char *value){ if(name){ if(value) appendStringInfo(res, " %s=\"%s\"", name, value); } } void append_attribute_chk_len(StringInfo res, const char *tag_name, const char *tag_value) noexcept { if(tag_name != nullptr) { if(tag_value != nullptr && strlen(tag_value)) { appendStringInfo(res, " %s=\"%s\"", tag_name, tag_value); } } } char* generate_file_tag(const char *cname, const char *caccept, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_hidden_tag(const char *cname, const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_image_tag(const char *cname, const char *csrc, const char *calign, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_password_tag(const char *cname, const char *csize, const char *cmaxlength, const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_radio_tag(const char *cname, const char *cvalue, const char *cchecked, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_reset_tag(const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_selectoption_tag(const char *cvalue, const char *cselected, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", cvalue ? cvalue : ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_submit_tag(const char *cname, const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_formtext_tag(const char *cname, const char *csize, const char *cmaxlength, const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_formtextarea_tag(const char *cname, const char *crows, const char *ccolumns, const char *calign, const char *cattributes, const char *cwrap = NULL){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_address_tag(const char *cvalue, const char *cnowrap, const char *cclear, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", cvalue ? cvalue : ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_anchor_tag(const char *curl, const char *ctext, const char *cname, const char *cattributes, const char *ctarget = NULL){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_area_tag(const char *ccoord, const char *cshape, const char *chref, const char *cnohref, const char *ctarget, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_em_tag(const char *ctext, const char *cattributes) noexcept { char *result = nullptr; constexpr int em_tag_len = 10; // is 10 symbols int ctext_len = 0; int cattr_len = 0; bool inc_space = false; if (ctext != nullptr) { ctext_len = strlen(ctext); } if (cattributes != nullptr) { cattr_len = strlen(cattributes); if (cattr_len) { inc_space = true; } } result = (char*)palloc0(ctext_len + cattr_len + em_tag_len + 1); sprintf(result, "%s", inc_space ? " " : "", cattributes ? cattributes : "", ctext ? ctext : ""); return result; } char* generate_frame_tag(const char *csrc, const char *cname, const char *cmarginwidth, const char *cmarginheight, const char *cscrolling, const char *cnoresize, const char *cattributes) noexcept { StringInfo result = makeStringInfo(); appendStringInfo(result, ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_header_tag(int32 clevel, bool clevel_is_set, const char *cheader, const char *calign, const char *cnowrap, const char *cclear, const char *cattributes) noexcept { StringInfo result = makeStringInfo(); char clevel_str[1 + 1] = {0}; if (clevel_is_set) { if (clevel < 0) { clevel *= -1; } if (clevel > 6) { clevel = 6; } sprintf(clevel_str, "%d", clevel); } appendStringInfo(result, "%s", cheader ? cheader : "", clevel_str); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } char* generate_dlistterm_tag(const char *ctext, const char *cclear, const char *cattributes) noexcept { StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); char *ret = pstrdup(result->data); destroyStringInfo(result); return ret; } }// end namespace htp extern "C" { PG_FUNCTION_INFO_V1(htp_enable_test_mode); PG_FUNCTION_INFO_V1(htp_adddefaulthtmlhdr); PG_FUNCTION_INFO_V1(htp_address); PG_FUNCTION_INFO_V1(htp_anchor); PG_FUNCTION_INFO_V1(htp_anchor2); PG_FUNCTION_INFO_V1(htp_appletopen); PG_FUNCTION_INFO_V1(htp_area); PG_FUNCTION_INFO_V1(htp_base); PG_FUNCTION_INFO_V1(htp_basefont); PG_FUNCTION_INFO_V1(htp_bgsound); PG_FUNCTION_INFO_V1(htp_big); PG_FUNCTION_INFO_V1(htp_blockquoteopen); PG_FUNCTION_INFO_V1(htp_bodyopen); PG_FUNCTION_INFO_V1(htp_bold); PG_FUNCTION_INFO_V1(htp_br); PG_FUNCTION_INFO_V1(htp_center); PG_FUNCTION_INFO_V1(htp_cite); PG_FUNCTION_INFO_V1(htp_code); PG_FUNCTION_INFO_V1(htp_comment); PG_FUNCTION_INFO_V1(htp_dfn); PG_FUNCTION_INFO_V1(htp_div); PG_FUNCTION_INFO_V1(htp_dlistdef); PG_FUNCTION_INFO_V1(htp_dlistopen); PG_FUNCTION_INFO_V1(htp_dlistterm); PG_FUNCTION_INFO_V1(htp_download_file); PG_FUNCTION_INFO_V1(htp_em); PG_FUNCTION_INFO_V1(htp_emphasis); PG_FUNCTION_INFO_V1(htp_escape_oracle_full); PG_FUNCTION_INFO_V1(htp_escape_sc); PG_FUNCTION_INFO_V1(htp_flush_charset_convert); PG_FUNCTION_INFO_V1(htp_fontopen); PG_FUNCTION_INFO_V1(htp_formcheckbox); PG_FUNCTION_INFO_V1(htp_formfile); PG_FUNCTION_INFO_V1(htp_formhidden); PG_FUNCTION_INFO_V1(htp_formimage); PG_FUNCTION_INFO_V1(htp_formopen); PG_FUNCTION_INFO_V1(htp_formpassword); PG_FUNCTION_INFO_V1(htp_formradio); PG_FUNCTION_INFO_V1(htp_formreset); PG_FUNCTION_INFO_V1(htp_formselectopen); PG_FUNCTION_INFO_V1(htp_formselectoption); PG_FUNCTION_INFO_V1(htp_formsubmit); PG_FUNCTION_INFO_V1(htp_formtext); PG_FUNCTION_INFO_V1(htp_formtextarea); PG_FUNCTION_INFO_V1(htp_formtextarea2); PG_FUNCTION_INFO_V1(htp_formtextareaopen); PG_FUNCTION_INFO_V1(htp_formtextareaopen2); PG_FUNCTION_INFO_V1(htp_frame); PG_FUNCTION_INFO_V1(htp_framesetopen); PG_FUNCTION_INFO_V1(htp_get_download_files_list); PG_FUNCTION_INFO_V1(htp_get_line); PG_FUNCTION_INFO_V1(htp_get_page); PG_FUNCTION_INFO_V1(htp_get_page_charset_convert); PG_FUNCTION_INFO_V1(htp_get_page_raw); PG_FUNCTION_INFO_V1(htp_header); PG_FUNCTION_INFO_V1(htp_hr); PG_FUNCTION_INFO_V1(htp_htitle); PG_FUNCTION_INFO_V1(htp_img); PG_FUNCTION_INFO_V1(htp_img2); PG_FUNCTION_INFO_V1(htp_isindex); PG_FUNCTION_INFO_V1(htp_italic); PG_FUNCTION_INFO_V1(htp_kbd); PG_FUNCTION_INFO_V1(htp_keyboard); PG_FUNCTION_INFO_V1(htp_line); PG_FUNCTION_INFO_V1(htp_linkrel); PG_FUNCTION_INFO_V1(htp_linkrev); PG_FUNCTION_INFO_V1(htp_listheader); PG_FUNCTION_INFO_V1(htp_listitem); PG_FUNCTION_INFO_V1(htp_mailto); PG_FUNCTION_INFO_V1(htp_mapopen); PG_FUNCTION_INFO_V1(htp_meta); PG_FUNCTION_INFO_V1(htp_nextid); PG_FUNCTION_INFO_V1(htp_nl); PG_FUNCTION_INFO_V1(htp_nobr); PG_FUNCTION_INFO_V1(htp_olistopen); PG_FUNCTION_INFO_V1(htp_p_ovr1); PG_FUNCTION_INFO_V1(htp_p_ovr2); PG_FUNCTION_INFO_V1(htp_p_ovr3); PG_FUNCTION_INFO_V1(htp_paragraph); PG_FUNCTION_INFO_V1(htp_param); PG_FUNCTION_INFO_V1(htp_plaintext); PG_FUNCTION_INFO_V1(htp_preopen); PG_FUNCTION_INFO_V1(htp_print_ovr1); PG_FUNCTION_INFO_V1(htp_print_ovr2); PG_FUNCTION_INFO_V1(htp_print_ovr3); PG_FUNCTION_INFO_V1(htp_prints); PG_FUNCTION_INFO_V1(htp_print_header); PG_FUNCTION_INFO_V1(htp_prn_ovr1); PG_FUNCTION_INFO_V1(htp_prn_ovr2); PG_FUNCTION_INFO_V1(htp_prn_ovr3); PG_FUNCTION_INFO_V1(htp_ps); PG_FUNCTION_INFO_V1(htp_putraw); PG_FUNCTION_INFO_V1(htp_s); PG_FUNCTION_INFO_V1(htp_sample); PG_FUNCTION_INFO_V1(htp_script); PG_FUNCTION_INFO_V1(htp_sethttpcharset); PG_FUNCTION_INFO_V1(htp_set_transfer_mode); PG_FUNCTION_INFO_V1(htp_small); PG_FUNCTION_INFO_V1(htp_strike); PG_FUNCTION_INFO_V1(htp_strong); PG_FUNCTION_INFO_V1(htp_style); PG_FUNCTION_INFO_V1(htp_sub); PG_FUNCTION_INFO_V1(htp_sup); PG_FUNCTION_INFO_V1(htp_tablecaption); PG_FUNCTION_INFO_V1(htp_tabledata); PG_FUNCTION_INFO_V1(htp_tableheader); PG_FUNCTION_INFO_V1(htp_tableopen); PG_FUNCTION_INFO_V1(htp_tablerowopen); PG_FUNCTION_INFO_V1(htp_teletype); PG_FUNCTION_INFO_V1(htp_title); PG_FUNCTION_INFO_V1(htp_ulistopen); PG_FUNCTION_INFO_V1(htp_underline); PG_FUNCTION_INFO_V1(htp_variable); PG_FUNCTION_INFO_V1(htp_appletclose); PG_FUNCTION_INFO_V1(htp_blockquoteclose); PG_FUNCTION_INFO_V1(htp_bodyclose); PG_FUNCTION_INFO_V1(htp_centerclose); PG_FUNCTION_INFO_V1(htp_centeropen); PG_FUNCTION_INFO_V1(htp_dirlistclose); PG_FUNCTION_INFO_V1(htp_dirlistopen); PG_FUNCTION_INFO_V1(htp_dlistclose); PG_FUNCTION_INFO_V1(htp_flush); PG_FUNCTION_INFO_V1(htp_fontclose); PG_FUNCTION_INFO_V1(htp_formclose); PG_FUNCTION_INFO_V1(htp_formselectclose); PG_FUNCTION_INFO_V1(htp_formtextareaclose); PG_FUNCTION_INFO_V1(htp_framesetclose); PG_FUNCTION_INFO_V1(htp_headclose); PG_FUNCTION_INFO_V1(htp_headopen); PG_FUNCTION_INFO_V1(htp_htmlclose); PG_FUNCTION_INFO_V1(htp_htmlopen); PG_FUNCTION_INFO_V1(htp_init); PG_FUNCTION_INFO_V1(htp_listingclose); PG_FUNCTION_INFO_V1(htp_listingopen); PG_FUNCTION_INFO_V1(htp_mapclose); PG_FUNCTION_INFO_V1(htp_menulistclose); PG_FUNCTION_INFO_V1(htp_menulistopen); PG_FUNCTION_INFO_V1(htp_noframesclose); PG_FUNCTION_INFO_V1(htp_noframesopen); PG_FUNCTION_INFO_V1(htp_olistclose); PG_FUNCTION_INFO_V1(htp_para); PG_FUNCTION_INFO_V1(htp_preclose); PG_FUNCTION_INFO_V1(htp_reset_get_page); PG_FUNCTION_INFO_V1(htp_showpage); PG_FUNCTION_INFO_V1(htp_tableclose); PG_FUNCTION_INFO_V1(htp_tablerowclose); PG_FUNCTION_INFO_V1(htp_ulistclose); PG_FUNCTION_INFO_V1(htp_wbr); /** * @brief TODO: Enable test mode for HTP * @details TODO: Sets test_mode variable to TRUE thus enabling buffer cleaning before any tag adding * * Parameters: * * @param TEST_MODE (in) INT32: turns test mode on/off * * * * * */ Datum htp_enable_test_mode(PG_FUNCTION_ARGS) { int32 mode = PG_GETARG_INT32(0); char msg[13 + 1] = {0}; // "test mode off" if (mode) { test_mode = true; sprintf(msg, "test mode on"); } else { test_mode = false; sprintf(msg, "test mode off"); } htp::html_buffer_add(msg); PG_RETURN_VOID(); } /** * @brief TODO: Добавить описание * @details TODO: Добавить детальное описание * * Parameters: * * @param BADDHTMLHDR (in) BOOLEAN: TODO: Описание параметра BADDHTMLHDR * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_adddefaulthtmlhdr(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.adddefaulthtmlhdr еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates the
and
tags which specify the address, author and signature of a document. * @details This procedure generates the
and
tags which specify the address, author and signature of a document. * * Parameters: * * @param CVALUE (in) VARCHAR2: The string that goes between the
and
tags. * * @param CNOWRAP (in) VARCHAR2: If the value for this parameter is notNULL, theNOWRAPattribute is included in the tag * * @param CCLEAR (in) VARCHAR2: The value for theCLEARattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_address(PG_FUNCTION_ARGS) { char *cvalue = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracleFull); char *cnowrap = htp::get_string_argument(fcinfo, 1); char *cclear = htp::get_string_argument(fcinfo, 2, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 3); char *tag = htp::generate_address_tag(cvalue, cnowrap, cclear, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cvalue, cnowrap, cclear, cattributes, tag); PG_RETURN_VOID(); } /** * @brief Like the ANCHOR2 procedure, this procedure generates theandHTML tags which specify the source or destination of a hypertext link. * @details Like the ANCHOR2 procedure, this procedure generates theandHTML tags which specify the source or destination of a hypertext link. * * Parameters: * * @param CURL (in) VARCHAR2: The value for theHREFattribute. * * @param CTEXT (in) VARCHAR2: The string that goes between theandtags. * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_anchor(PG_FUNCTION_ARGS) { char *curl = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatSpecialChars); char *ctext = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracleFull); char *cname = htp::get_string_argument(fcinfo, 2, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 3); char *tag = htp::generate_anchor_tag(curl, ctext, cname, cattributes); htp::html_buffer_add(tag); htp::pfree_all(curl, ctext, cname, cattributes, tag); PG_RETURN_VOID(); } /** * @brief Like the ANCHOR procedure, this procedure generates theandHTML tags which specify the source or destination of a hypertext link. * @details Like the ANCHOR procedure, this procedure generates theandHTML tags which specify the source or destination of a hypertext link. * * Parameters: * * @param CURL (in) VARCHAR2: The value for theHREFattribute. * * @param CTEXT (in) VARCHAR2: The string that goes between theandtags. * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute * * @param CTARGET (in) VARCHAR2: The value for theTARGETattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_anchor2(PG_FUNCTION_ARGS) { char *curl = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatSpecialChars); char *ctext = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracleFull); char *cname = htp::get_string_argument(fcinfo, 2, htp::StringEscapeFormatOracle); char *ctarget = htp::get_string_argument(fcinfo, 3, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 4); char *tag = htp::generate_anchor_tag(curl, ctext, cname, cattributes, ctarget); htp::html_buffer_add(tag); htp::pfree_all(curl, ctext, cname, ctarget, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag which begins the invocation of a Java applet. * @details This procedure generates thetag which begins the invocation of a Java applet. Specify parameters to the Java applet using thePARAM Procedure. Use thecattributesparameter to specify theCODEBASEattribute since the PL/SQL cartridge does not know where to find the class files. TheCODEBASEattribute specifies the virtual path containing the class files. * * Parameters: * * @param CCODE (in) VARCHAR2: The the value for theCODEattribute which specifies the name of the applet class. * * @param CWIDTH (in) NUMBER: The value for theWIDTHattribute. * * @param CHEIGHT (in) NUMBER: The value for theHEIGHTattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_appletopen(PG_FUNCTION_ARGS) { text *ccode_text = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEXT_PP(0); text *cattributes_text = PG_ARGISNULL(3) ? NULL : PG_GETARG_TEXT_PP(3); Numeric cwidth_num = PG_ARGISNULL(1) ? NULL : PG_GETARG_NUMERIC(1); Numeric cheight_num = PG_ARGISNULL(2) ? NULL : PG_GETARG_NUMERIC(2); char *ccode = NULL; char *cattributes = NULL; int32 cwidth = 0; int32 cheight = 0; bool cwidth_is_set = false; bool cheight_is_set = false; if(cwidth_num){ cwidth = DatumGetInt32(DirectFunctionCall1(numeric_int4, NumericGetDatum(cwidth_num))); cwidth_is_set = true; } if(cheight_num){ cheight = DatumGetInt32(DirectFunctionCall1(numeric_int4, NumericGetDatum(cheight_num))); cheight_is_set = true; } if(ccode_text && VARSIZE_ANY_EXHDR(ccode_text)!=0) { ccode = text_to_cstring(ccode_text); } if(cattributes_text && VARSIZE_ANY_EXHDR(cattributes_text)!=0){ cattributes = text_to_cstring(cattributes_text); } char *tag = htp::generate_applet_tag(ccode, cwidth, cwidth_is_set, cheight, cheight_is_set, cattributes); htp::html_buffer_add(tag); pfree(tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag, which defines a client-side image map. Thetag defines areas within the image and destinations for the areas. * @details This procedure generates thetag, which defines a client-side image map. Thetag defines areas within the image and destinations for the areas. * * Parameters: * * @param CCOORDS (in) VARCHAR2: TODO: Описание параметра CCOORDS * * @param CSHAPE (in) VARCHAR2: The value for theSHAPEattribute. * * @param CHREF (in) VARCHAR2: The value for theHREFattribute. * * @param CNOHREF (in) VARCHAR2: If the value for this parameter is notNULL, theNOHREFattribute is added to the tag. * * @param CTARGET (in) VARCHAR2: The value for theTARGETattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_area(PG_FUNCTION_ARGS) { char *ccoords = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *cshape = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracle); char *chref = htp::get_string_argument(fcinfo, 2, htp::StringEscapeFormatSpecialChars); char *cnohref = htp::get_string_argument(fcinfo, 3, htp::StringEscapeFormatOracle); char *ctarget = htp::get_string_argument(fcinfo, 4, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 5); char *tag = htp::generate_area_tag(ccoords, cshape, chref, cnohref, ctarget, cattributes); htp::html_buffer_add(tag); htp::pfree_all(ccoords, cshape, chref, cnohref, ctarget, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag which records the URL of the document. * @details This procedure generates thetag which records the URL of the document. * * Parameters: * * @param CTARGET (in) VARCHAR2: The value for theTARGETattribute which establishes a window name to which all links in this document are targeted. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_base(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.base еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag which specifies the base font size for a Web page. * @details This procedure generates thetag which specifies the base font size for a Web page. * * Parameters: * * @param NSIZE (in) NUMBER: The value for theSIZEattribute. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_basefont(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.basefont еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag which includes audio for a Web page. * @details This procedure generates thetag which includes audio for a Web page. * * Parameters: * * @param CSRC (in) VARCHAR2: The value for theSRCattribute. * * @param CLOOP (in) VARCHAR2: The value for theLOOPattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_bgsound(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.bgsound еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates theandtags which direct the browser to render the text in a bigger font. * @details This procedure generates theandtags which direct the browser to render the text in a bigger font. * * Parameters: * * @param CTEXT (in) VARCHAR2: The the text that goes between the tags. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_big(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.big еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates the
tag, which marks the beginning of a section of quoted text. * @details This procedure generates the
tag, which marks the beginning of a section of quoted text. * * Parameters: * * @param CNOWRAP (in) VARCHAR2: If the value for this parameter is notNULL, theNOWRAPattribute is added to the tag. * * @param CCLEAR (in) VARCHAR2: The value for theCLEARattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_blockquoteopen(PG_FUNCTION_ARGS) { text *cnowrap_txt = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEXT_PP(0); text *cclear_txt = PG_ARGISNULL(1) ? NULL : PG_GETARG_TEXT_PP(1); text *cattributes_txt = PG_ARGISNULL(2) ? NULL : PG_GETARG_TEXT_PP(2); bool nowrap = false; char *cclear = NULL; char *cattributes = NULL; if(cnowrap_txt && VARSIZE_ANY_EXHDR(cnowrap_txt)!=0) { nowrap = true; } if(cclear_txt && VARSIZE_ANY_EXHDR(cclear_txt)!=0) { cclear = htp::escape_to_numeric_entity(cclear_txt); } if(cattributes_txt && VARSIZE_ANY_EXHDR(cattributes_txt)!=0) { cattributes = text_to_cstring(cattributes_txt); } char *tag = htp::generate_blockquote_tag(nowrap, cclear, cattributes); htp::html_buffer_add(tag); pfree(tag); if(cclear) pfree(cclear); if(cattributes) pfree(cattributes); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag which marks the beginning of the body section of an HTML document. * @details This procedure generates thetag which marks the beginning of the body section of an HTML document. * * Parameters: * * @param CBACKGROUND (in) VARCHAR2: The value for theBACKGROUNDattribute which specifies a graphic file to use for the background of the document. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_bodyopen(PG_FUNCTION_ARGS) { text *cbackground_txt = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEXT_PP(0); text *cattributes_txt = PG_ARGISNULL(1) ? NULL : PG_GETARG_TEXT_PP(1); char *cbackground = NULL; char *cattributes = NULL; if(cbackground_txt && VARSIZE_ANY_EXHDR(cbackground_txt)!=0) { cbackground = htp::escape_to_numeric_entity(cbackground_txt); } if(cattributes_txt && VARSIZE_ANY_EXHDR(cattributes_txt)!=0) { cattributes = text_to_cstring(cattributes_txt); } char *tag = htp::generate_body_tag(cbackground, cattributes); htp::html_buffer_add(tag); pfree(tag); if(cbackground) pfree(cbackground); if(cattributes) pfree(cattributes); PG_RETURN_VOID(); } /** * @brief This procedure generates theandtags which direct the browser to display the text in boldface. * @details This procedure generates theandtags which direct the browser to display the text in boldface. * * Parameters: * * @param CTEXT (in) VARCHAR2: The text that goes between the tags. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_bold(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.bold еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates the
tag which begins a new line of text. * @details This procedure generates the
tag which begins a new line of text. * * Parameters: * * @param CCLEAR (in) VARCHAR2: The value for theCLEARattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_br(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.br еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates the
and
tags which center a section of text within a Web page. * @details This procedure generates the
and
tags which center a section of text within a Web page. * * Parameters: * * @param CTEXT (in) VARCHAR2: The text that goes between the tags. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_center(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.center еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates theandtags which direct the browser to render the text as a citation. * @details This procedure generates theandtags which direct the browser to render the text as a citation. * * Parameters: * * @param CTEXT (in) VARCHAR2: The text to render as citation. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_cite(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.cite еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates theandtags which direct the browser to render the text in monospace font or however "code" is defined stylistically. * @details This procedure generates theandtags which direct the browser to render the text in monospace font or however "code" is defined stylistically. * * Parameters: * * @param CTEXT (in) VARCHAR2: The text to render as code. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_code(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.code еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates the comment tags. * @details This procedure generates the comment tags. * * Parameters: * * @param CTEXT (in) VARCHAR2: The comment. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_comment(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.comment еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates theandtags which direct the browser to mark the text in italics or however "definition" is described stylistically. * @details This procedure generates theandtags which direct the browser to mark the text in italics or however "definition" is described stylistically. * * Parameters: * * @param CTEXT (in) VARCHAR2: The text to render in italics. * * @param CATTRIBUTES (in) VARCHAR2: TODO: Описание параметра CATTRIBUTES * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_dfn(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.dfn еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates the
tag which creates document divisions. * @details This procedure generates the
tag which creates document divisions. * * Parameters: * * @param CALIGN (in) VARCHAR2: The value for theALIGNattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_div(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.div еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates the
tag, which inserts definitions of terms. Use this tag for a definition list
. Terms are tagged
and definitions are tagged
. * @details This procedure generates the
tag, which inserts definitions of terms. Use this tag for a definition list
. Terms are tagged
and definitions are tagged
. * * Parameters: * * @param CTEXT (in) VARCHAR2: The definition of the term. * * @param CCLEAR (in) VARCHAR2: The value for theCLEARattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_dlistdef(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.dlistdef еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates the
tag which starts a definition list. You end a definition list by means of the DLISTCLOSE Procedure. * @details This procedure generates the
tag which starts a definition list. You end a definition list by means of the DLISTCLOSE Procedure. * * Parameters: * * @param CCLEAR (in) VARCHAR2: The value for theCLEARattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_dlistopen(PG_FUNCTION_ARGS) { text *cclear_txt = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEXT_PP(0); text *cattributes_txt = PG_ARGISNULL(1) ? NULL : PG_GETARG_TEXT_PP(1); char *cclear = NULL; char *cattributes = NULL; if(cclear_txt && VARSIZE_ANY_EXHDR(cclear_txt)!=0) { cclear = htp::escape_to_numeric_entity(cclear_txt); } if(cattributes_txt && VARSIZE_ANY_EXHDR(cattributes_txt)!=0) { cattributes = text_to_cstring(cattributes_txt); } char *tag = htp::generate_dlist_tag(cclear, cattributes); htp::html_buffer_add(tag); pfree(tag); if(cclear) pfree(cclear); if(cattributes) pfree(cattributes); PG_RETURN_VOID(); } /** * @brief This procedure generates the
tag which defines a term in a definition list
. * @details This procedure generates the
tag which defines a term in a definition list
. * * Parameters: * * @param CTEXT (in) VARCHAR2: The term. * * @param CCLEAR (in) VARCHAR2: The value for the CLEAR attribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_dlistterm(PG_FUNCTION_ARGS) { char *ctext = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracleFull); char *cclear = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 2, htp::StringEscapeLtGtChars); char *tag = htp::generate_dlistterm_tag(ctext, cclear, cattributes); htp::html_buffer_add(tag); htp::pfree_all(ctext, cclear, cattributes); PG_RETURN_VOID(); } /** * @brief TODO: Добавить описание * @details TODO: Добавить детальное описание * * Parameters: * * @param SFILENAME (in) VARCHAR2: TODO: Описание параметра SFILENAME * * @param BCOMPRESS (in) BOOLEAN: TODO: Описание параметра BCOMPRESS * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_download_file(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.download_file еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates theandtags, which define text to be emphasized. * @details Generates theandtags by including preprocessed cattributes parameter as tag * attribute and preprocessed ctext parameter as the tag body. * * Parameters: * * @param CTEXT (in) VARCHAR2: The text to emphasize. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_em(PG_FUNCTION_ARGS) { char *ctext = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracleFull); char *cattributes = htp::get_string_argument(fcinfo, 1, htp::StringEscapeLtGtChars); char *tag = htp::generate_em_tag(ctext, cattributes); htp::html_buffer_add(tag); htp::pfree_all(tag, ctext, cattributes); PG_RETURN_VOID(); } /** * @brief This procedure generates theandtags, which define text to be emphasized. * @details Generates theandtags by including preprocessed cattributes parameter as the tag * attribute and preprocessed ctext parameter as the tag body. * * Parameters: * * @param CTEXT (in) VARCHAR2: The text to emphasize. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_emphasis(PG_FUNCTION_ARGS) { char *ctext = NULL; char *cattributes = htp::get_string_argument(fcinfo, 1, htp::StringEscapeLtGtChars); text *textarg = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEXT_PP(0); LOCAL_FCINFO(local_fcinfo, 1); InitFunctionCallInfoData(*local_fcinfo, NULL, 1, PG_GET_COLLATION(), fcinfo->context, NULL); local_fcinfo->args[0].value = PointerGetDatum(textarg); local_fcinfo->args[0].isnull = (textarg == NULL ? true : false); Datum esc_text_datum = (*htf_escape_oracle_full) (local_fcinfo); text *esc_text = NULL; if (DatumGetPointer(esc_text_datum) != NULL) { esc_text = DatumGetTextPP(esc_text_datum); } if(esc_text) ctext = text_to_cstring(esc_text); char *tag = htp::generate_em_tag(ctext, cattributes); htp::html_buffer_add(tag); htp::pfree_all(tag, ctext, cattributes); if(esc_text) pfree(esc_text); PG_RETURN_VOID(); } /** * @brief заменяет символы, имеющие специальное значение в HTML, их escape-последовательностями. * @details Функция преобразует символы <, >, & и другие в HTML-сущности для безопасного отображения. * * Parameters: * * @param CTEXT (in) VARCHAR2: Строка для преобразования. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTF.html */ Datum htp_escape_oracle_full(PG_FUNCTION_ARGS) { char *res_str = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracleFull); if(res_str){ text *result = cstring_to_text(res_str); pfree(res_str); PG_RETURN_TEXT_P(result); } PG_RETURN_NULL(); } /** * @brief This procedure replaces characters that have special meaning in HTML with their escape sequences. * @details This procedure replaces characters that have special meaning in HTML with their escape sequences. * * Parameters: * * @param CTEXT (in) VARCHAR2: The text string to convert. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_escape_sc(PG_FUNCTION_ARGS) { char *ctext = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatSpecialChars); htp::html_buffer_add(ctext); htp::pfree_all(ctext); PG_RETURN_VOID(); } /** * @brief TODO: Добавить описание * @details TODO: Добавить детальное описание * * Parameters: * * @param CHARSET (in) VARCHAR2: TODO: Описание параметра CHARSET * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_flush_charset_convert(PG_FUNCTION_ARGS) { ereport(NOTICE, (errmsg("Функция htp.flush_charset_convert еще не реализована."))); PG_RETURN_VOID(); } /** * @brief This procedure generates thewhich marks the beginning of section of text with the specified font characteristics. * @details This procedure generates thewhich marks the beginning of section of text with the specified font characteristics. * * Parameters: * * @param CCOLOR (in) VARCHAR2: The value for theCOLORattribute. * * @param CFACE (in) VARCHAR2: The value for theFACEattribute * * @param CSIZE (in) VARCHAR2: The value for theSIZEattribute * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_fontopen(PG_FUNCTION_ARGS) { text *ccolor_txt = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEXT_PP(0); text *cface_txt = PG_ARGISNULL(1) ? NULL : PG_GETARG_TEXT_PP(1); text *csize_txt = PG_ARGISNULL(2) ? NULL : PG_GETARG_TEXT_PP(2); text *cattributes_txt = PG_ARGISNULL(3) ? NULL : PG_GETARG_TEXT_PP(3); char *ccolor = NULL; char *cface = NULL; char *csize = NULL; char *cattributes = NULL; if(ccolor_txt && VARSIZE_ANY_EXHDR(ccolor_txt)!=0) { ccolor = htp::escape_to_numeric_entity(ccolor_txt); } if(cface_txt && VARSIZE_ANY_EXHDR(cface_txt)!=0) { cface = htp::escape_to_numeric_entity(cface_txt); } if(csize_txt && VARSIZE_ANY_EXHDR(csize_txt)!=0) { csize = htp::escape_to_numeric_entity(csize_txt); } if(cattributes_txt && VARSIZE_ANY_EXHDR(cattributes_txt)!=0) { cattributes = text_to_cstring(cattributes_txt); } char *tag = htp::generate_font_tag(ccolor, cface, csize, cattributes); htp::html_buffer_add(tag); pfree(tag); if(ccolor) pfree(ccolor); if(cface) pfree(cface); if(csize) pfree(csize); if(cattributes) pfree(cattributes); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag withTYPE="checkbox"which inserts a checkbox element in a form. * @details This procedure generates thetag withTYPE="checkbox"which inserts a checkbox element in a form. * * Parameters: * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute. * * @param CVALUE (in) VARCHAR2: The value for theVALUEattribute. * * @param CCHECKED (in) VARCHAR2: If the value for this parameter is notNULL, theCHECKEDattribute is added to the tag. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formcheckbox(PG_FUNCTION_ARGS) { char *cname = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *cvalue = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracle); char *cchecked = htp::get_string_argument(fcinfo, 2, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 3); char *tag = htp::generate_checkbox_tag(cname, cvalue, cchecked, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cname, cvalue, cchecked, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag withTYPE="file"which inserts a file form element. This is used for file uploading for a given page. * @details This procedure generates thetag withTYPE="file"which inserts a file form element. This is used for file uploading for a given page. * * Parameters: * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute. * * @param CACCEPT (in) VARCHAR2: A comma-delimited list of MIME types for upload. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formfile(PG_FUNCTION_ARGS) { char *cname = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *caccept = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 2); char *tag = htp::generate_file_tag(cname, caccept, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cname, caccept, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag with TYPE="hidden", which inserts a hidden form element. * @details This procedure generates thetag with TYPE="hidden", which inserts a hidden form element. * * Parameters: * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute. * * @param CVALUE (in) VARCHAR2: The value for theVALUEattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formhidden(PG_FUNCTION_ARGS) { char *cname = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *value = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 2); char *tag = htp::generate_hidden_tag(cname, value, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cname, value, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag withTYPE="image"which creates an image field that the user clicks to submit the form immediately. * @details This procedure generates thetag withTYPE="image"which creates an image field that the user clicks to submit the form immediately. * * Parameters: * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute. * * @param CSRC (in) VARCHAR2: The value for theSRCattribute that specifies the image file. * * @param CALIGN (in) VARCHAR2: The value for theALIGNattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formimage(PG_FUNCTION_ARGS) { char *cname = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *csrc = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracle); char *calign = htp::get_string_argument(fcinfo, 2, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 3); char *tag = htp::generate_image_tag(cname, csrc, calign, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cname, csrc, calign, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates the
tag which marks the beginning of a form section in an HTML document. * @details This procedure generates thetag which marks the beginning of a form section in an HTML document. * * Parameters: * * @param CURL (in) VARCHAR2: The URL of the WRB or CGI script where the contents of the form is sent. This parameter is required. * * @param CMETHOD (in) VARCHAR2: The value for theMETHODattribute. The value can be "GET" or "POST". * * @param CTARGET (in) VARCHAR2: The value for theTARGETattribute. * * @param CENCTYPE (in) VARCHAR2: The value for theENCTYPEattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formopen(PG_FUNCTION_ARGS) { text *curl_txt = PG_ARGISNULL(0) ? NULL : PG_GETARG_TEXT_PP(0); text *cmethod_txt = PG_ARGISNULL(1) ? NULL : PG_GETARG_TEXT_PP(1); text *ctarget_txt = PG_ARGISNULL(2) ? NULL : PG_GETARG_TEXT_PP(2); text *cenctype_txt = PG_ARGISNULL(3) ? NULL : PG_GETARG_TEXT_PP(3); text *cattributes_txt = PG_ARGISNULL(4) ? NULL : PG_GETARG_TEXT_PP(4); char *curl = NULL; char *cmethod = NULL; char *ctarget = NULL; char *cenctype = NULL; char *cattributes = NULL; if(curl_txt && VARSIZE_ANY_EXHDR(curl_txt)!=0) { curl = htp::escape_special_chars(curl_txt); } if(cmethod_txt && VARSIZE_ANY_EXHDR(cmethod_txt)!=0) { cmethod = htp::escape_to_numeric_entity(cmethod_txt); } if(ctarget_txt && VARSIZE_ANY_EXHDR(ctarget_txt)!=0) { ctarget = htp::escape_to_numeric_entity(ctarget_txt); } if(cenctype_txt && VARSIZE_ANY_EXHDR(cenctype_txt)!=0) { cenctype = htp::escape_to_numeric_entity(cenctype_txt); } if(cattributes_txt && VARSIZE_ANY_EXHDR(cattributes_txt)!=0) { cattributes = text_to_cstring(cattributes_txt); } char *tag = htp::generate_form_tag(curl, cmethod, ctarget, cenctype, cattributes); htp::html_buffer_add(tag); pfree(tag); if(curl) pfree(curl); if(cmethod) pfree(cmethod); if(ctarget) pfree(ctarget); if(cenctype) pfree(cenctype); if(cattributes) pfree(cattributes); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag withTYPE="password"which creates a single-line text entry field. When the user enters text in the field, each character is represented by one asterisk. This is used for entering passwords. * @details This procedure generates thetag withTYPE="password"which creates a single-line text entry field. When the user enters text in the field, each character is represented by one asterisk. This is used for entering passwords. * * Parameters: * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute. * * @param CSIZE (in) VARCHAR2: The value for theSIZEattribute. * * @param CMAXLENGTH (in) VARCHAR2: The value for theMAXLENGTHattribute. * * @param CVALUE (in) VARCHAR2: The value for theVALUEattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formpassword(PG_FUNCTION_ARGS) { char *cname = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *csize = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracle); char *cmaxlength = htp::get_string_argument(fcinfo, 2, htp::StringEscapeFormatOracle); char *cvalue = htp::get_string_argument(fcinfo, 3, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 4); char *tag = htp::generate_password_tag(cname, csize, cmaxlength, cvalue, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cname, csize, cmaxlength, cvalue, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag withTYPE="radio", which creates a radio button on the HTML form. Within a set of radio buttons, the user selects only one. Each radio button in the same set has the same name, but different values. The selected radio button generates a name/value pair. * @details This procedure generates thetag withTYPE="radio", which creates a radio button on the HTML form. Within a set of radio buttons, the user selects only one. Each radio button in the same set has the same name, but different values. The selected radio button generates a name/value pair. * * Parameters: * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute. * * @param CVALUE (in) VARCHAR2: The value for theVALUEattribute. * * @param CCHECKED (in) VARCHAR2: If the value for this parameter is notNULL, theCHECKEDattribute is added to the tag. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formradio(PG_FUNCTION_ARGS) { char *cname = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *cvalue = htp::get_string_argument(fcinfo, 1, htp::StringEscapeFormatOracle); char *cchecked = htp::get_string_argument(fcinfo, 2, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 3); char *tag = htp::generate_radio_tag(cname, cvalue, cchecked, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cname, cvalue, cchecked, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetag withTYPE="reset"which creates a button that, when selected, resets the form fields to their initial values. * @details This procedure generates thetag withTYPE="reset"which creates a button that, when selected, resets the form fields to their initial values. * * Parameters: * * @param CVALUE (in) VARCHAR2: The value for theVALUEattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formreset(PG_FUNCTION_ARGS) { char *cvalue = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *cattributes = htp::get_string_argument(fcinfo, 1); char *tag = htp::generate_reset_tag(cvalue, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cvalue, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates thetags which creates a Select form element. * * Parameters: * * @param CNAME (in) VARCHAR2: The value for theNAMEattribute. * * @param CPROMPT (in) VARCHAR2: The string preceding the list box. * * @param NSIZE (in) NUMBER: The value for theSIZEattribute. * * @param CATTRIBUTES (in) VARCHAR2: The other attributes to be included as-is in the tag. * * * * * * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/HTP.html */ Datum htp_formselectopen(PG_FUNCTION_ARGS) { char *cname = htp::get_string_argument(fcinfo, 0, htp::StringEscapeFormatOracle); char *cprompt = htp::get_string_argument(fcinfo, 1); char *csize = htp::get_numeric_argument_as_string(fcinfo, 2); char *cattributes = htp::get_string_argument(fcinfo, 3); char *tag = htp::generate_formselect_tag(cname, cprompt, csize, cattributes); htp::html_buffer_add(tag); htp::pfree_all(cname, cprompt, csize, cattributes, tag); PG_RETURN_VOID(); } /** * @brief This procedure generates the