Skip to content

[sds] add flb_sds_cat_replace: concatenate a string by replacing a set of chars#1365

Merged
edsiper merged 4 commits intofluent:masterfrom
manuelluis:mlsr/gelf-chars
Jan 15, 2020
Merged

[sds] add flb_sds_cat_replace: concatenate a string by replacing a set of chars#1365
edsiper merged 4 commits intofluent:masterfrom
manuelluis:mlsr/gelf-chars

Conversation

@manuelluis
Copy link
Contributor

No description provided.

@manuelluis
Copy link
Contributor Author

Fixes #1291

@edsiper
Copy link
Member

edsiper commented Sep 2, 2019

would flb_sds_copy() solve the requirement ?

@edsiper edsiper added the waiting-for-user Waiting for more information, tests or requested changes label Sep 2, 2019
@manuelluis
Copy link
Contributor Author

No, flb_sds_copy() not solve the problem.
I was trying to make a generic implementation to replace a set of characters when concatenate a string, but it was a bit over-engineering.

We can do with in a simple for loop after concatenate the string:

int i;
flb_sds_t tmp;
/* check valid key char [A-Za-z0-9_\.\-] */
static char valid_char[256] = {
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
   0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

if (in_array == FLB_FALSE) {
    tmp = flb_sds_cat(*s, ", \"", 3);
    if (tmp == NULL) return NULL;
    *s = tmp;
}

if (prefix_key_len > 0) {
    int start_len, end_len;

    start_len = flb_sds_len(s);

    tmp = flb_sds_cat(*s, prefix_key, prefix_key_len);
    if (tmp == NULL) return NULL;
    *s = tmp;

    end_len = flb_sds_len(s);
    for(i=start_len; i < end_len; i++) {
        if (!valid_char[(unsigned char)(*s)[i]]) {
            (*s)[i] = '_';
        }
    }
}

if (concat == FLB_TRUE) {
    tmp = flb_sds_cat(*s, "_", 1);
    if (tmp == NULL) return NULL;
    *s = tmp;
}

if (key_len > 0) {
    int start_len, end_len;

    start_len = flb_sds_len(s);

    tmp = flb_sds_cat(*s, prefix_key, prefix_key_len);
    if (tmp == NULL) return NULL;
    *s = tmp;

    end_len = flb_sds_len(s);
    for(i=start_len; i < end_len; i++) {
        if (!valid_char[(unsigned char)(*s)[i]]) {
            (*s)[i] = '_';
        }
    }
}

@edsiper
Copy link
Member

edsiper commented Sep 21, 2019

got it.

Please resolve the conflicts and we are ready to go

@bluebike
Copy link
Contributor

I would split this to two commits.

  1. add flb_sds_t flb_sds_cat_replace ( src/flb_sds.c , include/fluent-bit/flb_sds.h )
  2. flb_msgpack_gelf_key ( src/flb_pack.c )

…t of chars

Signed-off-by: Manuel Luis Sanmartín Rozada <manuel.luis@gmail.com>
Signed-off-by: Manuel Luis Sanmartín Rozada <manuel.luis@gmail.com>
Signed-off-by: Manuel Luis Sanmartín Rozada <manuel.luis@gmail.com>
Signed-off-by: Manuel Luis Sanmartín Rozada <manuel.luis@gmail.com>
@wrossmann
Copy link

Is this going to get merged at some point?

@edsiper edsiper merged commit 1945e6f into fluent:master Jan 15, 2020
@edsiper
Copy link
Member

edsiper commented Jan 15, 2020

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-user Waiting for more information, tests or requested changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants