<commit_before>/*
  Author: Harshavardhana <<EMAIL>>
  Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com>

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <errno.h>
#include <sys/stat.h>
#include <curl/curl.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>

#include "s3-priv.h"
#include "s3.h"


/*
  SYNOPSIS

  s3_curl_write: handles writing to I/O buffer

  PARAMETERS:
  @ptr - pointer to the incoming data
  @size - size of the individual data member
  @nmemb - total number of data members
  @stream - stream pointer to allocated io buffer

  RETURN VALUES:
  N : Total number of bytes processed
*/

static size_t s3_curl_write (void *ptr, size_t size, size_t nmemb, void *stream)
{
        return s3_iobuf_add (stream, ptr, (nmemb * size));
}

/*
  SYNOPSIS

  s3_curl_read: Handles reading through stream per line

  PARAMETERS:
  @ptr - pointer to the incoming data
  @size - size of the individual data member
  @nmemb - total number of data members
  @stream - stream pointer to allocated io buffer

  RETURN VALUES:
  N : Total number of bytes sent
*/

static size_t s3_curl_read (void *ptr, size_t size, size_t nmemb, void *stream)
{
        return s3_iobuf_getline (stream, ptr, (nmemb * size));
}

/*
  SYNOPSIS

  process_header: Process incoming header

  PARAMETERS:
  @ptr - pointer to the incoming data
  @size - size of the individual data member
  @nmemb - total number of data members
  @stream - stream pointer to allocated io buffer

  RETURN VALUES:
  N : Total number of bytes sent
*/

static size_t process_header (void *ptr, size_t size, size_t nmemb,
                              void *stream)
{
        iobuf_t *buf = NULL;

        if (!stream)
                return -1;

        if (!strncmp (ptr, "HTTP/1.1", 8)) {
                buf->reply = strdup ((char *)ptr + 9);
                _chomp (buf->reply);
                buf->code = atoi ((char *)ptr + 9);
        } else if (!strncmp (ptr, "Etag: ", 6)) {
                buf->etag = strdup ((char *)ptr + 6);
                _chomp (buf->etag);
        } else if (!strncmp (ptr, "Last-Modified: ", 14)) {
                buf->lastmod = strdup ((char *)ptr + 15);
                _chomp (buf->lastmod);
        } else if (!strncmp (ptr, "Content-Length: ", 15)) {
                buf->contentlen = atoi ((char *)ptr + 16);
        }

        return (nmemb * size);
}

static
char *__s3_sign (const char *str, const char *awskey)
{
        uchar_t   *MD;
        char      *base64 = NULL;<commit_msg>s3: Fix iobuf object wasn't initialized<commit_after>/*
  Author: Harshavardhana <<EMAIL>>
  Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com>

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <stdint.h>
#include <errno.h>
#include <sys/stat.h>
#include <curl/curl.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>

#include "s3-priv.h"
#include "s3.h"


/*
  SYNOPSIS

  s3_curl_write: handles writing to I/O buffer

  PARAMETERS:
  @ptr - pointer to the incoming data
  @size - size of the individual data member
  @nmemb - total number of data members
  @stream - stream pointer to allocated io buffer

  RETURN VALUES:
  N : Total number of bytes processed
*/

static size_t s3_curl_write (void *ptr, size_t size, size_t nmemb, void *stream)
{
        return s3_iobuf_add (stream, ptr, (nmemb * size));
}

/*
  SYNOPSIS

  s3_curl_read: Handles reading through stream per line

  PARAMETERS:
  @ptr - pointer to the incoming data
  @size - size of the individual data member
  @nmemb - total number of data members
  @stream - stream pointer to allocated io buffer

  RETURN VALUES:
  N : Total number of bytes sent
*/

static size_t s3_curl_read (void *ptr, size_t size, size_t nmemb, void *stream)
{
        return s3_iobuf_getline (stream, ptr, (nmemb * size));
}

/*
  SYNOPSIS

  process_header: Process incoming header

  PARAMETERS:
  @ptr - pointer to the incoming data
  @size - size of the individual data member
  @nmemb - total number of data members
  @stream - stream pointer to allocated io buffer

  RETURN VALUES:
  N : Total number of bytes sent
*/

static size_t process_header (void *ptr, size_t size, size_t nmemb,
                              void *stream)
{
        iobuf_t *buf = NULL;

        if (!stream)
                return -1;

        buf = s3_iobuf_new();
        if (!buf)
                return -1;

        if (!strncmp (ptr, "HTTP/1.1", 8)) {
                buf->reply = strdup ((char *)ptr + 9);
                _chomp (buf->reply);
                buf->code = atoi ((char *)ptr + 9);
        } else if (!strncmp (ptr, "Etag: ", 6)) {
                buf->etag = strdup ((char *)ptr + 6);
                _chomp (buf->etag);
        } else if (!strncmp (ptr, "Last-Modified: ", 14)) {
                buf->lastmod = strdup ((char *)ptr + 15);
                _chomp (buf->lastmod);
        } else if (!strncmp (ptr, "Content-Length: ", 15)) {
                buf->contentlen = atoi ((char *)ptr + 16);
        }

        return (nmemb * size);
}

static
char *__s3_sign (const char *str, const char *awskey)
{
        uchar_t   *MD;
        char      *base64 = NULL;
{'fraction_non_alphanumeric': 0.1089922480620155, 'fraction_numerical': 0.01131782945736434, 'mean_word_length': 2.601898380792853, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5237584', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2056, 'n_words': 744}