Everywhere: Use slon_mem_task for memory allocation
This commit is contained in:
parent
5333b64917
commit
64f31de070
24 changed files with 146 additions and 139 deletions
|
@ -109,7 +109,7 @@ Bool @slon_activitypub_http_signature_is_valid(SlonHttpSession* session, U8* use
|
|||
U8* signatory_url_string = @slon_strnew(session, keyId);
|
||||
StrFind("#", signatory_url_string)[0] = NULL;
|
||||
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
U8* signatory = db->o("actors")->o(user)->@("id");
|
||||
@http_response* resp = @slon_activitypub_signed_request(signatory_url_string, fetch_buffer, NULL, SLON_HTTP_VERB_GET, signatory);
|
||||
@slon_free(session, signatory_url_string);
|
||||
|
@ -230,7 +230,7 @@ Bool @slon_activitypub_http_signature_is_valid(SlonHttpSession* session, U8* use
|
|||
calc_sha_256(sig_string_hash, sig_string, StrLen(sig_string));
|
||||
|
||||
// Import RSA key
|
||||
U64 rsa_key = CAlloc(sizeof(U64) * 32, adam_task);
|
||||
U64 rsa_key = CAlloc(sizeof(U64) * 32, slon_mem_task);
|
||||
I64 res = @rsa_import(db->o("public_keys")->o(keyId)->@("key"), db->o("public_keys")->o(keyId)->@("length"), rsa_key);
|
||||
if (res != 0) { // CRYPT_OK = 0
|
||||
@slon_log(LOG_HTTPD, "Received error from @rsa_import: %d", res);
|
||||
|
@ -348,7 +348,7 @@ U0 @slon_activitypub_users_get(SlonHttpSession* session)
|
|||
I64 res;
|
||||
|
||||
// Import RSA key
|
||||
U64 rsa_key = CAlloc(sizeof(U64) * 32, adam_task);
|
||||
U64 rsa_key = CAlloc(sizeof(U64) * 32, slon_mem_task);
|
||||
res = @rsa_import(private_key_binary->@("data"), private_key_binary->@("size"), rsa_key);
|
||||
AdamLog("@rsa_import: res: %d\n", res);
|
||||
|
||||
|
@ -423,7 +423,7 @@ U0 @slon_activitypub_async_accept_request(JsonObject* o)
|
|||
accept_object->set("actor", this_actor, JSON_STRING);
|
||||
accept_object->set("object", request, JSON_OBJECT);
|
||||
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
StrPrint(scratch_buffer, "%s/inbox", o->@("actor_for_key_id"));
|
||||
@slon_activitypub_signed_request(scratch_buffer, fetch_buffer, accept_object);
|
||||
Free(fetch_buffer);
|
||||
|
@ -437,7 +437,7 @@ U0 @slon_activitypub_async_create_status_to(JsonObject* status, U8* dest)
|
|||
|
||||
U8 scratch_buffer[2048];
|
||||
|
||||
U8* this_actor = StrNew(status->@("uri"), adam_task);
|
||||
U8* this_actor = StrNew(status->@("uri"), slon_mem_task);
|
||||
StrFind("/statuses/", this_actor)[0] = NULL;
|
||||
|
||||
JsonObject* create_object = Json.CreateObject();
|
||||
|
@ -505,7 +505,7 @@ U0 @slon_activitypub_async_create_status_to(JsonObject* status, U8* dest)
|
|||
note_object->set("shares", SLON_EMPTY_JSON_OBJECT, JSON_OBJECT);
|
||||
|
||||
create_object->set("object", note_object, JSON_OBJECT);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
StrPrint(scratch_buffer, "%s/inbox", dest);
|
||||
@slon_activitypub_signed_request(scratch_buffer, fetch_buffer, create_object);
|
||||
Free(fetch_buffer);
|
||||
|
@ -532,7 +532,7 @@ U0 @slon_activitypub_async_delete_status_to(JsonObject* status, U8* dest)
|
|||
Sleep(1000);
|
||||
U8 scratch_buffer[2048];
|
||||
|
||||
U8* this_actor = StrNew(status->@("uri"), adam_task);
|
||||
U8* this_actor = StrNew(status->@("uri"), slon_mem_task);
|
||||
StrFind("/statuses/", this_actor)[0] = NULL;
|
||||
|
||||
JsonObject* delete_object = Json.CreateObject();
|
||||
|
@ -550,7 +550,7 @@ U0 @slon_activitypub_async_delete_status_to(JsonObject* status, U8* dest)
|
|||
ts_object->set("atomUri", status->@("uri"), JSON_STRING);
|
||||
|
||||
delete_object->set("object", ts_object, JSON_OBJECT);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
StrPrint(scratch_buffer, "%s/inbox", dest);
|
||||
@slon_activitypub_signed_request(scratch_buffer, fetch_buffer, delete_object);
|
||||
Free(fetch_buffer);
|
||||
|
@ -561,7 +561,7 @@ U0 @slon_activitypub_async_follow(JsonObject* follow)
|
|||
{
|
||||
Sleep(1000);
|
||||
U8 scratch_buffer[1024];
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
StrPrint(scratch_buffer, "%s/inbox", follow->@("object"));
|
||||
@slon_activitypub_signed_request(scratch_buffer, fetch_buffer, follow);
|
||||
Free(fetch_buffer);
|
||||
|
@ -618,7 +618,7 @@ JsonObject* @slon_activitypub_get_account_for_remote_actor(SlonHttpSession* sess
|
|||
return NULL;
|
||||
}
|
||||
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
JsonObject* http_headers = Json.CreateObject();
|
||||
http_headers->set("accept", "application/json", JSON_STRING);
|
||||
@http_response* resp = Http.Get(url, fetch_buffer, NULL, http_headers);
|
||||
|
|
|
@ -146,7 +146,7 @@ U0 @slon_api_async_upload_to_catbox(SlonCatboxUpload* cb)
|
|||
|
||||
// build the multipart/form-data payload
|
||||
|
||||
U8* payload = CAlloc(4096 + data_size, adam_task);
|
||||
U8* payload = CAlloc(4096 + data_size, slon_mem_task);
|
||||
I64 payload_size = 0;
|
||||
|
||||
U8* boundary = "----------SlonFormBoundary00";
|
||||
|
@ -174,7 +174,7 @@ U0 @slon_api_async_upload_to_catbox(SlonCatboxUpload* cb)
|
|||
payload_size += StrLen(boundary);
|
||||
|
||||
// build the http headers
|
||||
U8* headers = CAlloc(4096, adam_task);
|
||||
U8* headers = CAlloc(4096, slon_mem_task);
|
||||
String.Append(headers, "POST /user/api.php HTTP/1.1\r\n");
|
||||
String.Append(headers, "Host: catbox.moe\r\n");
|
||||
String.Append(headers, "User-Agent: slon/1.0\r\n");
|
||||
|
@ -182,7 +182,7 @@ U0 @slon_api_async_upload_to_catbox(SlonCatboxUpload* cb)
|
|||
String.Append(headers, "Content-Type: multipart/form-data; boundary=%s\r\n\r\n", boundary);
|
||||
|
||||
I64 send_buffer_size = StrLen(headers) + payload_size;
|
||||
U8* send_buffer = CAlloc(send_buffer_size, adam_task);
|
||||
U8* send_buffer = CAlloc(send_buffer_size, slon_mem_task);
|
||||
|
||||
MemCpy(send_buffer, headers, StrLen(headers));
|
||||
MemCpy(send_buffer + StrLen(headers), payload, payload_size);
|
||||
|
@ -206,7 +206,7 @@ U0 @slon_api_async_upload_to_catbox(SlonCatboxUpload* cb)
|
|||
|
||||
I64 bytes_received = 0;
|
||||
I64 response_buffer_size = 0;
|
||||
U8* response_buffer = CAlloc(4096, adam_task);
|
||||
U8* response_buffer = CAlloc(4096, slon_mem_task);
|
||||
|
||||
while (!bytes_received) {
|
||||
bytes_received = s->receive(response_buffer + response_buffer_size, 4096);
|
||||
|
@ -222,7 +222,7 @@ U0 @slon_api_async_upload_to_catbox(SlonCatboxUpload* cb)
|
|||
url_ptr = StrFind("\r\n", url_ptr) + 2;
|
||||
StrFind("\r\n", url_ptr)[0] = NULL;
|
||||
|
||||
cb->key->value = StrNew(url_ptr, adam_task);
|
||||
cb->key->value = StrNew(url_ptr, slon_mem_task);
|
||||
cb->key->type = JSON_STRING;
|
||||
if (cb->callback) {
|
||||
cb->callback(cb->callback_arg);
|
||||
|
@ -248,7 +248,7 @@ U0 @slon_api_async_delete_from_catbox(U8* filename)
|
|||
|
||||
// build the multipart/form-data payload
|
||||
|
||||
U8* payload = CAlloc(4096, adam_task);
|
||||
U8* payload = CAlloc(4096, slon_mem_task);
|
||||
I64 payload_size = 0;
|
||||
|
||||
U8* boundary = "----------SlonFormBoundary00";
|
||||
|
@ -262,7 +262,7 @@ U0 @slon_api_async_delete_from_catbox(U8* filename)
|
|||
payload_size = StrLen(payload);
|
||||
|
||||
// build the http headers
|
||||
U8* headers = CAlloc(4096, adam_task);
|
||||
U8* headers = CAlloc(4096, slon_mem_task);
|
||||
String.Append(headers, "POST /user/api.php HTTP/1.1\r\n");
|
||||
String.Append(headers, "Host: catbox.moe\r\n");
|
||||
String.Append(headers, "User-Agent: slon/1.0\r\n");
|
||||
|
@ -270,7 +270,7 @@ U0 @slon_api_async_delete_from_catbox(U8* filename)
|
|||
String.Append(headers, "Content-Type: multipart/form-data; boundary=%s\r\n\r\n", boundary);
|
||||
|
||||
I64 send_buffer_size = StrLen(headers) + payload_size;
|
||||
U8* send_buffer = CAlloc(send_buffer_size, adam_task);
|
||||
U8* send_buffer = CAlloc(send_buffer_size, slon_mem_task);
|
||||
|
||||
MemCpy(send_buffer, headers, StrLen(headers));
|
||||
MemCpy(send_buffer + StrLen(headers), payload, payload_size);
|
||||
|
@ -283,7 +283,7 @@ U0 @slon_api_async_delete_from_catbox(U8* filename)
|
|||
|
||||
I64 bytes_received = 0;
|
||||
I64 response_buffer_size = 0;
|
||||
U8* response_buffer = CAlloc(4096, adam_task);
|
||||
U8* response_buffer = CAlloc(4096, slon_mem_task);
|
||||
|
||||
while (!bytes_received) {
|
||||
bytes_received = s->receive(response_buffer + response_buffer_size, 4096);
|
||||
|
|
|
@ -97,7 +97,7 @@ U64 @slon_calloc(SlonHttpSession* session, I64 size)
|
|||
{
|
||||
if (!session || !size)
|
||||
return NULL;
|
||||
U64 res = CAlloc(size, adam_task);
|
||||
U64 res = CAlloc(size, slon_mem_task);
|
||||
session->bytes_used += MSize2(res);
|
||||
// AdamLog("@slon_calloc: requested %d, total used: %d\n", MSize2(res), session->bytes_used);
|
||||
return res;
|
||||
|
@ -116,7 +116,7 @@ U64 @slon_malloc(SlonHttpSession* session, I64 size)
|
|||
{
|
||||
if (!session || !size)
|
||||
return NULL;
|
||||
U64 res = MAlloc(size, adam_task);
|
||||
U64 res = MAlloc(size, slon_mem_task);
|
||||
session->bytes_used += MSize2(res);
|
||||
// AdamLog("@slon_malloc: requested %d, total used: %d\n", MSize2(res), session->bytes_used);
|
||||
return res;
|
||||
|
@ -126,7 +126,7 @@ U8* @slon_strnew(SlonHttpSession* session, U8* str)
|
|||
{
|
||||
if (!session || !str)
|
||||
return NULL;
|
||||
U8* new = StrNew(str, adam_task);
|
||||
U8* new = StrNew(str, slon_mem_task);
|
||||
session->bytes_used += MSize2(new);
|
||||
// AdamLog("@slon_strnew: requested %d, total used: %d\n", MSize2(new), session->bytes_used);
|
||||
// AdamLog("@slon_strnew: %s\n", new);
|
||||
|
|
|
@ -26,7 +26,7 @@ U0 @slon_oauth_fetch_token(U8* client_id)
|
|||
return;
|
||||
}
|
||||
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, adam_task);
|
||||
U8* fetch_buffer = CAlloc(HTTP_FETCH_BUFFER_SIZE, slon_mem_task);
|
||||
StrPrint(url_string, "%s%s", SLON_OAUTH_USERINFO_URL, access_token);
|
||||
@http_response* resp = fetch(url_string, fetch_buffer);
|
||||
|
||||
|
@ -49,7 +49,7 @@ oauth_free_and_return:
|
|||
|
||||
U0 @async_slon_oauth_fetch_token(U8* client_id)
|
||||
{
|
||||
Spawn(&@slon_oauth_fetch_token, StrNew(client_id, adam_task), "OauthFetchTokenTask");
|
||||
Spawn(&@slon_oauth_fetch_token, StrNew(client_id, slon_mem_task), "OauthFetchTokenTask");
|
||||
}
|
||||
|
||||
U8* @slon_oauth_generate_access_token(SlonHttpSession* session)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue