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 1529 of file psqlscan.l.

1530{
1531 PQExpBuffer output_buf = state->output_buf;
1532
1533 if (state->safe_encoding)
1534 appendBinaryPQExpBuffer(output_buf, txt, len);
1535 else
1536 {
1537 /* Gotta do it the hard way */
1538 const char *reference = state->refline;
1539 int i;
1540
1541 reference += (txt - state->curline);
1542
1543 for (i = 0; i < len; i++)
1544 {
1545 char ch = txt[i];
1546
1547 if (ch == (char) 0xFF)
1548 ch = reference[i];
1549 appendPQExpBufferChar(output_buf, ch);
1550 }
1551 }
1552}
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 1597 of file psqlscan.l.

1599{
1600 char *varname;
1601 char *value;
1602
1603 /* Variable lookup. */
1604 varname = psqlscan_extract_substring(state, txt + 2, len - 3);
1605 if (state->callbacks->get_variable)
1606 value = state->callbacks->get_variable(varname, quote,
1607 state->cb_passthrough);
1608 else
1609 value = NULL;
1610 free(varname);
1611
1612 if (value)
1613 {
1614 /* Emit the suitably-escaped value */
1615 appendPQExpBufferStr(state->output_buf, value);
1616 free(value);
1617 }
1618 else
1619 {
1620 /* Emit original token as-is */
1622 }
1623}
static struct @177 value
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void psqlscan_emit(PsqlScanState state, const char *txt, int len)
Definition psqlscan.l:1529
char * psqlscan_extract_substring(PsqlScanState state, const char *txt, int len)
Definition psqlscan.l:1561
#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 1561 of file psqlscan.l.

1562{
1563 char *result = pg_malloc_array(char, (len + 1));
1564
1565 if (state->safe_encoding)
1566 memcpy(result, txt, len);
1567 else
1568 {
1569 /* Gotta do it the hard way */
1570 const char *reference = state->refline;
1571 int i;
1572
1573 reference += (txt - state->curline);
1574
1575 for (i = 0; i < len; i++)
1576 {
1577 char ch = txt[i];
1578
1579 if (ch == (char) 0xFF)
1580 ch = reference[i];
1581 result[i] = ch;
1582 }
1583 }
1584 result[len] = '\0';
1585 return result;
1586}
uint32 result
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define pg_malloc_array(type, count)
Definition fe_memutils.h:56

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 1425 of file psqlscan.l.

1426{
1427 StackElem *stackelem = state->buffer_stack;
1428
1429 state->buffer_stack = stackelem->next;
1430 yy_delete_buffer(stackelem->buf, state->scanner);
1431 free(stackelem->bufstring);
1432 if (stackelem->origstring)
1433 free(stackelem->origstring);
1434 if (stackelem->varname)
1435 free(stackelem->varname);
1436 free(stackelem);
1437}
struct state * next
Definition regguts.h:332

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 1488 of file psqlscan.l.

1490{
1491 char *newtxt;
1492
1493 /* Flex wants two \0 characters after the actual data */
1494 newtxt = pg_malloc_array(char, (len + 2));
1495 *txtcopy = newtxt;
1497
1498 if (state->safe_encoding)
1499 memcpy(newtxt, txt, len);
1500 else
1501 {
1502 /* Gotta do it the hard way */
1503 int i = 0;
1504
1505 while (i < len)
1506 {
1507 int thislen = PQmblen(txt + i, state->encoding);
1508
1509 /* first byte should always be okay... */
1510 newtxt[i] = txt[i];
1511 i++;
1512 while (--thislen > 0 && i < len)
1513 newtxt[i++] = (char) 0xFF;
1514 }
1515 }
1516
1517 return yy_scan_buffer(newtxt, len + 2, state->scanner);
1518}
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 1386 of file psqlscan.l.

1388{
1390
1392
1393 /*
1394 * In current usage, the passed varname points at the current flex input
1395 * buffer; we must copy it before calling psqlscan_prepare_buffer()
1396 * because that will change the buffer state.
1397 */
1398 stackelem->varname = varname ? pg_strdup(varname) : NULL;
1399
1401 &stackelem->bufstring);
1402 state->curline = stackelem->bufstring;
1403 if (state->safe_encoding)
1404 {
1405 stackelem->origstring = NULL;
1406 state->refline = stackelem->bufstring;
1407 }
1408 else
1409 {
1410 stackelem->origstring = pg_strdup(newstr);
1411 state->refline = stackelem->origstring;
1412 }
1413 stackelem->next = state->buffer_stack;
1414 state->buffer_stack = stackelem;
1415}
char * pg_strdup(const char *in)
Definition fe_memutils.c:85
#define pg_malloc_object(type)
Definition fe_memutils.h:50
YY_BUFFER_STATE psqlscan_prepare_buffer(PsqlScanState state, const char *txt, int len, char **txtcopy)
Definition psqlscan.l:1488

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 1443 of file psqlscan.l.

1444{
1445 StackElem *stackelem = state->buffer_stack;
1446
1447 if (stackelem != NULL)
1448 {
1449 yy_switch_to_buffer(stackelem->buf, state->scanner);
1450 state->curline = stackelem->bufstring;
1451 state->refline = stackelem->origstring ? stackelem->origstring : stackelem->bufstring;
1452 }
1453 else
1454 {
1455 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
1456 state->curline = state->scanbuf;
1457 state->refline = state->scanline;
1458 }
1459}

References fb().

◆ psqlscan_test_variable()

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

Definition at line 1626 of file psqlscan.l.

1627{
1628 char *varname;
1629 char *value;
1630
1631 varname = psqlscan_extract_substring(state, txt + 3, len - 4);
1632 if (state->callbacks->get_variable)
1633 value = state->callbacks->get_variable(varname, PQUOTE_PLAIN,
1634 state->cb_passthrough);
1635 else
1636 value = NULL;
1637 free(varname);
1638
1639 if (value != NULL)
1640 {
1641 appendPQExpBufferStr(state->output_buf, "TRUE");
1642 free(value);
1643 }
1644 else
1645 {
1646 appendPQExpBufferStr(state->output_buf, "FALSE");
1647 }
1648}
@ 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 1466 of file psqlscan.l.

1467{
1469
1470 for (stackelem = state->buffer_stack;
1471 stackelem != NULL;
1472 stackelem = stackelem->next)
1473 {
1474 if (stackelem->varname && strcmp(stackelem->varname, varname) == 0)
1475 return true;
1476 }
1477 return false;
1478}

References fb().