/*_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
* *
* html.c..... *
* *
* Function:..WorldWideWeb-X.500-Gateway - HTML-Procedures *
* Based on web500gw.c 1.3 written by Frank Richter, TU Chemmniz *
* which is based on go500gw by Tim Howes, University of *
* Michigan - All rights reserved *
* *
* Authors:...Dr. Kurt Spanier & Bernhard Winkler, *
* Zentrum fuer Datenverarbeitung, Bereich Entwicklung *
* neuer Dienste, Universitaet Tuebingen, GERMANY *
* *
* ZZZZZ DDD V V *
* Creation date: Z D D V V *
* August 16 1995 Z D D V V *
* Last modification: Z D D V V *
* May 28 1999 ZZZZ DDD V *
* *
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_*/
/*
* $Id: html.c,v 1.6 1999/09/10 15:01:17 zrnsk01 Exp $
*
*/
#include "tgeneral.h"
#include "tglobal.h"
#include "html.h"
#include "init_exp.h"
#include "support_exp.h"
#ifdef TUETEL
#include "tueTel_exp.h"
#endif
PUBLIC void print_attr(ld, fp, dn, label, tattr, e, flag, doNotShow, glob)
LDAP *ld;
FILE *fp;
char *dn;
char *label;
char *tattr;
LDAPMessage *e;
int flag;
char *doNotShow;
GLOB_STRUCT *glob;
{
char **val;
int i, gotone = 0, firstline = TRUE, valid_label = FALSE;
static char *nlabel;
char imageChar = 'J';
char strbuf[BUFSIZ];
int first_of_same = TRUE;
nlabel = ldap_friendly_name(glob->friendlyfile, label, &fm);
if ( (val = ldap_get_values( ld, e, tattr )) == NULL )
return;
/* check if only 1 value and this one is in "doNotShow"
if((doNotShow) && (val[1] == NULL) && (strcmp(val[0],doNotShow) == 0))
return;
*/
for ( i = 0; val[i]; i++ ) {
sprintf(strbuf, "(%s)", glob->la[0]);
if(!strncasecmp(val[i], strbuf, 4)) {
strcpy(val[i], val[i]+4);
}
else if(val[i][0] == '(' && val[i][3] == ')' ) {
val[i][0] = '\0';
continue;
}
if (!doNotShow || strncasecmp (val[i], doNotShow, strlen (val[i])))
valid_label = TRUE;
else
val[i][0] = '\0';
}
if(!valid_label) {
ldap_value_free (val);
return;
}
fprintf( fp, "\n
%s ", nlabel );
/* handle photo-requests */
if((flag == BMP) || (flag == JPEG2GIF) || (flag == JPEG)) {
photof(fp, flag, imageChar, dn, tattr);
return;
}
for ( i = 0; val[i] != NULL; i++ ) {
char *vali;
if(!*label ) first_of_same = FALSE;
if(!*val[i]) continue;
vali = char2html(val[i]);
if (flag == URL) {
urlf(fp, vali);
#ifdef TUE_TEL
} else if (flag == TFUNCPERS) {
tfuncpersf(fp, vali, ld, glob);
#endif
} else if (flag == DYNAMICDN) {
dynamicdnf(fp, vali, glob);
} else if (flag == INDEXURL) {
indexurlf(fp, vali, dn, glob);
} else if (flag == URI) {
urif(fp, vali, glob);
} else if (flag == PGPKEY) {
pgpkeyf(fp, vali, &firstline);
} else if ( ( flag == MULTILINE ) || (strchr(vali, '$') &&
strncmp(vali, "{T.61}", 6) != 0 )) {
multilinef(fp, vali, &first_of_same, &firstline, &gotone, nlabel);
} else if (flag == BOOLEAN) {
booleanf(fp, val[i], glob);
} else if (flag == DATE) {
datef(fp, val[i]);
} else if (flag == MAILTO) {
mailtof(fp, val[i], vali);
} else if (flag == HREF) {
hreff(fp, val[i], vali, glob);
} else if (flag == MOVETO) {
movetof(fp, val[i], vali, glob);
} else if (flag == PRE) {
pref(fp, vali, glob);
} else if (flag == HEADER) {
headerf(fp, vali, glob);
} else if (flag == REFERRAL) {
referralf(fp, vali, glob);
#ifdef TUE_TEL
} else if(flag == FAXTABLE) {
faxtablef(fp, val, &firstline);
#endif
} else
defaultf(fp, vali, &firstline);
}
ldap_value_free( val );
}
/* end of function: print_attr */
PUBLIC void form_attr(ld, fp, label, tattr, e, multiline, add_empty, glob)
LDAP *ld;
FILE *fp;
char *label;
char *tattr;
LDAPMessage *e;
int multiline;
int add_empty;
GLOB_STRUCT *glob;
{
char **val, *s;
char buffer[1024];
int i, gotone = 0, line = 0;
static char *nlabel;
nlabel = ldap_friendly_name(glob->friendlyfile, label, &fm);
if ( (val = ldap_get_values( ld, e, tattr )) == NULL ) {
if (add_empty > 0)
if(multiline)
fprintf( fp, " %s \n",
nlabel, tattr);
else
fprintf( fp, "%s \n",
nlabel, tattr);
return;
}
fprintf( fp, "\n%s ", nlabel );
buffer[0] ='\0';
for ( i = 0; val[i] != NULL; i++ ) {
if ( multiline ) {
char *s, *p;
buffer[0] ='\0';
if ( gotone )
fprintf( fp, " %s ", nlabel);
p = s = val[i];
while ( ( s = strchr( s, '$' )) ) {
*s++ = '\0';
while ( isspace( *s ) )
s++;
if ( line == 0 ) {
sprintf(buffer, "%s", p);
line++;
} else {
sprintf(buffer, "%s\n%s", buffer, p);
line++;
}
p = s;
}
if (line++ == 0) {
sprintf(buffer, "%s", p);
} else {
sprintf(buffer, "%s\n%s", buffer, p);
}
s = form_encode(buffer);
fprintf( fp,
" \n",
tattr, s, line + 1, s);
/* fprintf( fp, " \n", tattr, s, line + 1, s); */
gotone = 1;
line = 0;
} else {
s = form_encode(val[i]);
fprintf( fp, " \n", tattr, s,
strlen(val[i]) > 30 ? strlen(val[i]) + 3 : 30, s);
}
}
if (add_empty > i)
fprintf( fp, " \n", tattr);
ldap_value_free( val );
}
/* end of function: form_attr */
PUBLIC void do_pict(ld, fp, dn, type, glob)
LDAP *ld;
FILE *fp;
char *dn;
int type;
GLOB_STRUCT *glob;
{
int rc, i;
struct berval **val;
char cmd[128], buffer[1024];
char *s;
FILE *op, *tp;
LDAPMessage *res, *e;
struct stat st;
char *cPtr, *ptype;
char *tattr;
if ( (rc = ldap_search_s( ld, dn, LDAP_SCOPE_BASE, NULL,
NULL, 0, &res )) != LDAP_SUCCESS ) {
do_error(fp, rc, NOT_FOUND, glob);
return;
}
if ( (e = ldap_first_entry( ld, res )) == NULL ) {
do_error(fp, -2, SERVER_ERROR, glob);
return;
}
/*
* old behaviour: use "photo" or "jpegPhoto" attribute
* as indicated by type-argument.
*/
tattr = (type == 0 ? "photo" : "jpegPhoto");
/* NEW: if attr is added to URL via "+" use that attribute */
if( ( cPtr = strQuoteChr(dn,'+')) )
tattr = ++cPtr;
if ( (val = ldap_get_values_len( ld, e, tattr)) == NULL )
return;
s = tmpnam( NULL );
tp = fopen( s, "w+");
if (type == 0) { /* g3fax photo -> xbm */
sprintf(cmd, "%s > %s", G3TOXBM, s);
if (debug) fprintf(stderr, "%ld bytes FAX!! %s\n",
val[0]->bv_len, cmd);
ptype = "x-xbitmap";
} else if (type == 1) { /* jpeg -> gif */
sprintf(cmd, "%s > %s", JPEGTOGIF, s);
if (debug) fprintf(stderr, "%ld bytes JPEG!! %s\n",
val[0]->bv_len, cmd);
ptype = "gif";
} else { /* jpeg direct */
sprintf(cmd, "cat > %s", s);
if (debug) fprintf(stderr, "%ld bytes JPEG!! %s\n",
val[0]->bv_len, cmd);
ptype = "jpeg";
}
if (http == 1) {
fprintf(fp, "HTTP/1.0 %d OK MIME-Version: 1.0 ",
DOCUMENT_FOLLOWS );
fprintf(fp, "Content-type: image/%s ", ptype );
}
if (request == HEAD) {
fflush(fp);
exit_tweb (1);
}
if ((op = popen(cmd, "w")) == NULL )
return;
fwrite(val[0]->bv_val, val[0]->bv_len, 1, op);
pclose(op);
if (stat(s, &st) == 0 && http == 1) {
fprintf(fp, "Content-length: %lu ", st.st_size);
if (debug) fprintf(stderr, "Image size: %lu\n", st.st_size);
}
fprintf(fp, " \n\n");
while (( i = fread(buffer, 1, 1024, tp))) fwrite(buffer, 1, i, fp);
fclose(tp);
if (unlink(s) == -1) {
if (debug) perror("Couldn't unlink temp image file");
}
fflush(fp);
}
/* end of function: do_pict */
PUBLIC void do_audio(ld, fp, dn, type, glob)
LDAP *ld;
FILE *fp;
char *dn;
int type;
GLOB_STRUCT *glob;
{
int rc;
struct berval **val;
LDAPMessage *res, *e;
struct timeval timeout;
timeout.tv_sec = glob->timeout;
timeout.tv_usec = 0;
if ( (rc = ldap_search_st( ld, dn, LDAP_SCOPE_BASE, NULL,
NULL, 0, &timeout, &res )) != LDAP_SUCCESS ) {
do_error(fp, rc, NOT_FOUND, glob);
return;
}
if ( (e = ldap_first_entry( ld, res )) == NULL ) {
do_error(fp, -2, SERVER_ERROR, glob);
return;
}
if ( (val = ldap_get_values_len( ld, e, "audio" )) == NULL )
return;
if (http == 1) {
fprintf(fp, "HTTP/1.0 %d OK\nMIME-Version: 1.0\nServer: %s\n",
DOCUMENT_FOLLOWS, version);
fprintf(fp, "Content-type: audio/basicContent-length: %ld\n\n",
val[0]->bv_len);
}
if (request == HEAD) {
fflush(fp);
exit_tweb (1);
}
fwrite(val[0]->bv_val, val[0]->bv_len, 1, fp);
fflush(fp);
}
/* end of function: do_audio */
PUBLIC void do_sizelimit(fp, type, glob)
FILE *fp;
int type;
GLOB_STRUCT *glob;
{
fprintf(fp, type ? glob->la[21] : glob->la[20]);
}
/* end of function: do_sizelimit */
PUBLIC void do_error(fp, code, status, glob)
FILE *fp;
int code;
int status;
GLOB_STRUCT *glob;
{
char *s = "";
if (http == 1) {
switch (status) {
case BAD_REQUEST: s = "Bad request"; break;
case AUTH_REQUIRED: s = "Authorization required"; break;
case FORBIDDEN: s = "Forbidden"; break;
case NOT_FOUND: s = "Not found"; break;
case SERVER_ERROR: s = "Server error"; break;
case NOT_IMPLEMENTED: s = "Not implemented"; break;
default: s = "Unknown error";
}
fprintf(fp, "HTTP/1.0 %03d %s\nMIME-Version: 1.0\nContent-Type: text/html\n\n", status, s);
}
if (request == HEAD) {
fflush(fp);
exit_tweb (1);
}
fprintf( fp, HTML_HEAD_TITLE, glob->la[22], glob->la[100]);
fprintf( fp, "\n
%s %s \n%s %s %d: %s.
%s