void bp_sendto(int bp_sockfd, struct URI* dst_bp_endpoint_id_ptr, char* buffer, unsigned int len, int iscustody) { struct BPD_SEND signal_send; struct sockaddr_un bpd_uaddr; struct URI src_bp_endpoint_id; struct URI report_to_bp_endpoint_id; struct URI custodian_bp_endpoint_id; signal_send.signal_type = BPD_SIGNAL_SEND; bpd_uaddr.sun_family = AF_UNIX; strcpy(bpd_uaddr.sun_path, BPD_USOCK_ADDR); // strcpy(signal_send.dst_bp_endpoint_id, // dst_bp_endpoint_id); uri_copy(&signal_send.dst_bp_endpoint_id, dst_bp_endpoint_id_ptr); // signal_send.lifetime = lifetime; uri_assign(&src_bp_endpoint_id, "", ""); uri_copy(&signal_send.src_bp_endpoint_id, &src_bp_endpoint_id); memcpy(signal_send.payload, buffer, len); signal_send.payload_block_length = len; signal_send.iscustody = iscustody; sendto(bp_sockfd, &signal_send, sizeof(signal_send), 0, (struct sockaddr*) &bpd_uaddr, sizeof(bpd_uaddr)); }
/* * Note that only properties that can be populated by the session daemon * (output destination and name) are assigned. */ LTTNG_HIDDEN int lttng_session_descriptor_assign( struct lttng_session_descriptor *dst, const struct lttng_session_descriptor *src) { int ret = 0; if (dst->type != src->type) { ret = -1; goto end; } if (dst->output_type != src->output_type) { ret = -1; goto end; } ret = lttng_session_descriptor_set_session_name(dst, src->name); if (ret) { goto end; } switch (dst->output_type) { case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL: free(dst->output.local); dst->output.local = uri_copy(src->output.local); if (!dst->output.local) { ret = -1; goto end; } break; case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK: { struct lttng_uri *control_copy = NULL, *data_copy = NULL; control_copy = uri_copy(dst->output.network.control); if (!control_copy && dst->output.network.control) { ret = -1; goto end; } data_copy = uri_copy(dst->output.network.data); if (!data_copy && dst->output.network.data) { free(control_copy); ret = -1; goto end; } ret = network_location_set_from_lttng_uris(&dst->output.network, control_copy, data_copy); break; } case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE: goto end; } end: return ret; }
void bpd_bind_list_insert(struct URI* bp_endpoint_id_ptr, struct sockaddr_un* uaddr_ptr, struct sockaddr_in* iaddr_ptr, int local) { struct BIND_STRUCT* bind_struct_ptr; int bothnull = 1; printf("bpd_bind_list_insert upath %s\n", uaddr_ptr->sun_path); bind_struct_ptr = &bpd_bind_list.bind_structs[bpd_bind_list.nr]; // strcpy(bind_struct_ptr->bp_endpoint_id, bp_endpoint_id); uri_copy(&bind_struct_ptr->bp_endpoint_id, bp_endpoint_id_ptr); if (uaddr_ptr != NULL){ memcpy(&bind_struct_ptr->uaddr, uaddr_ptr, sizeof(struct sockaddr_un)); bothnull = 0; } if (iaddr_ptr != NULL){ memcpy(&bind_struct_ptr->iaddr, iaddr_ptr, sizeof(struct sockaddr_in)); bothnull = 0; } // assert(bothnull == 0); if (bothnull == 1){ printf("bpd_bind_list_insert uaddr and iaddr are null ptr!\n"); exit(EXIT_FAILURE); } bind_struct_ptr->valid = 1; bind_struct_ptr->local = local; bpd_bind_list.nr++; }
int urlparse ( const char *str, url_t *url ) { UriParserStateA state; UriPathSegmentA *path; UriUriA uri; char *s, buf[256]; /* Parse */ state.uri = &uri; if (uriParseUriA(&state, str) != URI_SUCCESS) { uriFreeUriMembersA(&uri); return -1; } /* Store raw */ strncpy(url->raw, str, sizeof(url->raw)); /* Copy */ #define uri_copy(y, x)\ if (x.first) {\ size_t len = x.afterLast - x.first;\ strncpy(y, x.first, len);\ y[len] = 0;\ } else {\ *y = 0;\ } uri_copy(url->scheme, uri.scheme); uri_copy(url->host, uri.hostText); uri_copy(url->user, uri.userInfo); uri_copy(url->query, uri.query); uri_copy(url->frag, uri.fragment); uri_copy(buf, uri.portText); if (*buf) url->port = atoi(buf); else url->port = 0; *url->path = 0; path = uri.pathHead; while (path) { strcat(url->path, "/"); uri_copy(buf, path->text); strcat(url->path, buf); path = path->next; } // TODO: query/fragment /* Split user/pass */ s = strstr(url->user, ":"); if (s) { strcpy(url->pass, s+1); *s = 0; } else { *url->pass = 0; } /* Cleanup */ uriFreeUriMembersA(&uri); return 0; }
TEST(Uri, copy_constructor) { Uri uri("http://*****:*****@localhost:80/myfile"); Uri uri_copy(uri); ASSERT_EQ(uri_copy.get_scheme(), "http"); //ASSERT_EQ(uri_copy.get_user(), "minorg"); //ASSERT_EQ(uri_copy.get_password(), "minorg"); ASSERT_EQ(uri_copy.get_host(), "localhost"); ASSERT_EQ(uri_copy.get_port(), 80); ASSERT_EQ(uri_copy.get_path(), "/myfile"); }
int bp_bind(int bp_sockfd, struct URI* bp_endpoint_id_ptr) { struct BPD_BIND signal_bind; struct sockaddr_un bpd_uaddr; signal_bind.signal_type = BPD_SIGNAL_BIND; // strcpy(signal_bind.bp_endpoint_id, bp_endpoint_id); uri_copy(&signal_bind.bp_endpoint_id, bp_endpoint_id_ptr); bpd_uaddr.sun_family = AF_UNIX; strcpy(bpd_uaddr.sun_path, BPD_USOCK_ADDR); sendto(bp_sockfd, &signal_bind, sizeof(signal_bind), 0, (struct sockaddr*) &bpd_uaddr, sizeof(bpd_uaddr)); }
int urlparse ( const char *str, url_t *url ) { UriParserStateA state; UriPathSegmentA *path; UriUriA uri; char *s, buf[256]; if (str == NULL || url == NULL) return -1; urlreset(url); /* Parse */ state.uri = &uri; if (uriParseUriA(&state, str) != URI_SUCCESS) { uriFreeUriMembersA(&uri); return -1; } /* Store raw */ url->raw = strdup(str); /* Copy */ #define uri_copy(y, x)\ if (x.first) {\ size_t len = x.afterLast - x.first;\ y = strndup(x.first, len);\ } #define uri_copy_static(y, x)\ if (x.first) {\ size_t len = x.afterLast - x.first;\ strncpy(y, x.first, len);\ y[len] = '\0';\ } else {\ y[0] = '\0';\ } uri_copy(url->scheme, uri.scheme); uri_copy(url->host, uri.hostText); uri_copy(url->user, uri.userInfo); uri_copy(url->query, uri.query); uri_copy(url->frag, uri.fragment); uri_copy_static(buf, uri.portText); if (*buf) url->port = atoi(buf); else url->port = 0; path = uri.pathHead; while (path) { uri_copy_static(buf, path->text); if (url->path) url->path = realloc(url->path, strlen(url->path) + strlen(buf) + 2); else url->path = calloc(1, strlen(buf) + 2); strcat(url->path, "/"); strcat(url->path, buf); path = path->next; } // TODO: query/fragment /* Split user/pass */ if (url->user) { s = strstr(url->user, ":"); if (s) { url->pass = strdup(s + 1); *s = 0; } } /* Cleanup */ uriFreeUriMembersA(&uri); return 0; }
LTTNG_HIDDEN enum lttng_error_code lttng_session_descriptor_set_default_output( struct lttng_session_descriptor *descriptor, time_t *session_creation_time, const char *absolute_home_path) { enum lttng_error_code ret_code = LTTNG_OK; struct lttng_uri *uris = NULL; switch (descriptor->output_type) { case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NONE: goto end; case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_LOCAL: { int ret; ssize_t uri_ret; char local_uri[LTTNG_PATH_MAX]; char creation_datetime_suffix[17] = {}; if (session_creation_time) { size_t strftime_ret; struct tm *timeinfo; timeinfo = localtime(session_creation_time); if (!timeinfo) { ret_code = LTTNG_ERR_FATAL; goto end; } strftime_ret = strftime(creation_datetime_suffix, sizeof(creation_datetime_suffix), "-%Y%m%d-%H%M%S", timeinfo); if (strftime_ret == 0) { ERR("Failed to format session creation timestamp while setting default local output destination"); ret_code = LTTNG_ERR_FATAL; goto end; } } assert(descriptor->name); ret = snprintf(local_uri, sizeof(local_uri), "file://%s/%s/%s%s", absolute_home_path, DEFAULT_TRACE_DIR_NAME, descriptor->name, creation_datetime_suffix); if (ret >= sizeof(local_uri)) { ERR("Truncation occurred while setting default local output destination"); ret_code = LTTNG_ERR_SET_URL; goto end; } else if (ret < 0) { PERROR("Failed to format default local output URI"); ret_code = LTTNG_ERR_SET_URL; goto end; } uri_ret = uri_parse(local_uri, &uris); if (uri_ret != 1) { ret_code = LTTNG_ERR_SET_URL; goto end; } free(descriptor->output.local); descriptor->output.local = &uris[0]; uris = NULL; break; } case LTTNG_SESSION_DESCRIPTOR_OUTPUT_TYPE_NETWORK: { int ret; ssize_t uri_ret; struct lttng_uri *control = NULL, *data = NULL; uri_ret = uri_parse_str_urls("net://127.0.0.1", NULL, &uris); if (uri_ret != 2) { ret_code = LTTNG_ERR_SET_URL; goto end; } control = uri_copy(&uris[0]); data = uri_copy(&uris[1]); if (!control || !data) { free(control); free(data); ret_code = LTTNG_ERR_SET_URL; goto end; } /* Ownership of uris is transferred. */ ret = network_location_set_from_lttng_uris( &descriptor->output.network, control, data); if (ret) { abort(); ret_code = LTTNG_ERR_SET_URL; goto end; } break; } default: abort(); } end: free(uris); return ret_code; }
if (ErrorSQL < 1) { exception_register(ErrorSQL); } typedescr_register_with_methods(DBConnection, dbconn_t); typedescr_register(DBTransaction, tx_t); } assert(DBConnection); } /* -- D B C O N N B A S E C L A S S ------------------------------------- */ dbconn_t *_dbconn_new(dbconn_t *conn, va_list args) { uri_t *uri = va_arg(args, uri_t *); conn -> status = DBConnUninitialized; conn -> uri = uri_copy(uri); conn -> status = DBConnInitialized; return conn; } void _dbconn_free(dbconn_t *conn) { if (conn) { uri_free(conn -> uri); } } char * _dbconn_tostring(dbconn_t *conn) { return uri_tostring(conn -> uri); } data_t * _dbconn_resolve(dbconn_t *conn, char *name) {