Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

account.c

Go to the documentation of this file.
00001 /*
00002  * Yattm 
00003  *
00004  * Copyright (C) 1999, Torrey Searle <tsearle@uci.edu>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 #include "intl.h"
00023 #include <string.h>
00024 #include <stdlib.h>
00025 #include <sys/stat.h>
00026 #include <fcntl.h>
00027 
00028 #include "globals.h"
00029 #include "value_pair.h"
00030 #include "util.h"
00031 
00032 
00033 void write_account_list()
00034 {
00035     FILE * fp;
00036     char buff2[1024];
00037     GList * l1;
00038 
00039     /*
00040      * The contact list is a 3 dimensional linked list, at the top
00041      * level you have a list of groups, each group can have several
00042      * contacts, each contact can have several accounts.  Please see
00043      * the Nomenclature file in the docs directory for details
00044      */
00045 
00046     g_snprintf(buff2, 1024, "%saccounts", config_dir);
00047     if(!(fp = fdopen(creat(buff2,0700),"w")))
00048         return;
00049 
00050 
00051     for(l1 = accounts; l1; l1=l1->next )
00052     {
00053         eb_local_account * ela = (eb_local_account*)l1->data; 
00054 
00055         /*
00056         * This is the deal, what a protocol stores as account data is 
00057         * protocol specific, so you just query for the values you need to write
00058         * cool stuff :-)
00059         */
00060 
00061         GList * config = eb_services[ela->service_id].sc->write_local_config(ela);
00062         fprintf(fp, "<ACCOUNT %s>\n", eb_services[ela->service_id].name);
00063         value_pair_print_values(config, fp, 1);
00064         fprintf( fp, "</ACCOUNT>\n" );
00065     }
00066 
00067     fclose(fp);
00068 }
00069 /*
00070  * Saves the contact list to (the list of people you see go on and off
00071  * line)
00072  */
00073 
00074 void write_contact_list()
00075 {
00076     FILE * fp;
00077     char buff2[1024];
00078     GList * l1;
00079     GList * l2;
00080     GList * l3;
00081 
00082     /*
00083      * The contact list is a 3 dimensional linked list, at the top
00084      * level you have a list of groups, each group can have several
00085      * contacts, each contact can have several accounts.  Please see
00086      * the Nomenclature file in the docs directory for details
00087      */
00088 
00089     g_snprintf(buff2, 1024, "%scontacts", config_dir);
00090     if(!(fp = fdopen(creat(buff2,0700),"w")))
00091         return;
00092 
00093 
00094     for(l1 = groups; l1; l1=l1->next ) {
00095         fprintf(fp,"<GROUP>\n\tNAME=\"%s\"\n", ((grouplist*)l1->data)->name);
00096         for(l2 = ((grouplist*)l1->data)->members; l2; l2=l2->next ) {
00097             struct contact * c = (struct contact*)l2->data;
00098             char *strbuf = NULL;
00099             fprintf(fp, "\t<CONTACT>\n\t\tNAME=\"%s\"\n\t\tDEFAULT_PROTOCOL=\"%s\"\n\t\tLANGUAGE=\"%s\"\n",
00100                     c->nick, eb_services[c->default_chatb].name, c->language);
00101             strbuf = escape_string(c->trigger.param);
00102             fprintf(fp, "\t\tTRIGGER_TYPE=\"%s\"\n\t\tTRIGGER_ACTION=\"%s\"\n\t\tTRIGGER_PARAM=\"%s\"\n",
00103                     get_trigger_type_text(c->trigger.type), 
00104                     get_trigger_action_text(c->trigger.action),
00105                     strbuf);
00106             g_free (strbuf);
00107             
00108             for(l3 = ((struct contact*)l2->data)->accounts; l3; l3=l3->next) {
00109                 eb_account * account = (eb_account*)l3->data;
00110                 fprintf( fp, "\t\t<ACCOUNT %s>\n\t\t\tNAME=\"%s\"\n\t\t</ACCOUNT>\n",
00111                      eb_services[account->service_id].name,
00112                      account->handle );  
00113 
00114             }
00115             fprintf( fp, "\t</CONTACT>\n" );
00116         }
00117         fprintf( fp, "</GROUP>\n" );
00118     }
00119 
00120     fclose(fp);
00121 }
00122 
00123 /*
00124  * To load the accounts file we currently use flex and bison for
00125  * speed and robustness.... so all that we have to do is just
00126  * call account parse after opening the file and we are home free
00127  */
00128 
00129 int load_accounts()
00130 {
00131     FILE * fp;
00132     char buff2[1024];
00133     extern int accountparse();
00134     extern FILE * accountin;
00135 
00136     g_snprintf(buff2, 1024, "%saccounts",config_dir);
00137 
00138     if(!(fp = fopen(buff2,"r")))
00139         return 0;
00140     accounts = NULL;
00141 
00142     accountin = fp;
00143     accountparse();
00144     eb_debug(DBG_CORE, "closing fp\n");
00145     fclose(fp);
00146     return accounts != NULL;
00147 }
00148 
00149 /*
00150  * to load the contact list we also use flex and bison, so we just
00151  * call the parser,  (isn't life so simple now :) )
00152  */
00153 
00154 int load_contacts()
00155 {
00156     FILE * fp;
00157     char buff2[1024];
00158     extern int contactparse();
00159     extern FILE * contactin;
00160 
00161     g_snprintf(buff2, 1024, "%scontacts",config_dir);
00162 
00163     if(!(fp = fopen(buff2,"r")))
00164         return 0;
00165     contactin = fp;
00166     groups = NULL;
00167 
00168     contactparse();
00169 
00170     fclose(fp);
00171     return 1;
00172 }
00173 
00174 

Contact: Andy Maloney     [Documentation generated by doxygen]