PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
 

Macros

#define YY_TYPEDEF_YY_BUFFER_STATE
 
#define YY_TYPEDEF_YY_SCANNER_T
 

Typedefs

typedef struct yy_buffer_state * YY_BUFFER_STATE
 
typedef void * yyscan_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)
 
char * psqlscan_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)
 

Macro Definition Documentation

◆ YY_TYPEDEF_YY_BUFFER_STATE

#define YY_TYPEDEF_YY_BUFFER_STATE

Definition at line 55 of file psqlscan_int.h.

◆ YY_TYPEDEF_YY_SCANNER_T

#define YY_TYPEDEF_YY_SCANNER_T

Definition at line 59 of file psqlscan_int.h.

Typedef Documentation

◆ PsqlScanStateData

◆ StackElem

typedef struct StackElem StackElem

◆ YY_BUFFER_STATE

typedef struct yy_buffer_state* YY_BUFFER_STATE

Definition at line 56 of file psqlscan_int.h.

◆ yyscan_t

typedef void* yyscan_t

Definition at line 60 of file psqlscan_int.h.

Function Documentation

◆ psqlscan_emit()

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

Definition at line 1517 of file psqlscan.l.

1518{
1519 PQExpBuffer output_buf = state->output_buf;
1520
1521 if (state->safe_encoding)
1522 appendBinaryPQExpBuffer(output_buf, txt, len);
1523 else
1524 {
1525 /* Gotta do it the hard way */
1526 const char *reference = state->refline;
1527 int i;
1528
1529 reference += (txt - state->curline);
1530
1531 for (i = 0; i < len; i++)
1532 {
1533 char ch = txt[i];
1534
1535 if (ch == (char) 0xFF)
1536 ch = reference[i];
1537 appendPQExpBufferChar(output_buf, ch);
1538 }
1539 }
1540}
int i
Definition: isn.c:77
const void size_t len
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)
Definition: pqexpbuffer.c:397
void appendPQExpBufferChar(PQExpBuffer str, char ch)
Definition: pqexpbuffer.c:378
Definition: regguts.h:323

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

Referenced by psqlscan_escape_variable().

◆ psqlscan_escape_variable()

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

Definition at line 1585 of file psqlscan.l.

1587{
1588 char *varname;
1589 char *value;
1590
1591 /* Variable lookup. */
1592 varname = psqlscan_extract_substring(state, txt + 2, len - 3);
1593 if (state->callbacks->get_variable)
1594 value = state->callbacks->get_variable(varname, quote,
1595 state->cb_passthrough);
1596 else
1597 value = NULL;
1598 free(varname);
1599
1600 if (value)
1601 {
1602 /* Emit the suitably-escaped value */
1603 appendPQExpBufferStr(state->output_buf, value);
1604 free(value);
1605 }
1606 else
1607 {
1608 /* Emit original token as-is */
1609 psqlscan_emit(state, txt, len);
1610 }
1611}
#define free(a)
Definition: header.h:65
static struct @165 value
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
Definition: pqexpbuffer.c:367
void psqlscan_emit(PsqlScanState state, const char *txt, int len)
Definition: psqlscan.l:1517
char * psqlscan_extract_substring(PsqlScanState state, const char *txt, int len)
Definition: psqlscan.l:1549

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

◆ psqlscan_extract_substring()

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

Definition at line 1549 of file psqlscan.l.

1550{
1551 char *result = (char *) pg_malloc(len + 1);
1552
1553 if (state->safe_encoding)
1554 memcpy(result, txt, len);
1555 else
1556 {
1557 /* Gotta do it the hard way */
1558 const char *reference = state->refline;
1559 int i;
1560
1561 reference += (txt - state->curline);
1562
1563 for (i = 0; i < len; i++)
1564 {
1565 char ch = txt[i];
1566
1567 if (ch == (char) 0xFF)
1568 ch = reference[i];
1569 result[i] = ch;
1570 }
1571 }
1572 result[len] = '\0';
1573 return result;
1574}
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47

References i, len, and pg_malloc().

Referenced by psqlscan_escape_variable(), and psqlscan_test_variable().

◆ psqlscan_pop_buffer_stack()

void psqlscan_pop_buffer_stack ( PsqlScanState  state)

Definition at line 1413 of file psqlscan.l.

1414{
1415 StackElem *stackelem = state->buffer_stack;
1416
1417 state->buffer_stack = stackelem->next;
1418 yy_delete_buffer(stackelem->buf, state->scanner);
1419 free(stackelem->bufstring);
1420 if (stackelem->origstring)
1421 free(stackelem->origstring);
1422 if (stackelem->varname)
1423 free(stackelem->varname);
1424 free(stackelem);
1425}
char * origstring
Definition: psqlscan_int.h:73
char * varname
Definition: psqlscan_int.h:74
YY_BUFFER_STATE buf
Definition: psqlscan_int.h:71
char * bufstring
Definition: psqlscan_int.h:72
struct StackElem * next
Definition: psqlscan_int.h:75

References StackElem::buf, StackElem::bufstring, free, StackElem::next, StackElem::origstring, and StackElem::varname.

Referenced by psql_scan_finish().

◆ psqlscan_prepare_buffer()

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

Definition at line 1476 of file psqlscan.l.

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

References i, len, pg_malloc(), 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 
)

Definition at line 1374 of file psqlscan.l.

1376{
1377 StackElem *stackelem;
1378
1379 stackelem = (StackElem *) pg_malloc(sizeof(StackElem));
1380
1381 /*
1382 * In current usage, the passed varname points at the current flex input
1383 * buffer; we must copy it before calling psqlscan_prepare_buffer()
1384 * because that will change the buffer state.
1385 */
1386 stackelem->varname = varname ? pg_strdup(varname) : NULL;
1387
1388 stackelem->buf = psqlscan_prepare_buffer(state, newstr, strlen(newstr),
1389 &stackelem->bufstring);
1390 state->curline = stackelem->bufstring;
1391 if (state->safe_encoding)
1392 {
1393 stackelem->origstring = NULL;
1394 state->refline = stackelem->bufstring;
1395 }
1396 else
1397 {
1398 stackelem->origstring = pg_strdup(newstr);
1399 state->refline = stackelem->origstring;
1400 }
1401 stackelem->next = state->buffer_stack;
1402 state->buffer_stack = stackelem;
1403}
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
YY_BUFFER_STATE psqlscan_prepare_buffer(PsqlScanState state, const char *txt, int len, char **txtcopy)
Definition: psqlscan.l:1476

References StackElem::buf, StackElem::bufstring, StackElem::next, StackElem::origstring, pg_malloc(), pg_strdup(), psqlscan_prepare_buffer(), and StackElem::varname.

◆ psqlscan_select_top_buffer()

void psqlscan_select_top_buffer ( PsqlScanState  state)

Definition at line 1431 of file psqlscan.l.

1432{
1433 StackElem *stackelem = state->buffer_stack;
1434
1435 if (stackelem != NULL)
1436 {
1437 yy_switch_to_buffer(stackelem->buf, state->scanner);
1438 state->curline = stackelem->bufstring;
1439 state->refline = stackelem->origstring ? stackelem->origstring : stackelem->bufstring;
1440 }
1441 else
1442 {
1443 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
1444 state->curline = state->scanbuf;
1445 state->refline = state->scanline;
1446 }
1447}

References StackElem::buf, StackElem::bufstring, and StackElem::origstring.

◆ psqlscan_test_variable()

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

Definition at line 1614 of file psqlscan.l.

1615{
1616 char *varname;
1617 char *value;
1618
1619 varname = psqlscan_extract_substring(state, txt + 3, len - 4);
1620 if (state->callbacks->get_variable)
1621 value = state->callbacks->get_variable(varname, PQUOTE_PLAIN,
1622 state->cb_passthrough);
1623 else
1624 value = NULL;
1625 free(varname);
1626
1627 if (value != NULL)
1628 {
1629 appendPQExpBufferStr(state->output_buf, "TRUE");
1630 free(value);
1631 }
1632 else
1633 {
1634 appendPQExpBufferStr(state->output_buf, "FALSE");
1635 }
1636}
@ PQUOTE_PLAIN
Definition: psqlscan.h:54

References appendPQExpBufferStr(), 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 
)

Definition at line 1454 of file psqlscan.l.

1455{
1456 StackElem *stackelem;
1457
1458 for (stackelem = state->buffer_stack;
1459 stackelem != NULL;
1460 stackelem = stackelem->next)
1461 {
1462 if (stackelem->varname && strcmp(stackelem->varname, varname) == 0)
1463 return true;
1464 }
1465 return false;
1466}

References StackElem::next, and StackElem::varname.