/* Copyright 1997 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/***************************************************/
/* File   : Cookies.c                              */
/*                                                 */
/* Purpose: Browser-end HTTP Cookie support.       */
/*                                                 */
/* Author : A.D.Hodgkinson                         */
/*                                                 */
/* History: 28-Jul-96: Created.                    */
/***************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "swis.h"

#include "wimp.h"
#include "wimplib.h"
#include "event.h"

#include "svcprint.h"
#include "Global.h"
#include "Utils.h"

#include "MiscDefs.h"

#include "Cookies.h"

/*************************************************/
/* cookies_process_cookie()                      */
/*                                               */
/* If a call to URL_ReadData flags (through bit  */
/* 16 of the returned status word being set)     */
/* that a cookie / some cookies have arrived,    */
/* this function deals with sending that cookie  */
/* on or getting rid of it. This may or may not  */
/* involve user level interaction.               */
/*                                               */
/* Parameters: Pointer to a browser_data struct  */
/*             relevant to the fetch.            */
/*************************************************/

_kernel_oserror * cookies_process_cookie(browser_data * b)
{
  _kernel_oserror * e;
  int               handle = 0;
  int               unread = 1;
  int               flags;
  int               ncookies;
  char            * domain;
  char            * name;
  char            * value;
  char            * path;

  while (unread)
  {
    e = _swix(HTTP_EnumerateCookies,
              _INR(0,1) | _OUTR(0,7),

              0,
              handle,

              &flags,
              &handle,
              &ncookies,
              &unread,
              &domain,
              &name,
              &value,
              &path);

    /* Exit conditions */

    if (e) return e;
    if (!handle) break;
  }

  return NULL;
}