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

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

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

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

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

Referenced by psqlscan_escape_variable(), and psqlscan_test_variable().

◆ psqlscan_pop_buffer_stack()

void psqlscan_pop_buffer_stack ( PsqlScanState  state)
extern

Definition at line 1419 of file psqlscan.l.

1420{
1421 StackElem *stackelem = state->buffer_stack;
1422
1423 state->buffer_stack = stackelem->next;
1424 yy_delete_buffer(stackelem->buf, state->scanner);
1425 free(stackelem->bufstring);
1426 if (stackelem->origstring)
1427 free(stackelem->origstring);
1428 if (stackelem->varname)
1429 free(stackelem->varname);
1430 free(stackelem);
1431}
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 1482 of file psqlscan.l.

1484{
1485 char *newtxt;
1486
1487 /* Flex wants two \0 characters after the actual data */
1488 newtxt = pg_malloc_array(char, (len + 2));
1489 *txtcopy = newtxt;
1491
1492 if (state->safe_encoding)
1493 memcpy(newtxt, txt, len);
1494 else
1495 {
1496 /* Gotta do it the hard way */
1497 int i = 0;
1498
1499 while (i < len)
1500 {
1501 int thislen = PQmblen(txt + i, state->encoding);
1502
1503 /* first byte should always be okay... */
1504 newtxt[i] = txt[i];
1505 i++;
1506 while (--thislen > 0 && i < len)
1507 newtxt[i++] = (char) 0xFF;
1508 }
1509 }
1510
1511 return yy_scan_buffer(newtxt, len + 2, state->scanner);
1512}
int PQmblen(const char *s, int encoding)
Definition fe-misc.c:1255

References fb(), i, len, 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 1380 of file psqlscan.l.

1382{
1384
1386
1387 /*
1388 * In current usage, the passed varname points at the current flex input
1389 * buffer; we must copy it before calling psqlscan_prepare_buffer()
1390 * because that will change the buffer state.
1391 */
1392 stackelem->varname = varname ? pg_strdup(varname) : NULL;
1393
1395 &stackelem->bufstring);
1396 state->curline = stackelem->bufstring;
1397 if (state->safe_encoding)
1398 {
1399 stackelem->origstring = NULL;
1400 state->refline = stackelem->bufstring;
1401 }
1402 else
1403 {
1404 stackelem->origstring = pg_strdup(newstr);
1405 state->refline = stackelem->origstring;
1406 }
1407 stackelem->next = state->buffer_stack;
1408 state->buffer_stack = stackelem;
1409}
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:1482

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

1438{
1439 StackElem *stackelem = state->buffer_stack;
1440
1441 if (stackelem != NULL)
1442 {
1443 yy_switch_to_buffer(stackelem->buf, state->scanner);
1444 state->curline = stackelem->bufstring;
1445 state->refline = stackelem->origstring ? stackelem->origstring : stackelem->bufstring;
1446 }
1447 else
1448 {
1449 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
1450 state->curline = state->scanbuf;
1451 state->refline = state->scanline;
1452 }
1453}

References fb().

◆ psqlscan_test_variable()

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

Definition at line 1620 of file psqlscan.l.

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

1461{
1463
1464 for (stackelem = state->buffer_stack;
1465 stackelem != NULL;
1466 stackelem = stackelem->next)
1467 {
1468 if (stackelem->varname && strcmp(stackelem->varname, varname) == 0)
1469 return true;
1470 }
1471 return false;
1472}

References fb().