如何使用C加入分片的http请求?

y4ekin9u  于 2023-04-05  发布在  其他
关注(0)|答案(1)|浏览(80)

有一个C代码,它通过HTTP接收数据。数据很大(下载)。因此它是碎片化的。我收到这样的东西:

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 28 Mar 2023 22:51:16 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close
Access-Control-Allow-Origin: *

1f75
{"dataUpdate":"HA7hjTuVlq8mmdx8jjS5JGlHsXql7+xnxuIdX3QoKQNjhE5UddJPvnQDDr58g2V7ygg6LuHaCpdN/7t80q/94dmgb3T4dtCzXfNuikfttQHDRf9OAdrxAFrln9QYg5Ts2JqbKipYYXLmYbkuUSaL9e/AVW2eU2Lj357nDdyGl+qIfYzkLlJtXve290LNbyXziZmrHs0TmazFK4Gv4QXzNZNN1ufnrxup1DuuoNQt79p+ktBFUFyZhYuzC0bOafr3PubbACH60eP3ND3elVxcfOFNXGGfcUAD3+fxBT8LnWvl/YIuflin8rWKDLwn70KaOJzBjK4W12z2sZMtv1sIc9GNcwPiJiZy5wVGRPRir088AqSNNRmIVQRlWaUhypd4f5Vb9wSfhKCDTxwGp0/QGxzx9i7IupgTgPBKfju+ZofcfUtReKV/eSbWTaXOSs2079EbshDhDaBtYAK4GR99anFR8l1hdJT2qpV0Su+dOlO9B/ueuXIZjsU2Y5xzV5xqQxjg28K5gAlySPWwo7E6kHndkK5+9a3UqTk3acNlUcg24caJAvHa+M24QrXzP1e2dSfBKWbIW5TJ38FSHBsXjaJZiTGnhe+QBD9S2WuS9wnpRqVihj3DnwwY7xGgMgaiTmtZTu2RsNBCoQZNQvRSxZRfp0b5pdKSX6YK5GRMk8c86P9Jsu9vihcNdiodUnn7ubwSIUpHvyhK9kCejV/REnrDgj5bt+yXwnwj+s1a5LV2C3YOdIrLwj5cFgY9ez0jQPl/FF0HUBNM034VAQUFAelNQEGl9w4qXQQElF4EpPdeQpEOAkGk19CL9N5BWkIPvUPoPQmhBUhI/u+fuZu52b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ps70VH+wqY2sy38lO0dc90ehEYwG6CnmapnyKMdZwgfX4w+iPE6jPB/kBVhWrZZY
2000
1000..... //==other data
"status":"ok"}
 0

如何将其连接到一个JSON片段,如{“dataChunk”:“qwerty”,“status”:“ok”}?我能得到一个免费的解析器代码吗?我试图自己做一个解析器,但不能成功。

char *filterInput(unsigned char* data) {

    data = strstr(data, "{"); //start from the first figure brace
    char *idx = strstr(data, "}"); // cut off data after second figure brace
    data = str_replace(idx, "", data);
    data = concat(data, "}"); // close json with "}"

    //=====remove excess data
    data = str_replace("\r\n0", "", data);
    data = str_replace("\r\n2000\r\n", "", data);
    data = str_replace("\r\n1000\r\n", "", data);
    data = str_replace("\r\nb94\r\n", "", data);
    data = str_replace("\r\n1b94\r\n", "", data);
    data = str_replace("\r\n2b94\r\n", "", data);
    data = str_replace("\r\n3b94\r\n", "", data);
    data = str_replace("\r\n4b94\r\n", "", data);
    data = str_replace("\r\n5b94\r\n", "", data);
    data = str_replace("\r\nfd8\r\n", "", data);
    data = str_replace("\r\nb98\r\n", "", data);
    data = str_replace("\r\n1b98\r\n", "", data);
    data = str_replace("\r\n2b98\r\n", "", data);
    data = str_replace("\r\n3b98\r\n", "", data);
    data = str_replace("\r\n4b98\r\n", "", data);
    data = str_replace("\r\n5b98\r\n", "", data);
    data = str_replace("\r\n6b98\r\n", "", data);
    data = str_replace("\r\n7b98\r\n", "", data);
    data = str_replace("\r\n8b98\r\n", "", data);
    data = str_replace("\r\n14f0\r\n", "", data);

    data = str_replace("\r\n", "", data);
    char *close_brace = strstr(data, "}");

    if (close_brace != NULL) {
        data = str_replace(close_brace, "", data);
        data = strcat(data, "}");
    }
    return data;
}

