Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

internal.cc File Reference

#include "ldapconf_defs.h"
#include "popen.h"
#include "daemoni.h"
#include <strings.h>

Go to the source code of this file.

Functions

const char* get_keyval (VIEWITEMS &items, const char *key)
const char* get_keyval (VIEWITEMS &items, const char *key, const char *defval)
void set_keyval (VIEWITEMS &items, const char *key, const char *val)
int sys_command_raw ( const char *cmd, const char *args, SSTRINGS &tb)
int sys_command ( const char *cmd, const char *args, SSTRINGS &tb)
int sys_showfile ( const char *file, SSTRINGS &tb)
void sys_command_title ( const char *title, const char *cmd, const char *args)
int dir_getfiltered ( const char *path, SSTRINGS &lst, const char *filter)


Function Documentation

const char * get_keyval ( VIEWITEMS & items,
const char * key )
 

Definition at line 15 of file internal.cc.

00016 {
00017     const char *ret = NULL;
00018     VIEWITEM *it = items.locate (key);
00019     if (it != NULL){
00020         const char *pt = it->line.get();
00021         pt = str_skip(pt);
00022         pt += strlen(key);
00023         pt = str_skip (pt);
00024         ret =pt;        
00025     }
00026     return ret;
00027 }

const char * get_keyval ( VIEWITEMS & items,
const char * key,
const char * defval )
 

Definition at line 29 of file internal.cc.

Referenced by ldap_client_config(), ldap_server_config(), ldap_system_config(), nss_config(), and LDAPDB::read().

00030 {
00031     const char *ret = get_keyval (items,key);
00032     if (ret == NULL) ret = defval;
00033     return ret;
00034 }

void set_keyval ( VIEWITEMS & items,
const char * key,
const char * val )
 

Definition at line 41 of file internal.cc.

Referenced by LDAPDB::config(), ldap_client_config(), ldap_server_config(), ldap_system_config(), and nss_config().

00042 {
00043     VIEWITEM *it = items.locate (key);      
00044     if (val[0] == '\0'){
00045         items.remove_del (it);
00046     }else{
00047         if (it == NULL){
00048             it = new VIEWITEM(key);
00049             items.add (it);
00050         }
00051         it->line.setfromf ("%s\t%s",key,val);
00052     }
00053 }

int sys_command_raw ( const char * cmd,
const char * args,
SSTRINGS & tb )
 

Definition at line 60 of file internal.cc.

Referenced by sys_command(), and sys_showfile().

00064 {
00065     int ret = -1;
00066 
00067     D(debugf(2,"sys_command: %s\nargs: %s\n",cmd,args));
00068     D(debugf(4,"RESULT BEGIN\n\n"));
00069 
00070     POPEN pop (cmd,args);
00071     if (pop.isok()){
00072         SSTRINGS tbout_err;
00073         bool oneerror = false;
00074         while (pop.wait(30) > 0){
00075             char buf[1000];
00076             buf[0] = buf[1] = buf[2] = ' ';
00077             while (pop.readout(buf+3,sizeof(buf)-4)!=-1){
00078                 tb.add (new SSTRING(buf));
00079                 tbout_err.add (new SSTRING(buf));
00080                 D(debugf(4,"%s",buf));
00081             }
00082             
00083             buf[0] = buf[1] = '*';
00084             while (pop.readerr(buf+3,sizeof(buf)-4)!=-1){
00085                 tbout_err.add (new SSTRING(buf));
00086                 oneerror = true;
00087             }
00088         }
00089         ret = pop.getstatus();
00090         if (oneerror){
00091             dialog_textbox ("Error messages",tbout_err);
00092         }
00093     }else{
00094         xconf_error (MSG_U(E_CANTEXEC,"Can't execute the command\n%s"),cmd);
00095     }
00096 
00097     D(debugf(4,"\nRESULT END\n") );
00098     return ret;
00099 }

int sys_command ( const char * cmd,
const char * args,
SSTRINGS & tb )
 

Definition at line 105 of file internal.cc.

Referenced by LDAPOBJECT::command(), and sys_command_title().

00109 {
00110     int ret = -1;
00111     char title[PATH_MAX+100];
00112     DAEMON_INTERNAL *dae = daemon_find (cmd);
00113     if (dae != NULL){
00114         snprintf (title,sizeof(title)-1
00115                   ,"%s: %s %s",MSG_U(I_OUTPUT,"Output of command")
00116                   ,dae->getpath(),args);
00117         tb.add (new SSTRING(title));
00118         ret = sys_command_raw (cmd,args,tb);
00119     }
00120     return ret;
00121 }

int sys_showfile ( const char * file,
SSTRINGS & tb )
 

Definition at line 127 of file internal.cc.

00130 {
00131     char title[PATH_MAX+100];
00132     snprintf (title,sizeof(title)-1,"%s %s",MSG_U(I_FILE,"File"),file);
00133     tb.add (new SSTRING(title));
00134     return sys_command_raw ("cat",file,tb);
00135 }

void sys_command_title ( const char * title,
const char * cmd,
const char * args )
 

Definition at line 141 of file internal.cc.

Referenced by LDAPDB::config(), LDAPDB::export_ldif(), ldap_server_control(), and ldap_status().

00145 {
00146     SSTRINGS tb;
00147     if (sys_command (cmd,args,tb) != -1){
00148         dialog_textbox (title,tb);
00149     }
00150 }

int dir_getfiltered ( const char * path,
SSTRINGS & lst,
const char * filter )
 

Definition at line 157 of file internal.cc.

Referenced by PROFILES::get_list(), and ldap_db_getlist().

00161 {
00162     int ret = 0;
00163     SSTRINGS tb;
00164     SSTRING * lsti=NULL;
00165     str_splitline(filter,' ',tb); // Get filter components
00166     dir_getlist (path,lst); // Get directory listing
00167     for (int i=0; i<lst.getnb(); i++){
00168         for (int f=0; f<tb.getnb(); f++){   
00169             lsti=lst.getitem(i);
00170             if (lsti && lsti->strstr(tb.getitem(f)->get())){
00171                 D(debugf(5,"Directory filter ignore: %s",lsti->get()));
00172                 lst.remove(lsti);
00173                 ret++;
00174             }
00175         }
00176     }
00177     return ret;
00178 }


Generated at Mon Jan 22 08:35:13 2001 for ldapconf by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000