mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-27 11:26:21 +00:00
Move code from jid_random_resource() into own function
Move the code that creates a random string into it's own function +get_random_string().
This commit is contained in:
@@ -198,18 +198,10 @@ jid_fulljid_or_barejid(Jid *jid)
|
||||
char*
|
||||
jid_random_resource(void)
|
||||
{
|
||||
GRand *prng;
|
||||
char rand[5];
|
||||
char alphabet[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
char *rand = get_random_string(4);
|
||||
|
||||
prng = g_rand_new();
|
||||
gchar *result = g_strdup_printf("profanity.%s", rand);
|
||||
free(rand);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
rand[i] = alphabet[g_rand_int_range(prng, 0, sizeof(alphabet))];
|
||||
}
|
||||
rand[4] = '\0';
|
||||
g_rand_free(prng);
|
||||
|
||||
return g_strdup_printf("profanity.%s", rand);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user