int main (int argc, char **argv) { FILE *wwwauthenticates_file; osip_www_authenticate_t *wwwauthenticate; char *a_wwwauthenticate; char *dest; char *res; wwwauthenticates_file = fopen (argv[1], "r"); if (wwwauthenticates_file == NULL) { fprintf (stdout, "Failed to open %s file.\nUsage: twwwauthenticate wwwauthenticates.txt\n", argv[1]); exit (0); } a_wwwauthenticate = (char *) osip_malloc (200); res = fgets (a_wwwauthenticate, 200, wwwauthenticates_file); /* lines are under 200 */ while (res != NULL) { int errcode; /* remove the last '\n' before parsing */ strncpy (a_wwwauthenticate + strlen (a_wwwauthenticate) - 1, "\0", 1); if (0 != strncmp (a_wwwauthenticate, "#", 1)) { /* allocate & init wwwauthenticate */ osip_www_authenticate_init (&wwwauthenticate); printf ("=================================================\n"); printf ("WWWAUTHENTICATE TO PARSE: |%s|\n", a_wwwauthenticate); errcode = osip_www_authenticate_parse (wwwauthenticate, a_wwwauthenticate); if (errcode != -1) { if (osip_www_authenticate_to_str (wwwauthenticate, &dest) != -1) { printf ("result: |%s|\n", dest); osip_free (dest); } } else printf ("Bad wwwauthenticate format: %s\n", a_wwwauthenticate); osip_www_authenticate_free (wwwauthenticate); printf ("=================================================\n"); } res = fgets (a_wwwauthenticate, 200, wwwauthenticates_file); /* lines are under 200 */ } osip_free (a_wwwauthenticate); return 0; }
/* returns -1 on error. */ int osip_message_set_www_authenticate (osip_message_t * sip, const char *hvalue) { osip_www_authenticate_t *www_authenticate; int i; if (hvalue == NULL || hvalue[0] == '\0') return OSIP_SUCCESS; if (sip == NULL) return OSIP_BADPARAMETER; i = osip_www_authenticate_init (&www_authenticate); if (i != 0) return i; i = osip_www_authenticate_parse (www_authenticate, hvalue); if (i != 0) { osip_www_authenticate_free (www_authenticate); return i; } sip->message_property = 2; osip_list_add (&sip->www_authenticates, www_authenticate, -1); return OSIP_SUCCESS; }