Skip to content

Commit

Permalink
Expose gpr_asprintf and gpr_strdup
Browse files Browse the repository at this point in the history
  • Loading branch information
soltanmm committed Jun 3, 2015
1 parent ea81bcb commit 701af60
Show file tree
Hide file tree
Showing 60 changed files with 123 additions and 18 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ cc_library(
"include/grpc/support/port_platform.h",
"include/grpc/support/slice.h",
"include/grpc/support/slice_buffer.h",
"include/grpc/support/string_util.h",
"include/grpc/support/subprocess.h",
"include/grpc/support/sync.h",
"include/grpc/support/sync_generic.h",
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2838,6 +2838,7 @@ PUBLIC_HEADERS_C += \
include/grpc/support/port_platform.h \
include/grpc/support/slice.h \
include/grpc/support/slice_buffer.h \
include/grpc/support/string_util.h \
include/grpc/support/subprocess.h \
include/grpc/support/sync.h \
include/grpc/support/sync_generic.h \
Expand Down
1 change: 1 addition & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@
"include/grpc/support/port_platform.h",
"include/grpc/support/slice.h",
"include/grpc/support/slice_buffer.h",
"include/grpc/support/string_util.h",
"include/grpc/support/subprocess.h",
"include/grpc/support/sync.h",
"include/grpc/support/sync_generic.h",
Expand Down
61 changes: 61 additions & 0 deletions include/grpc/support/string_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
*
* Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

#ifndef GRPC_SUPPORT_STRING_UTIL_H
#define GRPC_SUPPORT_STRING_UTIL_H

#ifdef __cplusplus
extern "C" {
#endif

/* String utility functions */

/* Returns a copy of src that can be passed to gpr_free().
If allocation fails or if src is NULL, returns NULL. */
char *gpr_strdup(const char *src);

/* printf to a newly-allocated string. The set of supported formats may vary
between platforms.
On success, returns the number of bytes printed (excluding the final '\0'),
and *strp points to a string which must later be destroyed with gpr_free().
On error, returns -1 and sets *strp to NULL. If the format string is bad,
the result is undefined. */
int gpr_asprintf(char **strp, const char *format, ...);

#ifdef __cplusplus
}
#endif

#endif /* GRPC_SUPPORT_STRING_UTIL_H */
1 change: 1 addition & 0 deletions src/core/channel/channel_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "src/core/support/string.h"

#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>

#include <string.h>

Expand Down
1 change: 1 addition & 0 deletions src/core/httpcli/format_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/slice.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>

static void fill_common_header(const grpc_httpcli_request *request, gpr_strvec *buf) {
Expand Down
1 change: 1 addition & 0 deletions src/core/httpcli/httpcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

typedef struct {
gpr_slice request_text;
Expand Down
1 change: 1 addition & 0 deletions src/core/httpcli/httpcli_security_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/tsi/ssl_transport_security.h"

typedef struct {
Expand Down
1 change: 1 addition & 0 deletions src/core/iomgr/endpoint_pair_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

static void create_sockets(int sv[2]) {
int flags;
Expand Down
3 changes: 2 additions & 1 deletion src/core/iomgr/iomgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/thd.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>

static gpr_mu g_mu;
static gpr_cv g_rcv;
Expand Down
1 change: 1 addition & 0 deletions src/core/iomgr/resolve_address_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>

Expand Down
1 change: 1 addition & 0 deletions src/core/iomgr/resolve_address_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>

Expand Down
1 change: 1 addition & 0 deletions src/core/iomgr/sockaddr_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h>

static const gpr_uint8 kV4MappedPrefix[] = {0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0xff, 0xff};
Expand Down
1 change: 1 addition & 0 deletions src/core/iomgr/tcp_client_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>

typedef struct {
Expand Down
1 change: 1 addition & 0 deletions src/core/iomgr/tcp_server_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

Expand Down
1 change: 1 addition & 0 deletions src/core/iomgr/tcp_server_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/log_win32.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

Expand Down
1 change: 1 addition & 0 deletions src/core/iomgr/tcp_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <grpc/support/log.h>
#include <grpc/support/log_win32.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>

#include "src/core/iomgr/alarm.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/security/client_auth_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/support/string.h"
#include "src/core/channel/channel_stack.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/security/credentials.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

Expand Down
1 change: 1 addition & 0 deletions src/core/security/credentials_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/support/env.h"
#include "src/core/support/string.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/security/credentials_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/support/env.h"
#include "src/core/support/string.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/security/json_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/security/base64.h"
#include "src/core/support/string.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/security/security_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/string_util.h>
#include "src/core/tsi/fake_transport_security.h"
#include "src/core/tsi/ssl_transport_security.h"

Expand Down
1 change: 1 addition & 0 deletions src/core/security/security_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

/* --- grpc_call --- */

Expand Down
1 change: 1 addition & 0 deletions src/core/support/cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

typedef enum { ARGTYPE_INT, ARGTYPE_BOOL, ARGTYPE_STRING } argtype;

Expand Down
1 change: 1 addition & 0 deletions src/core/support/env_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <stdlib.h>

#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/support/string.h"

Expand Down
1 change: 1 addition & 0 deletions src/core/support/env_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <grpc/support/log.h>

#include "src/core/support/string.h"
#include <grpc/support/string_util.h>

char *gpr_getenv(const char *name) {
char *result = getenv(name);
Expand Down
1 change: 1 addition & 0 deletions src/core/support/env_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

char *gpr_getenv(const char *name) {
size_t size;
Expand Down
1 change: 1 addition & 0 deletions src/core/support/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/support/string.h"

Expand Down
1 change: 1 addition & 0 deletions src/core/support/file_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/support/string.h"

Expand Down
1 change: 1 addition & 0 deletions src/core/support/file_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

#include "src/core/support/file.h"
#include "src/core/support/string_win32.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/support/host_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>

int gpr_join_host_port(char **out, const char *host, int port) {
if (host[0] != '[' && strchr(host, ':') != NULL) {
Expand Down
14 changes: 0 additions & 14 deletions src/core/support/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ extern "C" {

/* String utility functions */

/* Returns a copy of src that can be passed to gpr_free().
If allocation fails or if src is NULL, returns NULL. */
char *gpr_strdup(const char *src);

/* flag to include plaintext after a hexdump */
#define GPR_HEXDUMP_PLAINTEXT 0x00000001

Expand All @@ -71,16 +67,6 @@ int gpr_ltoa(long value, char *output);
/* Reverse a run of bytes */
void gpr_reverse_bytes(char *str, int len);

/* printf to a newly-allocated string. The set of supported formats may vary
between platforms.
On success, returns the number of bytes printed (excluding the final '\0'),
and *strp points to a string which must later be destroyed with gpr_free().
On error, returns -1 and sets *strp to NULL. If the format string is bad,
the result is undefined. */
int gpr_asprintf(char **strp, const char *format, ...);

/* Join a set of strings, returning the resulting string.
Total combined length (excluding null terminator) is returned in total_length
if it is non-null. */
Expand Down
1 change: 1 addition & 0 deletions src/core/surface/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "src/core/surface/completion_queue.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <assert.h>

#include <stdio.h>
Expand Down
1 change: 1 addition & 0 deletions src/core/surface/call_log_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>

int grpc_trace_batch = 0;

Expand Down
1 change: 1 addition & 0 deletions src/core/surface/channel_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "src/core/transport/chttp2_transport.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>

Expand Down
1 change: 1 addition & 0 deletions src/core/surface/event_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "src/core/support/string.h"
#include <grpc/byte_buffer.h>
#include <grpc/support/string_util.h>

static void addhdr(gpr_strvec *buf, grpc_event *ev) {
char *tmp;
Expand Down
1 change: 1 addition & 0 deletions src/core/surface/secure_channel_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security_interface.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/surface/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "src/core/transport/metadata.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>

typedef enum { PENDING_START, ALL_CALLS, CALL_LIST_COUNT } call_list;
Expand Down
1 change: 1 addition & 0 deletions src/core/transport/transport_op_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>

/* These routines are here to facilitate debugging - they produce string
Expand Down
Loading

0 comments on commit 701af60

Please sign in to comment.