summaryrefslogtreecommitdiff
path: root/test/quic_test_plug.cpp
blob: 1c0ffcbcd49b3e5ef83c5c1e297703bfc27ec7f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 *  author:yangwei
 *  create time:2021-8-21
 *
 */



#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>

#include "cJSON.h"
#include "gquic.h"
#include "MESA_prof_load.h"
#include <MESA/stream.h>

extern "C" int commit_test_result_json(cJSON *node, const char *name);

static int g_result_count = 1;

extern "C" unsigned char QUIC_TEST_PLUG_ENTRY(stSessionInfo *session_info, void **pme,
                             int thread_seq, struct streaminfo *a_tcp, void *a_packet)
{
    assert(NULL != session_info || pme != NULL);

    cJSON *ctx = (cJSON *)*pme;
    struct _quic_info *quic_info=NULL;
    char version_str[128]={0};
    unsigned int version = 0;

    if (session_info->session_state & SESSION_STATE_PENDING)
    {
        if (*pme == NULL)
        {
            ctx = cJSON_CreateObject();
            *pme = (void *)ctx;
            cJSON_AddStringToObject(ctx, "Tuple4", printaddr(&a_tcp->addr, a_tcp->threadnum));
        }
    }

    switch (session_info->prot_flag)
    {
    case QUIC_CLIENT_HELLO:
        if (session_info == NULL || session_info->app_info == NULL)
        {
            break;
        }
        quic_info = (struct _quic_info *)session_info->app_info;
        cJSON_AddStringToObject(ctx, "SNI", (char *)(quic_info->client_hello->ext_tags[quic_info->client_hello->sni_idx].value));
        break;
    case QUIC_USEING_VERSION:
        version = *(unsigned int *)(session_info->buf);
        quic_version_int2string(version, version_str, sizeof(version_str));
        cJSON_AddStringToObject(ctx, "VERSION", version_str);
        break;
    default:
        break;
    }

    if(session_info->session_state&SESSION_STATE_CLOSE)
    {
            if(ctx)
            {
                char result_name[16]="";
                sprintf(result_name,"QUIC_RESULT_%d", g_result_count);
                commit_test_result_json(ctx, result_name);
                g_result_count+=1;
            }
            *pme = NULL;
            return PROT_STATE_DROPME;

    }

    return PROT_STATE_GIVEME;

}

extern "C" int QUIC_TEST_PLUG_INIT()
{
    return 0;
}

extern "C" void QUIC_TEST_PLUG_DESTROY(void)
{
    return ;
}/*CHAR_DESTRORY*/