comparison src/parse.c @ 15:f671821d8222

code beautifying; 0 -> \0 if appropriate
author meillo@marmaro.de
date Thu, 06 Nov 2008 09:18:38 +0100
parents 26e34ae9a3e3
children a80ebfa16cd5
comparison
equal deleted inserted replaced
14:a8f3424347dc 15:f671821d8222
123 *e = p; 123 *e = p;
124 return TRUE; 124 return TRUE;
125 } 125 }
126 126
127 gboolean 127 gboolean
128 parse_address_rfc822(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin, gchar** domain_end, gchar** address_end) 128 parse_address_rfc822(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin,
129 gchar** domain_end, gchar** address_end)
129 { 130 {
130 gint angle_brackets = 0; 131 gint angle_brackets = 0;
131 132
132 gchar *p = string; 133 gchar *p = string;
133 gchar *b, *e; 134 gchar *b, *e;
260 } 261 }
261 return FALSE; 262 return FALSE;
262 } 263 }
263 264
264 gboolean 265 gboolean
265 parse_address_rfc821(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin, gchar** domain_end, gchar** address_end) 266 parse_address_rfc821(gchar* string, gchar** local_begin, gchar** local_end, gchar** domain_begin,
267 gchar** domain_end, gchar** address_end)
266 { 268 {
267 gint angle_brackets = 0; 269 gint angle_brackets = 0;
268 270
269 gchar *p = string; 271 gchar *p = string;
270 gchar *b, *e; 272 gchar *b, *e;
350 after call, end contatins a pointer to the end of the parsed string 352 after call, end contatins a pointer to the end of the parsed string
351 end may be NULL, if we are not interested. 353 end may be NULL, if we are not interested.
352 354
353 parses both rfc 821 and rfc 822 addresses, depending on flag is_rfc821 355 parses both rfc 821 and rfc 822 addresses, depending on flag is_rfc821
354 */ 356 */
355
356 address* 357 address*
357 _create_address(gchar * string, gchar ** end, gboolean is_rfc821) 358 _create_address(gchar * string, gchar ** end, gboolean is_rfc821)
358 { 359 {
359 gchar *loc_beg, *loc_end; 360 gchar *loc_beg, *loc_end;
360 gchar *dom_beg, *dom_end; 361 gchar *dom_beg, *dom_end;
362 363
363 if (string && (string[0] == 0)) { 364 if (string && (string[0] == 0)) {
364 address *addr = g_malloc(sizeof(address)); 365 address *addr = g_malloc(sizeof(address));
365 addr->address = g_strdup(""); 366 addr->address = g_strdup("");
366 addr->local_part = g_strdup(""); 367 addr->local_part = g_strdup("");
367 addr->domain = g_strdup(""); /* 'NULL' address (failure notice), "" makes sure it will not be qualified with a hostname */ 368 addr->domain = g_strdup(""); /* 'NULL' address (failure notice),
369 "" makes sure it will not be qualified with a hostname */
368 return addr; 370 return addr;
369 } 371 }
370 372
371 if (is_rfc821 373 if (is_rfc821
372 ? parse_address_rfc821(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end) 374 ? parse_address_rfc821(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)
373 : parse_address_rfc822(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end)) 375 : parse_address_rfc822(string, &loc_beg, &loc_end, &dom_beg, &dom_end, &addr_end))
374 { 376 {
375 address *addr = g_malloc(sizeof(address)); 377 address *addr = g_malloc(sizeof(address));
376 gchar *p = addr_end; 378 gchar *p = addr_end;
377 379
378
379 memset(addr, 0, sizeof(address)); 380 memset(addr, 0, sizeof(address));
380 381
381 if (loc_beg[0] == '|') { 382 if (loc_beg[0] == '|') {
382 parse_error = g_strdup("no pipe allowed for RFC 822/821 address"); 383 parse_error = g_strdup("no pipe allowed for RFC 822/821 address");
383 return NULL; 384 return NULL;
395 396
396 if (dom_beg != NULL) { 397 if (dom_beg != NULL) {
397 addr->domain = g_strndup(dom_beg, dom_end - dom_beg); 398 addr->domain = g_strndup(dom_beg, dom_end - dom_beg);
398 } else { 399 } else {
399 if (addr->local_part[0] == 0) 400 if (addr->local_part[0] == 0)
400 addr->domain = g_strdup(""); /* 'NULL' address (failure notice), "" makes sure it will not be qualified with a hostname */ 401 addr->domain = g_strdup(""); /* 'NULL' address (failure notice),
402 "" makes sure it will not be qualified with a hostname */
401 else 403 else
402 addr->domain = NULL; 404 addr->domain = NULL;
403 } 405 }
404 406
405 if (end != NULL) 407 if (end != NULL)