#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <pwd.h>
#include <errno.h>
#include <sys/stat.h>
#include <dirent.h>
#include <wctype.h>
#include <iconv.h>
#include <locale.h>
#include <signal.h>
#include <sys/select.h>
#include "fallback.h"
#include "util.h"
#include "common.h"
#include "wutil.h"
#include "env_universal_common.h"
Data Structures | |
| struct | var_uni_entry |
| A variable entry. More... | |
Defines | |
| #define | SET_MBS "SET" |
| Non-wide version of the set command. | |
| #define | SET_EXPORT_MBS "SET_EXPORT" |
| Non-wide version of the set_export command. | |
| #define | ERASE_MBS "ERASE" |
| Non-wide version of the erase command. | |
| #define | BARRIER_MBS "BARRIER" |
| Non-wide version of the barrier command. | |
| #define | BARRIER_REPLY_MBS "BARRIER_REPLY" |
| Non-wide version of the barrier_reply command. | |
| #define | PARSE_ERR L"Unable to parse universal variable message: '%ls'" |
| Error message. | |
| #define | ENV_UNIVERSAL_ERROR 0x100 |
| ERROR string for internal buffered reader. | |
| #define | ENV_UNIVERSAL_AGAIN 0x101 |
| EAGAIN string for internal buffered reader. | |
| #define | ENV_UNIVERSAL_EOF 0x102 |
| EOF string for internal buffered reader. | |
Typedefs | |
| typedef struct var_uni_entry | var_uni_entry_t |
| A variable entry. | |
Functions | |
| static void | parse_message (wchar_t *msg, connection_t *src) |
| Parse message msg. | |
| static wchar_t * | utf2wcs (const char *in) |
| Convert utf-8 string to wide string. | |
| static char * | wcs2utf (const wchar_t *in) |
| Convert wide string to utf-8. | |
| void | env_universal_common_init (void(*cb)(int type, const wchar_t *key, const wchar_t *val)) |
| Init the library. | |
| static void | erase (void *key, void *data) |
| Free both key and data. | |
| void | env_universal_common_destroy () |
| Destroy library data. | |
| static int | read_byte (connection_t *src) |
| Read one byte of date form the specified connection. | |
| void | read_message (connection_t *src) |
| Read all available messages on this connection. | |
| void | env_universal_common_remove (const wchar_t *name) |
| Remove variable with specified name. | |
| static int | match (const wchar_t *msg, const wchar_t *cmd) |
| Test if the message msg contains the command cmd. | |
| void | env_universal_common_set (const wchar_t *key, const wchar_t *val, int export) |
| Perform the specified variable assignment. | |
| static int | try_send (message_t *msg, int fd) |
| Attempt to send the specified message to the specified file descriptor. | |
| void | try_send_all (connection_t *c) |
| Send as many messages as possible without blocking to the connection. | |
| static wchar_t * | full_escape (const wchar_t *in) |
| Escape specified string. | |
| message_t * | create_message (int type, const wchar_t *key_in, const wchar_t *val_in) |
| Create a messge with the specified properties. | |
| static void | add_key_to_hash (void *key, void *data, void *aux) |
| Function used with hash_foreach to insert keys of one table into another. | |
| void | env_universal_common_get_names (array_list_t *l, int show_exported, int show_unexported) |
| Add all variable names to the specified list. | |
| wchar_t * | env_universal_common_get (const wchar_t *name) |
| Get the value of the variable with the specified name. | |
| int | env_universal_common_get_export (const wchar_t *name) |
| Get the export flag of the variable with the specified name. | |
| static void | enqueue (void *k, void *v, void *q) |
| Adds a variable creation message about the specified variable to the specified queue. | |
| void | enqueue_all (connection_t *c) |
| Add messages about all existing variables to the specified connection. | |
| void | connection_init (connection_t *c, int fd) |
| Fill in the specified connection_t struct. | |
| void | connection_destroy (connection_t *c) |
| Close and destroy the specified connection struct. | |
Variables | |
| hash_table_t | env_universal_var |
| The table of all universal variables. | |
| void(* | callback )(int type, const wchar_t *key, const wchar_t *val) |
| Callback function, should be called on all events. | |
| static int | get_names_show_exported |
| Variable used by env_get_names to communicate auxiliary information to add_key_to_hash. | |
| static int | get_names_show_unexported |
| Variable used by env_get_names to communicate auxiliary information to add_key_to_hash. | |
| static char * | iconv_utf8_names [] |
| List of names for the UTF-8 character set. | |
| static char * | iconv_wide_names_unknown [] |
| List of wide character names, undefined byte length. | |
| static char * | iconv_wide_names_4 [] |
| List of wide character names, 4 bytes long. | |
| static char * | iconv_wide_names_2 [] |
| List of wide character names, 2 bytes long. | |
Used both by the client library and by the daemon.
| typedef struct var_uni_entry var_uni_entry_t |
A variable entry.
Stores the value of a variable and whether it should be exported. Obviously, it needs to be allocated large enough to fit the value string.
| void connection_destroy | ( | connection_t * | c | ) |
Close and destroy the specified connection struct.
This frees allstructures allocated by the connection, such as ques of unsent messages.
References b_destroy(), connection::fd, connection::input, q_destroy(), connection::unsent, and wperror().
Referenced by env_universal_destroy(), load_or_save(), and main().
| void connection_init | ( | connection_t * | c, | |
| int | fd | |||
| ) |
Fill in the specified connection_t struct.
Use the specified file descriptor for communication.
References b_init(), connection::buffer_consumed, connection::buffer_used, connection::fd, connection::input, q_init(), and connection::unsent.
Referenced by load_or_save(), and main().
| static void enqueue | ( | void * | k, | |
| void * | v, | |||
| void * | q | |||
| ) | [static] |
Adds a variable creation message about the specified variable to the specified queue.
The function signature is non-obvious since this function is used together with hash_foreach2, which requires the specified function signature.
| k | the variable name | |
| v | the variable value | |
| q | the queue to add the message to |
References message_t::count, create_message(), var_uni_entry::export, q_put(), and var_uni_entry::val.
Referenced by enqueue_all().
| wchar_t* env_universal_common_get | ( | const wchar_t * | name | ) |
Get the value of the variable with the specified name.
This function operate agains the local copy of all universal variables, it does not communicate with any other process.
References hash_get(), and var_uni_entry::val.
Referenced by env_universal_get(), env_universal_remove(), and fishd_env_get().
| int env_universal_common_get_export | ( | const wchar_t * | name | ) |
Get the export flag of the variable with the specified name.
Returns 0 if the variable doesn't exist.
This function operate agains the local copy of all universal variables, it does not communicate with any other process.
References var_uni_entry::export, and hash_get().
Referenced by env_universal_get_export().
| void env_universal_common_get_names | ( | array_list_t * | l, | |
| int | show_exported, | |||
| int | show_unexported | |||
| ) |
Add all variable names to the specified list.
This function operate agains the local copy of all universal variables, it does not communicate with any other process.
References add_key_to_hash(), get_names_show_exported, get_names_show_unexported, and hash_foreach2().
Referenced by env_universal_get_names().
| void env_universal_common_remove | ( | const wchar_t * | name | ) |
Remove variable with specified name.
Remove the specified variable.
References hash_remove().
Referenced by env_universal_common_set(), env_universal_remove(), and parse_message().
| void env_universal_common_set | ( | const wchar_t * | key, | |
| const wchar_t * | val, | |||
| int | export | |||
| ) |
Perform the specified variable assignment.
This function operate agains the local copy of all universal variables, it does not communicate with any other process.
Do not call this function. Create a message to do it. This function is only to be used when fishd is dead.
References callback, CHECK, DIE_MEM, env_universal_common_remove(), var_uni_entry::export, hash_put(), and var_uni_entry::val.
Referenced by env_universal_set(), and parse_message().
| static int try_send | ( | message_t * | msg, | |
| int | fd | |||
| ) | [static] |
Attempt to send the specified message to the specified file descriptor.
References message_t::body, message_t::count, debug(), debug_level, and wperror().
Referenced by try_send_all().
char* iconv_utf8_names[] [static] |
char* iconv_wide_names_2[] [static] |
char* iconv_wide_names_4[] [static] |
char* iconv_wide_names_unknown[] [static] |
1.5.6