Back to index

courier  0.68.2
Classes | Defines | Functions | Variables
ldaplist.c File Reference
#include "config.h"
#include "sqwebmail.h"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "cgi/cgi.h"
#include "ldapaddressbook/ldapaddressbook.h"
#include "maildir/maildircreate.h"
#include "numlib/numlib.h"
#include "htmllibdir.h"
#include "addressbook.h"
#include "pref.h"
#include "rfc2045/base64.h"
#include "unicode/unicode.h"

Go to the source code of this file.

Classes

struct  search_info

Defines

#define LOCALABOOK   "sqwebmail-ldapaddressbook"

Functions

void output_scriptptrget ()
void output_attrencoded (const char *)
void output_attrencoded_oknl (const char *p)
void output_urlencoded (const char *)
void output_attrencoded_fp (const char *, FILE *)
void output_attrencoded_oknl_fp (const char *, FILE *)
void ldaplist ()
static char * getfilter ()
int ldapsearch ()
static void save_errmsg (const char *errmsg, void *voidarg)
static int parsesearch (const char *cn, const char *mail, void *voidarg)
void doldapsearch ()

Variables

const char * sqwebmail_content_charset

Class Documentation

struct search_info

Definition at line 163 of file ldaplist.c.

Class Members
unsigned counter
char errmsgbuf
FILE * fpw

Define Documentation

#define LOCALABOOK   "sqwebmail-ldapaddressbook"

Definition at line 27 of file ldaplist.c.


Function Documentation

void doldapsearch ( )

Definition at line 231 of file ldaplist.c.

