1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Move p_sha1_hash() to stanza.c

Move `p_sha1_hash()` from `common.c` to	`xmpp/stanza.c` as it is only
used in this file and now depends on libstrophe so xmpp is a better
namespace folder.
Renaming it as `_stanza_create_sha1_hash()`. And making static since
only used here.

The function cannot be tested in the unit tests anymore.
Once functional tests are working again we should write a test for the
sha1 functionality.
This commit is contained in:
Michael Vetter 2018-09-06 20:32:08 +02:00
parent 9e021d5c8f
commit 82f8083b85
6 changed files with 18 additions and 90 deletions

View File

@ -55,7 +55,6 @@
#include "log.h"
#include "common.h"
#include <strophe.h>
struct curl_data_t
{
@ -330,21 +329,6 @@ release_is_new(char *found_version)
}
}
char*
p_sha1_hash(char *str)
{
unsigned char *digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE);
assert(digest != NULL);
xmpp_sha1_digest((unsigned char*)str, strlen(str), digest);
char *b64 = g_base64_encode(digest, XMPP_SHA1_DIGEST_SIZE);
assert(b64 != NULL);
free(digest);
return b64;
}
static size_t
_data_callback(void *ptr, size_t size, size_t nmemb, void *data)
{

View File

@ -92,8 +92,6 @@ char* file_getline(FILE *stream);
char* release_get_latest(void);
gboolean release_is_new(char *found_version);
char* p_sha1_hash(char *str);
char* get_file_or_linked(char *loc, char *basedir);
char* strip_arg_quotes(const char *const input);
gboolean is_notify_enabled(void);

View File

@ -45,6 +45,7 @@
#include <stdio.h>
#include <libgen.h>
#include <inttypes.h>
#include <assert.h>
#include <glib.h>
@ -66,6 +67,7 @@
#include "xmpp/muc.h"
static void _stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix);
static char* _stanza_create_sha1_hash(char *str);
#if 0
xmpp_stanza_t*
@ -1143,7 +1145,7 @@ stanza_create_caps_sha1_from_query(xmpp_stanza_t *const query)
curr = g_slist_next(curr);
}
char *result = p_sha1_hash(s->str);
char *result = _stanza_create_sha1_hash(s->str);
g_string_free(s, TRUE);
g_slist_free_full(identities, g_free);
@ -2045,3 +2047,18 @@ _stanza_add_unique_id(xmpp_stanza_t *stanza, char *prefix)
xmpp_stanza_set_id(stanza, id);
free(id);
}
static char*
_stanza_create_sha1_hash(char *str)
{
unsigned char *digest = (unsigned char*)malloc(XMPP_SHA1_DIGEST_SIZE);
assert(digest != NULL);
xmpp_sha1_digest((unsigned char*)str, strlen(str), digest);
char *b64 = g_base64_encode(digest, XMPP_SHA1_DIGEST_SIZE);
assert(b64 != NULL);
free(digest);
return b64;
}

File diff suppressed because one or more lines are too long

View File

@ -19,14 +19,6 @@ void test_dnd_is_valid_resource_presence_string(void **state);
void test_available_is_not_valid_resource_presence_string(void **state);
void test_unavailable_is_not_valid_resource_presence_string(void **state);
void test_blah_is_not_valid_resource_presence_string(void **state);
void test_p_sha1_hash1(void **state);
void test_p_sha1_hash2(void **state);
void test_p_sha1_hash3(void **state);
void test_p_sha1_hash4(void **state);
void test_p_sha1_hash5(void **state);
void test_p_sha1_hash6(void **state);
void test_p_sha1_hash6(void **state);
void test_p_sha1_hash7(void **state);
void utf8_display_len_null_str(void **state);
void utf8_display_len_1_non_wide(void **state);
void utf8_display_len_1_wide(void **state);

View File

@ -78,13 +78,6 @@ int main(int argc, char* argv[]) {
unit_test(test_available_is_not_valid_resource_presence_string),
unit_test(test_unavailable_is_not_valid_resource_presence_string),
unit_test(test_blah_is_not_valid_resource_presence_string),
unit_test(test_p_sha1_hash1),
unit_test(test_p_sha1_hash2),
unit_test(test_p_sha1_hash3),
unit_test(test_p_sha1_hash4),
unit_test(test_p_sha1_hash5),
unit_test(test_p_sha1_hash6),
unit_test(test_p_sha1_hash7),
unit_test(utf8_display_len_null_str),
unit_test(utf8_display_len_1_non_wide),
unit_test(utf8_display_len_1_wide),