?? dyncntnt.c
字號:
/* * Embedded HTTP Server Dynamic Content Utilities * * ./software/ch7/emhttps/dyncntnt.c * * mtj@cogitollc.com * */#include <stdio.h>#include <string.h>#include <sys/socket.h>#include "filehdlr.h"static int init = 0;#define MAX_DYNAMIC_CONTENT 20struct dynamicContentStructure { char variableName[80]; char *(*pfunc)();} dynamicContent[MAX_DYNAMIC_CONTENT];/*---------------------------------------------------------------------------- * defaultFunction() - Default to fill unused dynamic content rows *--------------------------------------------------------------------------*/static char *defaultFunction(){ return("???noinit");}/*---------------------------------------------------------------------------- * initContent() - Initialize the dynamic content array *--------------------------------------------------------------------------*/void initContent(){ int i; for (i = 0 ; i < MAX_DYNAMIC_CONTENT ; i++) { dynamicContent[i].variableName[0] = 0; dynamicContent[i].pfunc = &defaultFunction; }}/*---------------------------------------------------------------------------- * addDynamicContent() - Add a new element to the dynamic content array *--------------------------------------------------------------------------*/int addDynamicContent(char *name, char *(*function)()) { int i; if (!init) { initContent(); init=1; } /* First, ensure that the 'name' does not exist in the current list */ for (i = 0 ; i < MAX_DYNAMIC_CONTENT ; i++) { if (dynamicContent[i].variableName[0] != 0) { if (!strcmp(name, dynamicContent[i].variableName)) { return(-1); } } } /* Next, look for an empty slot */ for (i = 0 ; i < MAX_DYNAMIC_CONTENT ; i++) { if (dynamicContent[i].variableName[0] == 0) { strncpy(dynamicContent[i].variableName, name, 80); dynamicContent[i].pfunc = function; break; } } return(0); }/*---------------------------------------------------------------------------- * getDynamicContent() - Get the dynamic content for a particular entry *--------------------------------------------------------------------------*/void getDynamicContent(char *name, char *content){ int j, i; if (!init) { initContent(); init=1; } for (j = 0 ; j < MAX_DYNAMIC_CONTENT ; j++) { /* Search for the name in the list, avoid '>' trailing name... */ for (i = 0 ; name[i] != '>' ; i++) { if (dynamicContent[j].variableName[i] != name[i]) break; } if (name[i] == '>') { /* We've reached the end, so it was a good match */ strcpy(content, dynamicContent[j].pfunc()); return; } } strcpy(content, defaultFunction()); return;}/* * Copyright (c) 2002 Charles River Media. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, is hereby granted without fee provided * that the following conditions are met: * * 1. Redistributions of source code must retain the above * copyright notice, this list of conditions and the * following disclaimer. * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the * following disclaimer in the documentation and/or other * materials provided with the distribution. * 3. Neither the name of Charles River Media nor the names of * its contributors may be used to endorse or promote products * derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY CHARLES RIVER MEDIA AND CONTRIBUTERS * 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CHARLES * RIVER MEDIA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARAY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -