static void _get_driver_info (mongoc_handshake_t *handshake) { handshake->driver_name = bson_strndup ("mongoc", HANDSHAKE_DRIVER_NAME_MAX); handshake->driver_version = bson_strndup (MONGOC_VERSION_S, HANDSHAKE_DRIVER_VERSION_MAX); }
static char * _get_os_type (void) { #ifdef MONGOC_OS_TYPE return bson_strndup (MONGOC_OS_TYPE, METADATA_OS_TYPE_MAX); #endif return bson_strndup ("unknown", METADATA_OS_TYPE_MAX); }
static void _get_driver_info (mongoc_metadata_t *metadata) { metadata->driver_name = bson_strndup ("mongoc", METADATA_DRIVER_NAME_MAX); metadata->driver_version = bson_strndup (MONGOC_VERSION_S, METADATA_DRIVER_VERSION_MAX); }
static char * _get_os_type (void) { #ifdef MONGOC_OS_TYPE return bson_strndup (MONGOC_OS_TYPE, HANDSHAKE_OS_TYPE_MAX); #else return bson_strndup ("unknown", HANDSHAKE_OS_TYPE_MAX); #endif }
static bool mongoc_uri_parse_userpass (mongoc_uri_t *uri, const char *str, const char **end) { bool ret = false; const char *end_userpass; const char *end_user; char *s; if ((s = scan_to_unichar(str, '@', "", &end_userpass))) { if ((uri->username = scan_to_unichar(s, ':', "", &end_user))) { uri->password = bson_strdup(end_user + 1); } else { uri->username = bson_strndup(str, end_userpass - str); uri->password = NULL; } mongoc_uri_do_unescape(&uri->username); mongoc_uri_do_unescape(&uri->password); *end = end_userpass + 1; bson_free(s); ret = true; } else { ret = true; } return ret; }
static char * scan_to_unichar (const char *str, bson_unichar_t match, const char *terminators, const char **end) { bson_unichar_t c; const char *iter; for (iter = str; iter && *iter && (c = bson_utf8_get_char(iter)); iter = bson_utf8_next_char(iter)) { if (c == match) { *end = iter; return bson_strndup(str, iter - str); } else if (c == '\\') { iter = bson_utf8_next_char(iter); if (!bson_utf8_get_char(iter)) { break; } } else { const char *term_iter; for (term_iter = terminators; *term_iter; term_iter++) { if (c == *term_iter) { return NULL; } } } } return NULL; }
static char * _get_distro_name (void) { /* TODO: FIXME: Will be part of a future CR */ /* This will likely have its own file at some point. */ return bson_strndup ("Linux", METADATA_OS_NAME_MAX); }
static char * scan_to_unichar (const char *str, bson_unichar_t stop, const char **end) { bson_unichar_t c; const char *iter; for (iter = str; iter && *iter && (c = bson_utf8_get_char(iter)); iter = bson_utf8_next_char(iter)) { if (c == stop) { *end = iter; return bson_strndup(str, iter - str); } else if (c == '\\') { iter = bson_utf8_next_char(iter); if (!bson_utf8_get_char(iter)) { break; } } } return NULL; }
static char * _get_os_name (void) { #ifdef MONGOC_OS_NAME return bson_strndup (MONGOC_OS_NAME, HANDSHAKE_OS_NAME_MAX); #elif defined(_POSIX_VERSION) struct utsname system_info; if (uname (&system_info) >= 0) { return bson_strndup (system_info.sysname, HANDSHAKE_OS_NAME_MAX); } #endif return NULL; }
static char * _get_os_name (void) { #ifdef MONGOC_OS_NAME return bson_strndup (MONGOC_OS_NAME, METADATA_OS_NAME_MAX); #elif defined (MONGOC_OS_IS_LINUX) return _get_distro_name (); #elif defined (_POSIX_VERSION) struct utsname system_info; if (uname (&system_info) >= 0) { return bson_strndup (system_info.sysname, METADATA_OS_NAME_MAX); } #endif return NULL; }
void test_add_spec_test (TestSuite *suite, const char *filename, test_hook callback) { bson_t *test; char *skip_json; test = get_bson_from_json_file ((char *)filename); skip_json = strstr (filename, "json")+4; skip_json = bson_strndup (skip_json, strlen (skip_json)-5); TestSuite_AddWC (suite, skip_json, (void (*)(void *))callback, (void (*)(void*))bson_destroy, test); bson_free (skip_json); }
static char * _get_os_architecture (void) { const char *ret = NULL; #ifdef _WIN32 SYSTEM_INFO system_info; DWORD arch; GetSystemInfo (&system_info); arch = system_info.wProcessorArchitecture; switch (arch) { case PROCESSOR_ARCHITECTURE_AMD64: ret = "x86_64"; break; case PROCESSOR_ARCHITECTURE_ARM: ret = "ARM"; break; case PROCESSOR_ARCHITECTURE_IA64: ret = "IA64"; break; case PROCESSOR_ARCHITECTURE_INTEL: ret = "x86"; break; case PROCESSOR_ARCHITECTURE_UNKNOWN: ret = "Unknown"; break; default: ret = "Other"; break; } #elif defined(_POSIX_VERSION) struct utsname system_info; if (uname (&system_info) >= 0) { ret = system_info.machine; } #endif if (ret) { return bson_strndup (ret, HANDSHAKE_OS_ARCHITECTURE_MAX); } return NULL; }
static bool mongoc_uri_parse_hosts (mongoc_uri_t *uri, const char *str, const char **end) { bool ret = false; const char *end_hostport; const char *sock; const char *tmp; char *s; /* * Parsing the series of hosts is a lot more complicated than you might * imagine. This is due to some characters being both separators as well as * valid characters within the "hostname". In particularly, we can have file * paths to specify paths to UNIX domain sockets. We impose the restriction * that they must be suffixed with ".sock" to simplify the parsing. * * You can separate hosts and file system paths to UNIX domain sockets with * ",". * * When you reach a "/" or "?" that is not part of a file-system path, we * have completed our parsing of hosts. */ again: if (((*str == '/') && (sock = strstr(str, ".sock"))) && (!(tmp = strstr(str, ",")) || (tmp > sock)) && (!(tmp = strstr(str, "?")) || (tmp > sock))) { s = bson_strndup(str, sock + 5 - str); if (!mongoc_uri_parse_host(uri, s)) { bson_free(s); return false; } bson_free(s); str = sock + 5; ret = true; if (*str == ',') { str++; goto again; } } else if ((s = scan_to_unichar(str, ',', "/", &end_hostport))) { if (!mongoc_uri_parse_host(uri, s)) { bson_free(s); return false; } bson_free(s); str = end_hostport + 1; ret = true; goto again; } else if ((s = scan_to_unichar(str, '/', "", &end_hostport)) || (s = scan_to_unichar(str, '?', "", &end_hostport))) { if (!mongoc_uri_parse_host(uri, s)) { bson_free(s); return false; } bson_free(s); *end = end_hostport; return true; } else if (*str) { if (!mongoc_uri_parse_host(uri, str)) { return false; } *end = str + strlen(str); return true; } return ret; }