char* str_replace(const char* search, const char* replace, const char* subject) {
    size_t search_size = strlen(search);
    size_t replace_size = strlen(replace);
    size_t subject_size = strlen(subject);

    // Count the number of occurrences of search in subject
    size_t count = 0;
    const char* p = subject;
    while ((p = strstr(p, search)) != NULL) {
        count++;
        p += search_size;
    }

    // Allocate memory for the new string
    size_t new_size = subject_size + count * (replace_size - search_size);
    char* new_subject = (char*)calloc(new_size + 1, sizeof(char));

    // Replace search with replace in subject
    const char* old = subject;
    char* new_p = new_subject;
    while ((p = strstr(old, search)) != NULL) {
        size_t old_size = p - old;
        memcpy(new_p, old, old_size);
        new_p += old_size;
        memcpy(new_p, replace, replace_size);
        new_p += replace_size;
        old = p + search_size;
    }
    strcpy(new_p, old);

    return new_subject;
}

有很多块要接收,我经常收到垃圾,之后我需要发送JSON到jannsson C库,所以每个字节都很重要。

ddrv8njm

ddrv8njm1#

这是我的最终解决方案,如何解析和连接来自带有body的碎片化HTTP响应的JSON数据。

char *filterInput(char* data) {

    data = strstr(data, "{"); //start from the first figure brace
    char *idx = strstr(data, "}"); // cut off data after second figure brace
    data = str_replace(idx, "", data);
    data = concat(data, "}"); // close json with "}"

    remove_substring_between_newlines(data);

    data = str_replace("\r\n0", "", data);
    data = str_replace("\r\n", "", data);

    char *close_brace = strstr(data, "}");

    if (close_brace != NULL) {
        data = str_replace(close_brace, "", data);
        data = strcat(data, "}");
    }
    return data;
}

void remove_substring_between_newlines(char *string) {
    char *start, *end;

    while ((start = strstr(string, "\r\n")) && (end = strstr(start + 2, "\r\n"))) {
        memmove(start, end + 2, strlen(end + 2) + 1);
    }
}

char *concat(const char *s1, const char *s2) {

    size_t len1 = strlen(s1);
    size_t len2 = strlen(s2);

    char *result = malloc(len1 + len2 + 1);

    if (!result) {
        fprintf(stderr, "malloc() failed: insufficient memory!\n");
        return NULL;
    }

    memcpy(result, s1, len1);
    memcpy(result + len1, s2, len2 + 1);

    return result;
}

char *str_replace(const char *search, const char *replace, const char *subject) {
    size_t search_size = strlen(search);
    size_t replace_size = strlen(replace);
    size_t subject_size = strlen(subject);

    // Count the number of occurrences of search in subject
    size_t count = 0;
    const char *p = subject;
    while ((p = strstr(p, search)) != NULL) {
        count++;
        p += search_size;
    }

    // Allocate memory for the new string
    size_t new_size = subject_size + count * (replace_size - search_size);
    char *new_subject = (char *) calloc(new_size + 1, sizeof(char));

    // Replace search with replace in subject
    const char *old = subject;
    char *new_p = new_subject;
    while ((p = strstr(old, search)) != NULL) {
        size_t old_size = p - old;
        memcpy(new_p, old, old_size);
        new_p += old_size;
        memcpy(new_p, replace, replace_size);
        new_p += replace_size;
        old = p + search_size;
    }
    strcpy(new_p, old);

    return new_subject;
}

相关问题