PostgreSQL Source Code git master
Loading...
Searching...
No Matches
psqlscan_int.h File Reference
Include dependency graph for psqlscan_int.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  StackElem
 
struct  PsqlScanStateData
 

Typedefs

typedef struct yy_buffer_stateYY_BUFFER_STATE
 
typedef voidyyscan_t
 
typedef struct StackElem StackElem
 
typedef struct PsqlScanStateData PsqlScanStateData
 

Functions

void psqlscan_push_new_buffer (PsqlScanState state, const char *newstr, const char *varname)
 
void psqlscan_pop_buffer_stack (PsqlScanState state)
 
void psqlscan_select_top_buffer (PsqlScanState state)
 
bool psqlscan_var_is_current_source (PsqlScanState state, const char *varname)
 
YY_BUFFER_STATE psqlscan_prepare_buffer (PsqlScanState state, const char *txt, int len, char **txtcopy)
 
void psqlscan_emit (PsqlScanState state, const char *txt, int len)
 
charpsqlscan_extract_substring (PsqlScanState state, const char *txt, int len)
 
void psqlscan_escape_variable (PsqlScanState state, const char *txt, int len, PsqlScanQuoteType quote)
 
void psqlscan_test_variable (PsqlScanState state, const char *txt, int len)
 

Typedef Documentation

◆ PsqlScanStateData

◆ StackElem

◆ YY_BUFFER_STATE

Definition at line 54 of file psqlscan_int.h.

◆ yyscan_t

Definition at line 55 of file psqlscan_int.h.

Function Documentation

◆ psqlscan_emit()

void psqlscan_emit ( PsqlScanState  state,
const char txt,
int  len 
)
extern

Definition at line 1611 of file psqlscan.l.

1612{
1613 PQExpBuffer output_buf = state->output_buf;
1614
1615 if (state->safe_encoding)
1616 appendBinaryPQExpBuffer(output_buf, txt, len);
1617 else
1618 {
1619 /* Gotta do it the hard way */
1620 const char *reference = state->refline;
1621 int i;
1622
1623 reference += (txt - state->curline);
1624
1625 for (i = 0; i < len; i++)
1626 {
1627 char ch = txt[i];
1628
1629 if (ch == (char) 0xFF)
1630 ch = reference[i];
1631 appendPQExpBufferChar(output_buf, ch);
1632 }
1633 }
1634}
int i
Definition isn.c:77
const void size_t len
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
static int fb(int x)

References appendBinaryPQExpBuffer(), appendPQExpBufferChar(), fb(), i, and len.

Referenced by psqlscan_escape_variable().

◆ psqlscan_escape_variable()

void psqlscan_escape_variable ( PsqlScanState  state,
const char txt,
int  len,
PsqlScanQuoteType  quote 
)
extern

Definition at line 1679 of file psqlscan.l.

1681{
1682 char *varname;
1683 char *value;
1684
1685 /* Variable lookup. */
1686 varname = psqlscan_extract_substring(state, txt + 2, len - 3);
1687 if (state->callbacks->get_variable)
1688 value = state->callbacks->get_variable(varname, quote,
1689 state->cb_passthrough);
1690 else
1691 value = NULL;
1692 free(varname);
1693
1694 if (value)
1695 {
1696 /* Emit the suitably-escaped value */
1697 appendPQExpBufferStr(state->output_buf, value);
1698 free(value);
1699 }
1700 else
1701 {
1702 /* Emit original token as-is */
1704 }
1705}
static struct @175 value
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void psqlscan_emit(PsqlScanState state, const char *txt, int len)
Definition psqlscan.l:1611
char * psqlscan_extract_substring(PsqlScanState state, const char *txt, int len)
Definition psqlscan.l:1643
#define free(a)

References appendPQExpBufferStr(), fb(), free, len, psqlscan_emit(), psqlscan_extract_substring(), and value.

◆ psqlscan_extract_substring()

char * psqlscan_extract_substring ( PsqlScanState  state,
const char txt,
int  len 
)
extern

Definition at line 1643 of file psqlscan.l.

1644{
1645 char *result = pg_malloc_array(char, (len + 1));
1646
1647 if (state->safe_encoding)
1648 memcpy(result, txt, len);
1649 else
1650 {
1651 /* Gotta do it the hard way */
1652 const char *reference = state->refline;
1653 int i;
1654
1655 reference += (txt - state->curline);
1656
1657 for (i = 0; i < len; i++)
1658 {
1659 char ch = txt[i];
1660
1661 if (ch == (char) 0xFF)
1662 ch = reference[i];
1663 result[i] = ch;
1664 }
1665 }
1666 result[len] = '\0';
1667 return result;
1668}
uint32 result
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define pg_malloc_array(type, count)
Definition fe_memutils.h:66

References fb(), i, len, memcpy(), pg_malloc_array, and result.

Referenced by psqlscan_escape_variable(), and psqlscan_test_variable().

◆ psqlscan_pop_buffer_stack()

void psqlscan_pop_buffer_stack ( PsqlScanState  state)
extern

Definition at line 1507 of file psqlscan.l.

1508{
1509 StackElem *stackelem = state->buffer_stack;
1510
1511 state->buffer_stack = stackelem->next;
1512 yy_delete_buffer(stackelem->buf, state->scanner);
1513 free(stackelem->bufstring);
1514 if (stackelem->origstring)
1515 free(stackelem->origstring);
1516 if (stackelem->varname)
1517 free(stackelem->varname);
1518 free(stackelem);
1519}
struct state * next
Definition regguts.h:340

References fb(), free, and state::next.

Referenced by psql_scan_finish().

◆ psqlscan_prepare_buffer()

YY_BUFFER_STATE psqlscan_prepare_buffer ( PsqlScanState  state,
const char txt,
int  len,
char **  txtcopy 
)
extern

Definition at line 1570 of file psqlscan.l.

1572{
1573 char *newtxt;
1574
1575 /* Flex wants two \0 characters after the actual data */
1576 newtxt = pg_malloc_array(char, (len + 2));
1577 *txtcopy = newtxt;
1579
1580 if (state->safe_encoding)
1581 memcpy(newtxt, txt, len);
1582 else
1583 {
1584 /* Gotta do it the hard way */
1585 int i = 0;
1586
1587 while (i < len)
1588 {
1589 int thislen = PQmblen(txt + i, state->encoding);
1590
1591 /* first byte should always be okay... */
1592 newtxt[i] = txt[i];
1593 i++;
1594 while (--thislen > 0 && i < len)
1595 newtxt[i++] = (char) 0xFF;
1596 }
1597 }
1598
1599 return yy_scan_buffer(newtxt, len + 2, state->scanner);
1600}
int PQmblen(const char *s, int encoding)
Definition fe-misc.c:1255

References fb(), i, len, memcpy(), pg_malloc_array, and PQmblen().

Referenced by psql_scan_setup(), and psqlscan_push_new_buffer().

◆ psqlscan_push_new_buffer()

void psqlscan_push_new_buffer ( PsqlScanState  state,
const char newstr,
const char varname 
)
extern

Definition at line 1468 of file psqlscan.l.

1470{
1472
1474
1475 /*
1476 * In current usage, the passed varname points at the current flex input
1477 * buffer; we must copy it before calling psqlscan_prepare_buffer()
1478 * because that will change the buffer state.
1479 */
1480 stackelem->varname = varname ? pg_strdup(varname) : NULL;
1481
1483 &stackelem->bufstring);
1484 state->curline = stackelem->bufstring;
1485 if (state->safe_encoding)
1486 {
1487 stackelem->origstring = NULL;
1488 state->refline = stackelem->bufstring;
1489 }
1490 else
1491 {
1492 stackelem->origstring = pg_strdup(newstr);
1493 state->refline = stackelem->origstring;
1494 }
1495 stackelem->next = state->buffer_stack;
1496 state->buffer_stack = stackelem;
1497}
char * pg_strdup(const char *in)
Definition fe_memutils.c:91
#define pg_malloc_object(type)
Definition fe_memutils.h:60
YY_BUFFER_STATE psqlscan_prepare_buffer(PsqlScanState state, const char *txt, int len, char **txtcopy)
Definition psqlscan.l:1570

References fb(), state::next, pg_malloc_object, pg_strdup(), and psqlscan_prepare_buffer().

◆ psqlscan_select_top_buffer()

void psqlscan_select_top_buffer ( PsqlScanState  state)
extern

Definition at line 1525 of file psqlscan.l.

1526{
1527 StackElem *stackelem = state->buffer_stack;
1528
1529 if (stackelem != NULL)
1530 {
1531 yy_switch_to_buffer(stackelem->buf, state->scanner);
1532 state->curline = stackelem->bufstring;
1533 state->refline = stackelem->origstring ? stackelem->origstring : stackelem->bufstring;
1534 }
1535 else
1536 {
1537 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
1538 state->curline = state->scanbuf;
1539 state->refline = state->scanline;
1540 }
1541}

References fb().

◆ psqlscan_test_variable()

void psqlscan_test_variable ( PsqlScanState  state,
const char txt,
int  len 
)
extern

Definition at line 1708 of file psqlscan.l.

1709{
1710 char *varname;
1711 char *value;
1712
1713 varname = psqlscan_extract_substring(state, txt + 3, len - 4);
1714 if (state->callbacks->get_variable)
1715 value = state->callbacks->get_variable(varname, PQUOTE_PLAIN,
1716 state->cb_passthrough);
1717 else
1718 value = NULL;
1719 free(varname);
1720
1721 if (value != NULL)
1722 {
1723 appendPQExpBufferStr(state->output_buf, "TRUE");
1724 free(value);
1725 }
1726 else
1727 {
1728 appendPQExpBufferStr(state->output_buf, "FALSE");
1729 }
1730}
@ PQUOTE_PLAIN
Definition psqlscan.h:54

References appendPQExpBufferStr(), fb(), free, len, PQUOTE_PLAIN, psqlscan_extract_substring(), and value.

◆ psqlscan_var_is_current_source()

bool psqlscan_var_is_current_source ( PsqlScanState  state,
const char varname 
)
extern

Definition at line 1548 of file psqlscan.l.

1549{
1551
1552 for (stackelem = state->buffer_stack;
1553 stackelem != NULL;
1554 stackelem = stackelem->next)
1555 {
1556 if (stackelem->varname && strcmp(stackelem->varname, varname) == 0)
1557 return true;
1558 }
1559 return false;
1560}

References fb().