Browse code

utils: fixed indentation

Daniel-Constantin Mierla authored on 17/06/2015 14:12:44
Showing 1 changed files
... ...
@@ -52,25 +52,25 @@
52 52
  */
53 53
 size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr)
54 54
 {
55
-    http_res_stream_t *stream = (http_res_stream_t *) stream_ptr;
55
+	http_res_stream_t *stream = (http_res_stream_t *) stream_ptr;
56 56
 
57
-    stream->buf = (char *) pkg_realloc(stream->buf, stream->curr_size + 
58
-				(size * nmemb) + 1);
57
+	stream->buf = (char *) pkg_realloc(stream->buf, stream->curr_size + 
58
+			(size * nmemb) + 1);
59 59
 
60
-    if (stream->buf == NULL) {
61
-	LM_ERR("cannot allocate memory for stream\n");
62
-	return CURLE_WRITE_ERROR;
63
-    }
60
+	if (stream->buf == NULL) {
61
+		LM_ERR("cannot allocate memory for stream\n");
62
+		return CURLE_WRITE_ERROR;
63
+	}
64 64
 
65
-    memcpy(&stream->buf[stream->pos], (char *) ptr, (size * nmemb));
65
+	memcpy(&stream->buf[stream->pos], (char *) ptr, (size * nmemb));
66 66
 
67
-    stream->curr_size += ((size * nmemb) + 1);
68
-    stream->pos += (size * nmemb);
67
+	stream->curr_size += ((size * nmemb) + 1);
68
+	stream->pos += (size * nmemb);
69 69
 
70
-    stream->buf[stream->pos + 1] = '\0';
70
+	stream->buf[stream->pos + 1] = '\0';
71 71
 
72
-    return size * nmemb;
73
- }
72
+	return size * nmemb;
73
+}
74 74
 
75 75
 
76 76
 /* 
... ...
@@ -79,73 +79,73 @@ size_t write_function( void *ptr, size_t size, size_t nmemb, void *stream_ptr)
79 79
  */
80 80
 int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post)
81 81
 {
82
-    CURL *curl;
83
-    CURLcode res;  
84
-    str value, post_value;
85
-    char *url, *at, *post;
86
-    http_res_stream_t stream;
87
-    long stat;
88
-    pv_spec_t *dst;
89
-    pv_value_t val;
90
-    double download_size;
91
-
92
-    memset(&stream, 0, sizeof(http_res_stream_t));
93
-
94
-    if (fixup_get_svalue(_m, (gparam_p)_url, &value) != 0) {
95
-	LM_ERR("cannot get page value\n");
96
-	return -1;
97
-    }
98
-
99
-    curl = curl_easy_init();
100
-    if (curl == NULL) {
101
-	LM_ERR("failed to initialize curl\n");
102
-	return -1;
103
-    }
104
-
105
-    url = pkg_malloc(value.len + 1);
106
-    if (url == NULL) {
107
-	curl_easy_cleanup(curl);
108
-	LM_ERR("cannot allocate pkg memory for url\n");
109
-	return -1;
110
-    }
111
-    memcpy(url, value.s, value.len);
112
-    *(url + value.len) = (char)0;
113
-    curl_easy_setopt(curl, CURLOPT_URL, url);
114
-
115
-    if (_post) {
116
-        /* Now specify we want to POST data */ 
117
-	curl_easy_setopt(curl, CURLOPT_POST, 1L);
118
-
119
-    	if (fixup_get_svalue(_m, (gparam_p)_post, &post_value) != 0) {
120
-		LM_ERR("cannot get post value\n");
121
-		curl_easy_cleanup(curl);
122
-		pkg_free(url);
82
+	CURL *curl;
83
+	CURLcode res;  
84
+	str value, post_value;
85
+	char *url, *at, *post;
86
+	http_res_stream_t stream;
87
+	long stat;
88
+	pv_spec_t *dst;
89
+	pv_value_t val;
90
+	double download_size;
91
+
92
+	memset(&stream, 0, sizeof(http_res_stream_t));
93
+
94
+	if (fixup_get_svalue(_m, (gparam_p)_url, &value) != 0) {
95
+		LM_ERR("cannot get page value\n");
123 96
 		return -1;
124
-    	}
125
-        post = pkg_malloc(post_value.len + 1);
126
-        if (post == NULL) {
97
+	}
98
+
99
+	curl = curl_easy_init();
100
+	if (curl == NULL) {
101
+		LM_ERR("failed to initialize curl\n");
102
+		return -1;
103
+	}
104
+
105
+	url = pkg_malloc(value.len + 1);
106
+	if (url == NULL) {
127 107
 		curl_easy_cleanup(curl);
128
-		pkg_free(url);
129
-        	LM_ERR("cannot allocate pkg memory for post\n");
130
-        	return -1;
108
+		LM_ERR("cannot allocate pkg memory for url\n");
109
+		return -1;
110
+	}
111
+	memcpy(url, value.s, value.len);
112
+	*(url + value.len) = (char)0;
113
+	curl_easy_setopt(curl, CURLOPT_URL, url);
114
+
115
+	if (_post) {
116
+		/* Now specify we want to POST data */ 
117
+		curl_easy_setopt(curl, CURLOPT_POST, 1L);
118
+
119
+		if (fixup_get_svalue(_m, (gparam_p)_post, &post_value) != 0) {
120
+			LM_ERR("cannot get post value\n");
121
+			curl_easy_cleanup(curl);
122
+			pkg_free(url);
123
+			return -1;
124
+		}
125
+		post = pkg_malloc(post_value.len + 1);
126
+		if (post == NULL) {
127
+			curl_easy_cleanup(curl);
128
+			pkg_free(url);
129
+			LM_ERR("cannot allocate pkg memory for post\n");
130
+			return -1;
131
+		}
132
+		memcpy(post, post_value.s, post_value.len);
133
+		*(post + post_value.len) = (char)0;
134
+		curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post);
131 135
 	}
132
-	memcpy(post, post_value.s, post_value.len);
133
-	*(post + post_value.len) = (char)0;
134
- 	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post);
135
-    }
136
-       
137 136
 
138
-    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
139
-    curl_easy_setopt(curl, CURLOPT_TIMEOUT, (long)http_query_timeout);
140 137
 
141
-    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
142
-    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
138
+	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
139
+	curl_easy_setopt(curl, CURLOPT_TIMEOUT, (long)http_query_timeout);
140
+
141
+	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
142
+	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
143 143
 
144
-    res = curl_easy_perform(curl);  
145
-    pkg_free(url);
146
-    if (_post) {
147
-	pkg_free(post);
148
-    }
144
+	res = curl_easy_perform(curl);  
145
+	pkg_free(url);
146
+	if (_post) {
147
+		pkg_free(post);
148
+	}
149 149
 
150 150
 	if (res != CURLE_OK) {
151 151
 		/* http://curl.haxx.se/libcurl/c/libcurl-errors.html */
... ...
@@ -156,33 +156,33 @@ int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post)
156 156
 		} else {
157 157
 			LM_ERR("failed to perform curl (%d)\n", res);
158 158
 		}
159
-	
159
+
160 160
 		curl_easy_cleanup(curl);
161 161
 		if(stream.buf)
162 162
 			pkg_free(stream.buf);
163 163
 		return -1;
164
-    }
165
-
166
-    curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &stat);
167
-    if ((stat >= 200) && (stat < 500)) {
168
-	curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &download_size);
169
-	LM_DBG("http_query download size: %u\n", (unsigned int)download_size);
170
-
171
-	/* search for line feed */
172
-	at = memchr(stream.buf, (char)10, download_size);
173
-	if (at == NULL) {
174
-	    /* not found: use whole stream */
175
-	    at = stream.buf + (unsigned int)download_size;
176 164
 	}
177
-	val.rs.s = stream.buf;
178
-	val.rs.len = at - stream.buf;
179
-	LM_DBG("http_query result: %.*s\n", val.rs.len, val.rs.s);
180
-	val.flags = PV_VAL_STR;
181
-	dst = (pv_spec_t *)_dst;
182
-	dst->setf(_m, &dst->pvp, (int)EQ_T, &val);
183
-    }
184
-	
185
-    curl_easy_cleanup(curl);
186
-    pkg_free(stream.buf);
187
-    return stat;
165
+
166
+	curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &stat);
167
+	if ((stat >= 200) && (stat < 500)) {
168
+		curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &download_size);
169
+		LM_DBG("http_query download size: %u\n", (unsigned int)download_size);
170
+
171
+		/* search for line feed */
172
+		at = memchr(stream.buf, (char)10, download_size);
173
+		if (at == NULL) {
174
+			/* not found: use whole stream */
175
+			at = stream.buf + (unsigned int)download_size;
176
+		}
177
+		val.rs.s = stream.buf;
178
+		val.rs.len = at - stream.buf;
179
+		LM_DBG("http_query result: %.*s\n", val.rs.len, val.rs.s);
180
+		val.flags = PV_VAL_STR;
181
+		dst = (pv_spec_t *)_dst;
182
+		dst->setf(_m, &dst->pvp, (int)EQ_T, &val);
183
+	}
184
+
185
+	curl_easy_cleanup(curl);
186
+	pkg_free(stream.buf);
187
+	return stat;
188 188
 }