![]() |
rtfm / SQL / Oracle Timestamps / src/ora_url.c
|
![]() |
#include <string.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> /* * URL style '%' encoding for PL/SQL * Copyright (C) 2001 Vivek Dasmohapatra <vivek@etla.org> * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* oracle include */ #include <oci.h> char * url_encode (OCIExtProcContext *ORA_CONTEXT, char *unenc_url) { FILE *debug; size_t maxlen; char *upos; char *epos; char *enc_url; debug = fopen("/tmp/ora_extproc.log", "wa+"); maxlen = (strlen(unenc_url) * 3) + 2; /* * This Oracle library function call is documented as the one * to use to allocate memory for return parameters: Oracle * should clean up this memory after copying out any data you * put in it: */ enc_url = OCIExtProcAllocCallMemory(ORA_CONTEXT, maxlen); epos = enc_url; *epos = '\0'; for (upos = unenc_url; (*upos && ((epos - enc_url) < maxlen)); upos++) { if(isalnum((int)*upos)) { *(epos++) = *upos; } else { epos += sprintf(epos, "%%%02x", *upos); } } *epos = (char)0; /* terminate the string (just in case ) */ close(debug); return enc_url; } |
![]() ![]() ![]() ![]() ![]() |