str_replace on %%2B

cin34

Member
Joined
Jan 23, 2016
Messages
32
Reaction score
15
Points
58
Hi, I have a problem replacing the characters in the id.
I would like to replace "+" with "%% 2B".

My code:

Code:
void ts3plugin_infoData(uint64 serverConnectionHandlerID, uint64 id, enum PluginItemType type, char** data) {
    char* name;
    char* uid;

    switch(type) {
            break;
        case PLUGIN_CLIENT:
            if(ts3Functions.getClientVariableAsString(serverConnectionHandlerID, (anyID)id, CLIENT_NICKNAME, &name) != ERROR_ok) {
                printf("Error getting client nickname\n");
                return;
            }

            if (ts3Functions.getClientVariableAsString(serverConnectionHandlerID, (anyID)id, CLIENT_UNIQUE_IDENTIFIER, &uid) != ERROR_ok) {
                printf("Error getting client identifier\n");
                return;
            }
            break;
        default:
            printf("Invalid item type: %d\n", type);
            data = NULL;  /* Ignore */
            return;
    }


    *data = (char*)malloc(INFODATA_BUFSIZE * sizeof(char));
    char *c = str_replace("+", "test", uid);
    snprintf(*data, INFODATA_BUFSIZE, "Client mysite: [URL=http://mysite.com/?page=searchclient&uid=%s]\"%s\"[/URL]", c, name); 
    ts3Functions.freeMemory(name);
    ts3Functions.freeMemory(uid);
}
Will anyone help me?
Thanks.
 

cin34

Member
Joined
Jan 23, 2016
Messages
32
Reaction score
15
Points
58
I did this:

Code:
char to_hex(char code) {
    static char hex[] = "0123456789abcdef";
    return hex[code & 15];
}

char *url_encode(char *str) {
    char *pstr = str, *buf = malloc(strlen(str) * 3 + 1), *pbuf = buf;
    while (*pstr) {
        if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
            *pbuf++ = *pstr;
        else if (*pstr == ' ')
            *pbuf++ = '+';
        else
            *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
        pstr++;
    }
    *pbuf = '\0';
    return buf;
}

void ts3plugin_infoData(uint64 serverConnectionHandlerID, uint64 id, enum PluginItemType type, char** data) {
    char* name;
    char* uid;

    /* For demonstration purpose, display the name of the currently selected server, channel or client. */
    switch(type) {
            break;
        case PLUGIN_CLIENT:
            if(ts3Functions.getClientVariableAsString(serverConnectionHandlerID, (anyID)id, CLIENT_NICKNAME, &name) != ERROR_ok) {
                printf("Error getting client nickname\n");
                return;
            }

            if (ts3Functions.getClientVariableAsString(serverConnectionHandlerID, (anyID)id, CLIENT_UNIQUE_IDENTIFIER, &uid) != ERROR_ok) {
                printf("Error getting client identifier\n");
                return;
            }
            break;
        default:
            printf("Invalid item type: %d\n", type);
            data = NULL;  /* Ignore */
            return;
    }
   
    *data = (char*)malloc(INFODATA_BUFSIZE * sizeof(char));
    snprintf(*data, INFODATA_BUFSIZE, "Client mysite: [URL=http://mysite.com/?uid=%s]\"%s\"[/URL]", url_encode(uid), name);
    ts3Functions.freeMemory(name);
    ts3Functions.freeMemory(uid);

}

But when I click on some users in the client teamspeak this is showing me this box.

ETuM0KL.png
 

Bluscream

Retired Staff
Contributor
Joined
May 8, 2015
Messages
967
Reaction score
934
Points
211
Make sure your INFODATA_BUFSIZE is > 512
 

cin34

Member
Joined
Jan 23, 2016
Messages
32
Reaction score
15
Points
58
Thanks.
I have increased the definition of INFODATA_BUFSIZE to 512 and it now works. :)
The default was 128.
 
Last edited:
Top