{
char   *f;
struct ldapabook *abooks[2];
const struct ldapabook *ptr;

       abooks[0]=ldapabook_read(LDAPADDRESSBOOK);
       abooks[1]=ldapabook_read(LOCALABOOK);

       ptr=ldapabook_find(abooks[0], cgi("ABOOK"));
       if (!ptr)
              ptr=ldapabook_find(abooks[1], cgi("ABOOK"));

       if (ptr && (f=getfilter()) != 0)
       {
              char   *tmpname=0;
              struct search_info si;
              struct maildir_tmpcreate_info createInfo;

              pref_setldap(ptr->name);
              printf("<pre>");
              fflush(stdout);


              si.fpw=NULL;
              si.errmsgbuf[0]=0;
              si.counter=0;

              maildir_tmpcreate_init(&createInfo);
              createInfo.uniq="ldap";
              createInfo.doordie=1;

              si.fpw=maildir_tmpcreate_fp(&createInfo);

              tmpname=createInfo.tmpname;
              createInfo.tmpname=NULL;
              maildir_tmpcreate_free(&createInfo);

              if (ldapabook_search(ptr, LDAPSEARCH, f, parsesearch,
                                 save_errmsg, &si) == 0)
              {
                     int    c;

                     printf("</pre>");

                     if (si.counter == 0)
                            printf("%s", getarg("NOTFOUND"));

                     printf("<table border=\"0\" cellpadding=\"4\">\n");
              
                     fflush(si.fpw);
                     rewind(si.fpw);
                     while ((c=getc(si.fpw)) != EOF)
                            putchar(c);

                     printf("<tr><td colspan=\"2\"><hr width=\"90%%\" />"
                            "<input type=\"hidden\" name=\"ADDYCNT\" value=\"%u\" />\n"
                            "</td></tr>\n", si.counter);
                     printf("<tr><td colspan=\"2\"><table>");

                     printf("<tr><td align=\"right\">%s</td><td>"
                            "<select name=\"nick1\"><option value=\"\"></option>\n", getarg("ADD"));
                     ab_listselect_fp(stdout);
                     printf("</select></td></tr>\n");
                     printf("<tr><td align=\"right\">%s</td><td>"
                            "<input type=\"text\" name=\"nick2\" /></td></tr>\n", getarg("CREATE"));
                     printf("<tr><td></td><td>"
                            "<input type=\"submit\" name=\"import\" value=\"%s\" /></td></tr>",
                            getarg("SUBMIT"));
                     printf("</table></td></tr></table>\n");
              }
              else if (si.errmsgbuf[0])
              {
                     output_attrencoded_oknl(si.errmsgbuf);
                     printf("</pre>");

              }
              fclose(si.fpw);

              if (tmpname)
              {
                     unlink(tmpname);
                     free(tmpname);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* getfilter ( ) [static]

Definition at line 148 of file ldaplist.c.

{
       const char *p;

       if (!*cgi("ldapsearch"))
              return NULL;

       p=cgi("value");

       if (!*p)
              return NULL;

       return libmail_u_convert_toutf8(p, sqwebmail_content_charset, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ldaplist ( )

Definition at line 40 of file ldaplist.c.

{
struct ldapabook *abooks[2];
int    i;
struct ldapabook *p;
const char    *delabook=getarg("DELABOOK");
const char    *sysbook=getarg("SYSBOOK");

       if (!delabook)       delabook="";
       if (!sysbook) sysbook="";

       if (*cgi("addabook"))
       {
              struct ldapabook newbook;

              memset(&newbook, 0, sizeof(newbook));

              newbook.name=(char *)cgi("name");
              newbook.host=(char *)cgi("host");
              newbook.port=(char *)cgi("port");
              newbook.suffix=(char *)cgi("suffix");

              if (*newbook.name && *newbook.host &&
                     ldapabook_add(LOCALABOOK, &newbook) < 0)
              {
                     printf("<pre>\n");
                     perror("ldapabook_add");
                     printf("</pre>\n");
              }
       }

       if (*cgi("delabook"))
       {
              struct maildir_tmpcreate_info createInfo;
              int fd;
              maildir_tmpcreate_init(&createInfo);

              createInfo.uniq="abook";

              if ((fd=maildir_tmpcreate_fd(&createInfo)) >= 0)
              {
                     close(fd);
                     unlink(createInfo.tmpname);
                     ldapabook_del(LOCALABOOK, createInfo.tmpname,
                                  cgi("ABOOK"));
                     maildir_tmpcreate_free(&createInfo);
              }
       }

       abooks[0]=ldapabook_read(LDAPADDRESSBOOK);
       abooks[1]=ldapabook_read(LOCALABOOK);

       printf("<table border=\"0\" cellpadding=\"8\" width=\"100%%\">\n");
       for (i=0; i<2; i++)
       {
              for (p=abooks[i]; p; p=p->next)
              {
                     printf("<tr valign=\"top\"><td align=\"right\">");
                     printf("<input type=\"radio\" name=\"ABOOK\"");

                     if (pref_ldap && strcmp(pref_ldap, p->name) == 0)
                            printf(" checked=\"checked\"");

                     printf(" value=\"");
                     output_attrencoded(p->name);
                     printf("\" /></td><td><font size=\"+1\""
                            " class=\"ldaplist-name\">%s</font><br />"
                            "&nbsp;&nbsp;&nbsp;<span class=\"tt\"><font size=\"-2\""
                            " class=\"ldaplist-ldapurl\">ldap://", p->name);
                     if (*p->binddn || *p->bindpw)
                     {
                            printf("%s", p->binddn);
                            if (*p->bindpw)
                                   printf(":%s", p->bindpw);
                            printf("@");
                     }
                     printf("%s", p->host);
                     if (atoi(p->port) != 389)
                            printf(":%s", p->port);
                     if (*p->suffix)
                     {
                     char   *q;

                            printf("/");
                            q=cgiurlencode_noeq(p->suffix);
                            if (q)
                            {
                                   printf("%s", q);
                                   free(q);
                            }
                     }
                     printf("</font></span>%s</td></tr>",
                            i ? "":sysbook);
              }
       }

       if (abooks[1])
       {
              printf("<tr><td></td><td>");
              printf("<input type=\"submit\" name=\"delabook\" value=\"%s\" />",
                            delabook);
              printf("</td></tr>\n");
       }
       printf("</table>\n");
       ldapabook_free(abooks[0]);
       ldapabook_free(abooks[1]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ldapsearch ( )

Definition at line 169 of file ldaplist.c.

{
       char *p;

       if (*cgi("ABOOK") == 0) return (-1);

       if ((p=getfilter()) == NULL)
              return -1;
       free(p);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void output_attrencoded ( const char *  )

Definition at line 259 of file sqwebmail.c.

{
       output_attrencoded_fp(p, stdout);
}
void output_attrencoded_fp ( const char *  ,
FILE *   
)

Definition at line 254 of file sqwebmail.c.

{
       print_attrencodedlen(p, strlen(p), 0, fp);
}

Here is the call graph for this function:

void output_attrencoded_oknl ( const char *  p)

Definition at line 269 of file sqwebmail.c.

Here is the caller graph for this function:

void output_attrencoded_oknl_fp ( const char *  ,
FILE *   
)

Definition at line 264 of file sqwebmail.c.

{
       print_attrencodedlen(p, strlen(p), 1, fp);
}

Here is the caller graph for this function:

Definition at line 384 of file sqwebmail.c.

{
char   *p=scriptptrget();

       printf("%s", p);
       free(p);
       return;
}
void output_urlencoded ( const char *  )

Definition at line 279 of file sqwebmail.c.

{
char   *q=cgiurlencode(p);

       printf("%s", q);
       free(q);
}
static int parsesearch ( const char *  cn,
const char *  mail,
void *  voidarg 
) [static]

Definition at line 191 of file ldaplist.c.

{
       struct search_info *si=(struct search_info *)voidarg;

       char   numbuf[NUMBUFSIZE];
       char   numbuf2[NUMBUFSIZE+10];

       char *cn_native;

       cn_native=libmail_u_convert_fromutf8(cn, sqwebmail_content_charset,
                                        NULL);

       if (cn_native)
              cn=cn_native;
 
       fprintf(si->fpw, "<tr valign=\"top\"><td><input type=\"checkbox\" "
                            "name=\"%s\" value=\"&lt;",
              strcat(strcpy(numbuf2, "ADDY"),
                     libmail_str_size_t(si->counter++, numbuf)));

       output_attrencoded_fp(mail, si->fpw);
       fprintf(si->fpw, "&gt;");

       output_attrencoded_fp(cn, si->fpw);

       fprintf(si->fpw, "&quot;\" /></td><td><font size=\"+1\" class=\"ldapsearch-name\">\"");

       output_attrencoded_fp(cn, si->fpw);
       fprintf(si->fpw,
              "\"</font><font size=\"+1\" class=\"ldapsearch-addr\">&lt;");
       output_attrencoded_fp(mail, si->fpw);
       fprintf(si->fpw, "&gt;</font>");
       fprintf(si->fpw, "</td></tr>\n");

       if (cn_native)
              free(cn_native);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void save_errmsg ( const char *  errmsg,
void *  voidarg 
) [static]

Definition at line 181 of file ldaplist.c.

{
       struct search_info *si=(struct search_info *)voidarg;

       si->errmsgbuf[0]=0;
       strncat(si->errmsgbuf, errmsg, sizeof(si->errmsgbuf)-1);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 39 of file gpg.c.