Browse Source

faux.msg: faux_msg_get_str_param_by_type()

Serj Kalichev 2 years ago
parent
commit
7b5d14c36a
3 changed files with 33 additions and 0 deletions
  1. 1 0
      faux/faux.map
  2. 4 0
      faux/msg.h
  3. 28 0
      faux/msg/msg.c

+ 1 - 0
faux/faux.map

@@ -193,6 +193,7 @@ FAUX_2.0 {
 		faux_msg_get_param_each;
 		faux_msg_get_param_by_index;
 		faux_msg_get_param_by_type;
+		faux_msg_get_str_param_by_type;
 		faux_msg_send;
 		faux_msg_send_async;
 		faux_msg_recv;

+ 4 - 0
faux/msg.h

@@ -110,6 +110,7 @@ int faux_msg_get_len(const faux_msg_t *msg);
 uint32_t faux_msg_get_magic(const faux_msg_t *msg);
 int faux_msg_get_major(const faux_msg_t *msg);
 int faux_msg_get_minor(const faux_msg_t *msg);
+
 ssize_t faux_msg_add_param(faux_msg_t *msg, uint16_t type,
 	const void *buf, size_t len);
 faux_list_node_t *faux_msg_init_param_iter(const faux_msg_t *msg);
@@ -119,6 +120,9 @@ faux_phdr_t *faux_msg_get_param_by_index(const faux_msg_t *msg, unsigned int ind
 	uint16_t *param_type, void **param_data, uint32_t *param_len);
 faux_phdr_t *faux_msg_get_param_by_type(const faux_msg_t *msg,
 	uint16_t param_type, void **param_data, uint32_t *param_len);
+char *faux_msg_get_str_param_by_type(const faux_msg_t *msg,
+	uint16_t param_type);
+
 ssize_t faux_msg_send(const faux_msg_t *msg, faux_net_t *faux_net);
 ssize_t faux_msg_send_async(const faux_msg_t *msg, faux_async_t *async);
 faux_msg_t *faux_msg_recv(faux_net_t *faux_net);

+ 28 - 0
faux/msg/msg.c

@@ -571,6 +571,34 @@ faux_phdr_t *faux_msg_get_param_by_type(const faux_msg_t *msg,
 }
 
 
+/** @brief Gets message string parameter by parameter's type.
+ *
+ * It's the same as faux_msg_get_param_by_type() but it's supposed
+ * the parameter contains text string without ending '\0'. Function
+ * will create C-string dup of this parameter. The resulting line must be freed
+ * later with faux_str_free().
+ *
+ * @sa faux_msg_get_param_by_type()
+ * @param [in] msg Allocated faux_msg_t object.
+ * @param [in] param_type Type of parameter.
+ * @return Pointer to allocated C-string or NULL on error.
+ */
+char *faux_msg_get_str_param_by_type(const faux_msg_t *msg,
+	uint16_t param_type)
+{
+	const char *raw = NULL;
+	uint32_t raw_len = 0;
+	char *line = NULL;
+
+	if (!faux_msg_get_param_by_type(msg, param_type,
+		(void **)&raw, &raw_len))
+		return NULL;
+	line = faux_str_dupn(raw, raw_len);
+
+	return line;
+}
+
+
 /** @brief Create IOV of message.
  *
  * Function creates and fills iovec structure. This iovec contains references