RSA BSAFE Cert-C

Certificate Components for C

Crypto-C 6.2.1 Developer's Guide
Search

urlenc.c

Use and attributes object can be used to construct a name-value pair for a URL

/* $Id: urlenc.c,v 1.3 2004/03/02 05:18:32 gsingh Exp $ */
/* urlenc.c
** Copyright (c) 2001-2002, RSA Security Inc.
**
** This file is used to demonstrate how to interface to an RSA Security
** licensed development product.  You have a royalty-free right to use,
** modify, reproduce and distribute this demonstration file (including
** any modified version), provided that you agree that RSA Security has
** no warranty, implied or otherwise, or liability for this demonstration
** file or any modified version.
**
** A quick test to show how an attributes object can be used to construct
** a name-value pair for a URL.
*/

#include "certc.h"
#include "demoutil.h"
#include "menuutil.h"

int main (int argc, char *argv[])
{
  int status;
  char userInput[RSA_DEMO_MAX_LINE_LEN];
  
  ATTRIBUTES_OBJ attributes = NULL;

  ITEM value = {NULL, 0}, urlString = {NULL, 0};

  status = RSA_SetOptions (NULL, argc, argv);
  if (status != 0)
    goto CLEANUP;

  RSA_PrintMessage ("Attributes Object Quick Test\n");
  RSA_PrintMessage ("============================\n");
  
  status = C_CreateAttributesObject (&attributes);
  if (status != 0)
    goto CLEANUP;

  status = RSA_GetCommand (userInput, sizeof (userInput),
                           "Enter name for name-value pair");
  if (status != 0)
    goto CLEANUP;

  status = RSA_GetFileToAllocBuffer (&value.data, &value.len,
                                     "Enter name of file containing value");
  if (status != 0)
    goto CLEANUP;

  status = C_AddStringAttribute
             (attributes, (POINTER)userInput, T_strlen (userInput),
              VT_T61_STRING, value.data, value.len);
  if (status != 0)
    goto CLEANUP;

  status = C_GetAttributesURLEncoded (attributes, &urlString.data,
                                      &urlString.len);
  if (status != 0)
    goto CLEANUP;

  status = RSA_WriteDataToFile (urlString.data, urlString.len,
                                "Enter name of file to store URL");

CLEANUP:
  if (status != 0)
    RSA_PrintError ("urlenc", status);

  T_free (urlString.data);
  T_free (value.data);
  C_DestroyAttributesObject (&attributes);
  
  return status;
}  /* end main */

Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 067-001001-2720-001-000 - 2.7.2