~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to src/network-injection.c

  • Committer: Kay Roepke
  • Author(s): Jan Kneschke
  • Date: 2008-01-23 22:00:28 UTC
  • Revision ID: kay@mysql.com-20080123220028-hq2xqb69apa75fnx
first round on mysql-shell based on the proxy code

this is mostly a verification if the proxy-code is flexible enough to handle 
all three scenarios of: client, server and forwarding (proxy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $%BEGINLICENSE%$
2
 
 Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
3
 
 
4
 
 This program is free software; you can redistribute it and/or
5
 
 modify it under the terms of the GNU General Public License as
6
 
 published by the Free Software Foundation; version 2 of the
7
 
 License.
8
 
 
9
 
 This program is distributed in the hope that it will be useful,
10
 
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 
 GNU General Public License for more details.
13
 
 
14
 
 You should have received a copy of the GNU General Public License
15
 
 along with this program; if not, write to the Free Software
16
 
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
 
 02110-1301  USA
18
 
 
19
 
 $%ENDLICENSE%$ */
20
 
 
21
 
 
22
 
#include <string.h>
23
 
 
24
 
#include "network-injection.h"
25
 
 
26
 
#include "network-mysqld-proto.h"
27
 
#include "network-mysqld-packet.h"
28
 
#include "glib-ext.h"
29
 
#include "lua-env.h"
30
 
#include "chassis-timings.h"
31
 
 
32
 
#define C(x) x, sizeof(x) - 1
33
 
#define S(x) x->str, x->len
34
 
 
35
 
#define TIME_DIFF_US(t2, t1) \
36
 
((t2.tv_sec - t1.tv_sec) * 1000000.0 + (t2.tv_usec - t1.tv_usec))
37
 
 
38
 
 
39
 
/**
40
 
 * Initialize an injection struct.
41
 
 */
42
 
injection *injection_new(int id, GString *query) {
43
 
        injection *i;
44
 
    
45
 
        i = g_new0(injection, 1);
46
 
        i->id = id;
47
 
        i->query = query;
48
 
        i->resultset_is_needed = FALSE; /* don't buffer the resultset */
49
 
    
50
 
        /**
51
 
         * we have to assume that injection_new() is only used by the read_query call
52
 
         * which should be fine
53
 
         */
54
 
        i->ts_read_query = chassis_get_rel_microseconds();
55
 
        /* g_get_current_time(&(i->ts_read_query)); */
56
 
    
57
 
        return i;
58
 
}
59
 
 
60
 
/**
61
 
 * Free an injection struct
62
 
 */
63
 
void injection_free(injection *i) {
64
 
        if (!i) return;
65
 
    
66
 
        if (i->query) g_string_free(i->query, TRUE);
67
 
    
68
 
        g_free(i);
69
 
}
70
 
 
71
 
network_injection_queue *network_injection_queue_new() {
72
 
        return g_queue_new();
73
 
}
74
 
 
75
 
void network_injection_queue_free(network_injection_queue *q) {
76
 
        if (!q) return;
77
 
 
78
 
        network_injection_queue_reset(q);
79
 
 
80
 
        g_queue_free(q);
81
 
}
82
 
 
83
 
void network_injection_queue_reset(network_injection_queue *q) {
84
 
        injection *inj;
85
 
        if (!q) return;
86
 
        
87
 
        while ((inj = g_queue_pop_head(q))) injection_free(inj);
88
 
}
89
 
 
90
 
void network_injection_queue_append(network_injection_queue *q, injection *inj) {
91
 
        g_queue_push_tail(q, inj);
92
 
}
93
 
 
94
 
void network_injection_queue_prepend(network_injection_queue *q, injection *inj) {
95
 
        g_queue_push_head(q, inj);
96
 
}
97
 
 
98
 
guint network_injection_queue_len(network_injection_queue *q) {
99
 
        return q->length;
100
 
}
101
 
/**
102
 
 * Initialize a resultset struct
103
 
 */
104
 
proxy_resultset_t *proxy_resultset_init() {
105
 
        return proxy_resultset_new();
106
 
}
107
 
 
108
 
proxy_resultset_t *proxy_resultset_new() {
109
 
        proxy_resultset_t *res;
110
 
    
111
 
        res = g_new0(proxy_resultset_t, 1);
112
 
    
113
 
        return res;
114
 
}
115
 
 
116
 
/**
117
 
 * Free a resultset struct
118
 
 */
119
 
void proxy_resultset_free(proxy_resultset_t *res) {
120
 
        if (!res) return;
121
 
    
122
 
        if (res->fields) {
123
 
                network_mysqld_proto_fielddefs_free(res->fields);
124
 
        }
125
 
    
126
 
        g_free(res);
127
 
}
128
 
 
129