📄 de.c
字号:
/* template.c - your comments here */#ifndef lintstatic char *rcsid = "$Header: /xtel/isode/isode/others/quipu/uips/de/RCS/de.c,v 9.0 1992/06/16 12:45:59 isode Rel $";#endif/* * $Header: /xtel/isode/isode/others/quipu/uips/de/RCS/de.c,v 9.0 1992/06/16 12:45:59 isode Rel $ * * * $Log: de.c,v $ * Revision 9.0 1992/06/16 12:45:59 isode * Release 8.0 * *//* * NOTICE * * Acquisition, use, and distribution of this module and related * materials are subject to the restrictions of a license agreement. * Consult the Preface in the User's Manual for the full terms of * this agreement. * *//***************************************************************************** main.c*****************************************************************************/#include <stdio.h>#include <ctype.h>#include <pwd.h>#include <signal.h>#include <setjmp.h>#include <sys/types.h>#include <sys/time.h>#include <sys/socket.h>#include "quipu/util.h"#include "demanifest.h"#include "bind.h"#include "namelist.h"#include "cnamelist.h"#include "mapatts.h"#include "mapphone.h"#include "tailor.h"#include "query.h"LLog _de_log = { "de.log", NULLCP, NULLCP, LLOG_FATAL | LLOG_EXCEPTIONS | LLOG_NOTICE, LLOG_NONE, -1, LLOGCLS | LLOGCRT | LLOGZER, NOTOK};LLog *de_log = &_de_log;extern char *TidyString();extern char *findHelp();void onint1(), de_exit();void foundFollowing(), matchFollowing();char enterYesNo();struct query qinfo[MAXTYPE + 1];int boundToDSA = FALSE;int limitProblem = FALSE;int browseMess = FALSE;int notAllReached = FALSE;int alarmCount = 0;int abandoned = FALSE;int accessrightproblem = FALSE;int searchfail = FALSE;int byeByeMessage = FALSE;int controlCtoQuit = TRUE;int wanAccess = FALSE;int exactMatch;int highNumber = 0;int maxOrgs = 1;int maxDepts = 1;int maxPersons = 3;int localAlarmTime = 15;int remoteAlarmTime = 30;int bindTimeout = 120;int quitChars = 1;int deLogLevel = 1;int alarmLeft = 0; struct cnamelist * cnamelp = NULLCNLIST;struct mapnamelist * mapnamelp = NULLMNLIST;struct mapphonelist * mapphonelp = NULLPHLIST;struct namelist * orgatts = NULLLIST;struct namelist * ouatts = NULLLIST;struct namelist * prratts = NULLLIST;/* Defaults for unspecified name parts */char origDefaultCo[LINESIZE], origDefaultOrg[LINESIZE], exactString[LINESIZE], welcomeMessage[LINESIZE] = "Welcome to the Directory Service", matched[LINESIZE], callingDteNumber[LINESIZE]; char * username, * backup_dsa_address;jmp_buf sjbuf;SFD cleanupok();int main(argc, argv) int argc; char *argv[];{int res;/* pdu_dump_init("/tmp"); */ if (initialisations(argc, argv) != OK) de_exit(-1); (void) tailorHelp(); if (de_bind(FALSE) != OK) de_exit(-1); ll_hdinit(de_log, "de"); (void)strcpy(origDefaultCo, qinfo[COUNTRY].defvalue); (void)strcpy(origDefaultOrg, qinfo[ORG].defvalue); qinfo[COUNTRY].lp = NULLLIST; qinfo[LOCALITY].lp = NULLLIST; qinfo[ORG].lp = NULLLIST; qinfo[ORGUNIT].lp = NULLLIST; qinfo[PERSON].lp = NULLLIST; welcome(); /* exit from this loop (and thus from the program) is handled by the enterString routine */ for (;;) { (void) setjmp(sjbuf); highNumber = 0; abandoned = FALSE; accessrightproblem = FALSE; if (controlCtoQuit == TRUE) (void) signal(SIGINT, cleanupok); else (void) signal(SIGINT, onint1); (void) enterString(PERSON); (void) signal(SIGINT, onint1); if (boundToDSA == FALSE) if (de_bind(FALSE) == NOTOK) /* don`t block */ de_exit(-1); highNumber = 0; (void) enterString(ORGUNIT); if (boundToDSA == FALSE) if (de_bind(FALSE) == NOTOK) /* don`t block */ de_exit(-1);enterorg: (void) enterString(ORG); highNumber = 0; if ((exactMatch != ORG) || ((strcmp(qinfo[ORG].entered, qinfo[ORG].defvalue) != 0) && (exactMatch != ORG)) || (searchfail == TRUE)) {entercountry: (void) enterString(COUNTRY); } /* look at the input strings and decide what sort of search or list to do */ /* must have entered a country */ if (strlen(qinfo[COUNTRY].entered) == 0) { if (strlen(qinfo[ORG].entered) == 0) { (void) printf("Must enter an organisation and country\n\n"); goto enterorg; } else { (void) printf("Must enter a country\n\n"); goto entercountry; } } if (boundToDSA == FALSE) { if (de_bind(TRUE) == NOTOK) /* block until bound */ de_exit(-1);#ifdef SPEC_MALL start_malloc_trace(0);#endif } if (deLogLevel) (void) ll_log (de_log, LLOG_NOTICE, NULLCP, "Search: co=%s, org=%s, ou=%s, cn=%s", qinfo[COUNTRY].entered, qinfo[ORG].entered, qinfo[ORGUNIT].entered, qinfo[PERSON].entered); searchfail = FALSE; pagerOn(NUMBER_ALLOWED); res = doCountry(); switch (res) { case QUERY_ERROR: goto set_up_defaults; case NAME_PRINTED: case LIST_PRINTED: if (((int)strlen(qinfo[ORG].entered) == 0) && (strlen(qinfo[ORGUNIT].entered) == 0) && (strlen(qinfo[PERSON].entered) == 0)) { goto set_up_defaults; } else break; } res = doOrganisation(matched); switch (res) { case QUERY_ERROR: case NO_ORG_ENTERED: goto set_up_defaults; case NAME_PRINTED: case LIST_PRINTED: if (((int)strlen(qinfo[ORGUNIT].entered) == 0) && (strlen(qinfo[PERSON].entered) == 0)) { goto set_up_defaults; } else break; } if (strlen(qinfo[ORGUNIT].entered) != 0) { res = doOU(matched); switch (res) { case NAME_PRINTED: case NO_DEPT_FOUND: if (strlen(qinfo[PERSON].entered) == 0) goto set_up_defaults; else { if (res == NO_DEPT_FOUND) { (void) doPRR(matched, ORG); goto set_up_defaults; } else break; } case PARENT_PRINTED: goto set_up_defaults; } (void) doPRR(matched, ORGUNIT); } else /* ou is null */ { freeOUs(&qinfo[ORGUNIT].lp); /* if prev ou value was non-null, force search for people */ if (strlen(qinfo[ORGUNIT].defvalue) != 0) freePRRs(&qinfo[PERSON].lp); (void) doPRR(matched, ORG); }set_up_defaults: /* set up defaults for next time round */ /* note that the list default is converted to null */ /* except for country */ (void) strcpy(qinfo[COUNTRY].defvalue, qinfo[COUNTRY].entered); if (strcmp(qinfo[ORG].entered, "*") == 0) (void) strcpy(qinfo[ORG].defvalue, ""); else (void) strcpy(qinfo[ORG].defvalue, qinfo[ORG].entered); if (strcmp(qinfo[ORGUNIT].entered, "*") == 0) (void) strcpy(qinfo[ORGUNIT].defvalue, ""); else (void) strcpy(qinfo[ORGUNIT].defvalue, qinfo[ORGUNIT].entered); if (strcmp(qinfo[PERSON].entered, "*") == 0) (void) strcpy(qinfo[PERSON].defvalue, ""); else (void) strcpy(qinfo[PERSON].defvalue, qinfo[PERSON].entered); } /* and that's all for now */}intdoCountry(){ if ((strcmp(qinfo[COUNTRY].entered, qinfo[COUNTRY].defvalue) == 0) && (qinfo[COUNTRY].lp != NULLLIST) && (qinfo[COUNTRY].listlen == 1)) { printLastComponent(INDENTON, qinfo[COUNTRY].lp->name, COUNTRY, 0); (void)strcpy(matched, qinfo[COUNTRY].lp->name); return NAME_PRINTED; } else { freeOrgs(&qinfo[ORG].lp); freeOUs(&qinfo[ORGUNIT].lp); freePRRs(&qinfo[PERSON].lp); } for (;;) { /* inits */ freeCos(&qinfo[COUNTRY].lp); pagerOn(NUMBER_ALLOWED);/* if (strcmp(qinfo[COUNTRY].entered, "*") == 0) (void) strcpy(qinfo[COUNTRY].defvalue, "*"); else (void) strcpy(qinfo[COUNTRY].defvalue, qinfo[COUNTRY].entered);*/ if (listCos(qinfo[COUNTRY].entered, &qinfo[COUNTRY].lp) != OK) { (void) searchFail(COUNTRY); return QUERY_ERROR; } qinfo[COUNTRY].listlen = listlen(qinfo[COUNTRY].lp); if (qinfo[COUNTRY].listlen == 0) { if (strcmp(qinfo[COUNTRY].entered, "*") == 0) { resetprint("\n Probably something wrong\n\n"); return QUERY_ERROR; } else { resetprint("No countries match `%s'\n\n", qinfo[COUNTRY].entered); (void) strcpy(qinfo[COUNTRY].defvalue, ""); (void) enterString(COUNTRY); continue; } } else if (qinfo[COUNTRY].listlen == 1) { (void) strcpy(qinfo[COUNTRY].displayed, qinfo[COUNTRY].lp->name); printLastComponent(INDENTON, qinfo[COUNTRY].lp->name, COUNTRY, 0); (void)strcpy(matched, qinfo[COUNTRY].lp->name); return NAME_PRINTED; } else /* qinfo[COUNTRY].listlen > 1 */ { if (strcmp(qinfo[COUNTRY].entered, "*") == 0) if (((int)strlen(qinfo[ORG].entered) != 0) || ((strlen(qinfo[ORGUNIT].entered) != 0)) || (strlen(qinfo[PERSON].entered) != 0)) { foundFollowing(); printListCos(qinfo[COUNTRY].entered, qinfo[COUNTRY].lp); (void) enterString(COUNTRY); continue; } else { printListCos(qinfo[COUNTRY].entered, qinfo[COUNTRY].lp); return LIST_PRINTED; } else { matchFollowing(); printListCos(qinfo[COUNTRY].entered, qinfo[COUNTRY].lp); (void) enterString(COUNTRY); continue; } } }}intdoOrganisation(matchstring)char matchstring [];{ if ((strcmp(qinfo[ORG].entered, qinfo[ORG].defvalue) == 0) && (qinfo[ORG].lp != NULLLIST) && (qinfo[ORG].listlen == 1)) { printLastComponent(INDENTON, qinfo[ORG].lp->name, ORG, 0); (void)strcpy(matched, qinfo[ORG].lp->name); if (((int)strlen(qinfo[ORGUNIT].entered) == 0) && (strlen(qinfo[PERSON].entered) == 0)) printDetails(ORG, qinfo[ORG].lp); return NAME_PRINTED; } else { freeOUs(&qinfo[ORGUNIT].lp); freePRRs(&qinfo[PERSON].lp); } for (;;) { /* inits */ freeOrgs(&qinfo[ORG].lp); if (strlen(qinfo[ORG].entered) == 0) { resetprint("\nNothing to search for as no organisation name entered. Either enter\n"); resetprint("an organisation name at the prompt, or press <CR> to start the\n"); resetprint("query again\n\n"); (void) enterString(ORG); if (strlen(qinfo[ORG].entered) == 0) return NO_ORG_ENTERED; } pagerOn(NUMBER_ALLOWED);/* if (strcmp(qinfo[ORG].entered, "*") == 0) (void) strcpy(qinfo[ORG].defvalue, ""); else (void) strcpy(qinfo[ORG].defvalue, qinfo[ORG].entered);*/ if (listOrgs(matchstring, qinfo[ORG].entered, &qinfo[ORG].lp) != OK) { (void) searchFail(ORG); return QUERY_ERROR; } qinfo[ORG].listlen = listlen(qinfo[ORG].lp); if (qinfo[ORG].listlen == 0) { if (strcmp(qinfo[ORG].entered, "*") == 0) { resetprint("No organisations found. Probably something wrong\n\n"); return QUERY_ERROR; } else { resetprint("No organisations match `%s'\n\n", qinfo[ORG].entered); (void) strcpy(qinfo[ORG].defvalue, ""); (void) enterString(ORG); continue; } } else if (qinfo[ORG].listlen == 1) { if (testRedisplay()) printNames(COUNTRY); printLastComponent(INDENTON, qinfo[ORG].lp->name, ORG, 0); if (((int)strlen(qinfo[ORGUNIT].entered) == 0) && (strlen(qinfo[PERSON].entered) == 0)) printDetails(ORG, qinfo[ORG].lp); (void)strcpy(matched, qinfo[ORG].lp->name); return NAME_PRINTED; } else /* qinfo[ORG].listlen > 1 */ { if (strcmp(qinfo[ORG].entered, "*") == 0) foundFollowing(); else matchFollowing(); printNames(COUNTRY); printListOrgs(qinfo[ORG].entered, qinfo[ORG].lp); (void) enterString(ORG); continue; } }}intdoOU(matchstring)char matchstring [];{ if ((strcmp(qinfo[ORGUNIT].entered, qinfo[ORGUNIT].defvalue) == 0) && (qinfo[ORGUNIT].lp != NULLLIST) && (qinfo[ORGUNIT].listlen == 1)) { printLastComponent(INDENTON, qinfo[ORGUNIT].lp->name, ORGUNIT, 0); if (strlen(qinfo[PERSON].entered) == 0) printDetails(ORGUNIT, qinfo[ORGUNIT].lp); (void)strcpy(matched, qinfo[ORGUNIT].lp->name); return NAME_PRINTED; } else freePRRs(&qinfo[PERSON].lp); for (;;) { /* inits */ freeOUs(&qinfo[ORGUNIT].lp); pagerOn(NUMBER_ALLOWED);/* if (strcmp(qinfo[ORGUNIT].entered, "*") == 0) (void) strcpy(qinfo[ORGUNIT].defvalue, ""); else (void) strcpy(qinfo[ORGUNIT].defvalue, qinfo[ORGUNIT].entered);*/ if (listOUs(matchstring, qinfo[ORGUNIT].entered, &qinfo[ORGUNIT].lp) != OK) { if (searchFail(ORGUNIT) != SF_ABANDONED) { /* initialise value to discard default which failed */ (void) strcpy(qinfo[ORGUNIT].entered, ""); } return PARENT_PRINTED; } qinfo[ORGUNIT].listlen = listlen(qinfo[ORGUNIT].lp); if (qinfo[ORGUNIT].listlen == 0) { if (strcmp(qinfo[ORGUNIT].entered, "*") == 0) if (strlen(qinfo[PERSON].entered) != 0) return NO_DEPT_FOUND; else resetprint("\n Can't find any departments."); else {/* (void) strcpy(qinfo[ORGUNIT].defvalue, ""); */ resetprint("\n No departments match `%s'.\n", qinfo[ORGUNIT].entered); (void) strcpy(qinfo[ORGUNIT].entered, ""); } if (strlen(qinfo[PERSON].entered) == 0) { resetprint(" Displaying organisation details.\n\n"); printNames(ORG); printDetails(ORG, qinfo[ORG].lp); return PARENT_PRINTED; } else { resetprint (" Continuing to search for person called `%s'\n", qinfo[PERSON].entered); resetprint (" within the whole organisation.\n\n"); return NO_DEPT_FOUND; } } else if (qinfo[ORGUNIT].listlen == 1) { if (testRedisplay()) printNames(ORG); printLastComponent(INDENTON, qinfo[ORGUNIT].lp->name, ORGUNIT, 0); if (strlen(qinfo[PERSON].entered) == 0) printDetails(ORGUNIT, qinfo[ORGUNIT].lp); (void)strcpy(matched, qinfo[ORGUNIT].lp->name); return NAME_PRINTED; } else /* qinfo[ORGUNIT].listlen > 1 */ { if (strcmp(qinfo[ORGUNIT].entered, "*") == 0) { foundFollowing(); printNames(ORG); printListOUs(qinfo[ORGUNIT].entered, qinfo[ORGUNIT].lp); (void) enterString(ORGUNIT); continue; } else { matchFollowing(); printNames(ORG); printListOUs(qinfo[ORGUNIT].entered, qinfo[ORGUNIT].lp); (void) enterString(ORGUNIT); continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -