Back to index

courier  0.68.2
Defines | Functions
http11.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define HTTP11_DEFAULTLANG   "en"

Functions

char * http11_best_content_language (const char *libdir, const char *acc_lang)
const char * http11_content_language (const char *libdir, const char *cont_lang)
const char * http11_content_locale (const char *libdir, const char *cont_lang)
const char * http11_content_ispelldict (const char *libdir, const char *cont_lang)
const char * http11_content_charset (const char *libdir, const char *acc_lang)
FILE * http11_open_langfile (const char *libdir, const char *acc_lang, const char *file)

Define Documentation

#define HTTP11_DEFAULTLANG   "en"

Definition at line 64 of file http11.h.


Function Documentation

char* http11_best_content_language ( const char *  libdir,
const char *  acc_lang 
)

Definition at line 124 of file contentlanguage.c.

{
size_t naccept=parse_accept_string(acc_lang, 0, 0);
char **languages=malloc(naccept ? sizeof(char *)*naccept:1);
double *weights=malloc(naccept ? sizeof(double)*naccept:1);
DIR    *p;
struct dirent *de;
size_t i;
#if 0
double missweight=1;
#endif
char   *bestlang=0;
double bestweight=0;
int    found_nondefault_match=0;

       if (!languages || !weights)
       {
              if (languages)       free(languages);
              if (weights)  free(weights);
              enomem();
       }
       (void)parse_accept_string(acc_lang, languages, weights);
#if 0
       for (i=0; i<naccept; i++)
              if (strcmp(languages[i], "*") == 0)       missweight=weights[i];
              /* Default weight */
#endif
       p=opendir(libdir);
       while (p && (de=readdir(p)) != 0)
       {
       FILE   *fp;

              if (*de->d_name == '.')     continue;

              if ((fp=http11_open_langfile(libdir, de->d_name, "LOCALE"))
                            != 0)
              {
#if 0
              double myweight=missweight;
#else
              double  myweight=0;
#endif

                     fclose(fp);
                     for (i=0; i<naccept; i++)
                            if (strcmp(languages[i], de->d_name) == 0)
                            {
                                   myweight=weights[i];
                                   break;
                            }
                     if (!bestlang || myweight > bestweight)
                     {
                            if (bestlang) free(bestlang);
                            bestlang=strdup(de->d_name);
                            if (!bestlang)       enomem();
                            bestweight=myweight;
                            if (i < naccept)
                                   found_nondefault_match=1;
                     }
              }
       }
       if (p) closedir(p);
       if (!bestlang || !found_nondefault_match)
       {
              if (bestlang) free(bestlang);
              if ((bestlang=malloc(sizeof(defaultlang))) == 0) enomem();
              strcpy(bestlang, defaultlang);
       }
       for (i=0; i<naccept; i++)
              free(languages[i]);
       free(languages);
       free(weights);
       return (bestlang);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* http11_content_charset ( const char *  libdir,
const char *  acc_lang 
)

Definition at line 239 of file contentlanguage.c.

{
       char buf[80];
       static char buf2[80];
       size_t naccept;
       char **charsets;
       double *weights;
       const char *p;
       size_t i;

       strcpy(buf2, get_http11(libdir, acc_lang, buf, "CHARSET",
                            RFC2045CHARSET));

       p=getenv("HTTP_ACCEPT_CHARSET");

       if (!p) p="";

       naccept=parse_accept_string(p, 0, 0);
       charsets=malloc(naccept ? sizeof(char *)*naccept:1);
       weights=malloc(naccept ? sizeof(double)*naccept:1);

       if (!charsets || !weights)
       {
              if (charsets) free(charsets);
              if (weights)  free(weights);
              enomem();
       }

       (void)parse_accept_string(p, charsets, weights);
       strcpy(buf, buf2);

       for (p=strtok(buf, ", \t\r\n"); p != NULL; p=strtok(NULL, ", \t\r\n"))
       {
              for (i=0; i<naccept; i++)
                     if (strcmp(charsets[i], p) == 0)
                     {
                            strcpy(buf2, charsets[i]);
                            for (i=0; i<naccept; i++)
                                   free(charsets[i]);
                            free(charsets);
                            free(weights);
                            return buf2;
                     }
       }

       p=strtok(buf2, ", \t\r\n");
       if (!p)
              p=RFC2045CHARSET;
       for (i=0; i<naccept; i++)
              free(charsets[i]);
       free(charsets);
       free(weights);
       return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* http11_content_ispelldict ( const char *  libdir,
const char *  cont_lang 
)

Definition at line 232 of file contentlanguage.c.

{
static char buf[80];

       return (get_http11(libdir, acc_lang, buf, "ISPELLDICT", defaultlang));
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* http11_content_language ( const char *  libdir,
const char *  cont_lang 
)

Definition at line 217 of file contentlanguage.c.

{
static char   buf[80];

       return (get_http11(libdir, acc_lang, buf, "LANGUAGE", defaultlang));
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* http11_content_locale ( const char *  libdir,
const char *  cont_lang 
)

Definition at line 224 of file contentlanguage.c.

{
static char buf[80];
const char *p=get_http11(libdir, acc_lang, buf, "LOCALE", "C");

       return (p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

FILE* http11_open_langfile ( const char *  libdir,
const char *  acc_lang,
const char *  file 
)

Definition at line 49 of file contentlanguage.c.

{
char   *p=malloc(strlen(libdir)+strlen(subdir)+strlen(file)+3);
FILE   *fp;

       if (!p)       return (0);
       strcat(strcat(strcat(strcat(strcpy(p, libdir), "/"), subdir), "/"),
              file);

       fp=fopen(p, "r");
       free(p);
       return (fp);
}

Here is the caller graph for this function: