Back to index

lightning-sunbird  0.9+nobinonly
profile.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "xp.h"
00039 
00040 #include "profile.h"
00041 #include "comstrs.h"
00042 #include "scrpthlp.h"
00043 #include "strconv.h"
00044 
00045 static char szDefaultString[] = PROFILE_DEFAULT_STRING;
00046 
00047 static void getAllArgStrings(LPSTR szFileName, LPSTR szSection, LPSTR sz1, LPSTR sz2, 
00048                              LPSTR sz3, LPSTR sz4, LPSTR sz5, LPSTR sz6, LPSTR sz7, 
00049                              int iSize)
00050 {
00051   XP_GetPrivateProfileString(szSection, KEY_ARG1, szDefaultString, sz1, iSize, szFileName);
00052   XP_GetPrivateProfileString(szSection, KEY_ARG2, szDefaultString, sz2, iSize, szFileName);
00053   XP_GetPrivateProfileString(szSection, KEY_ARG3, szDefaultString, sz3, iSize, szFileName);
00054   XP_GetPrivateProfileString(szSection, KEY_ARG4, szDefaultString, sz4, iSize, szFileName);
00055   XP_GetPrivateProfileString(szSection, KEY_ARG5, szDefaultString, sz5, iSize, szFileName);
00056   XP_GetPrivateProfileString(szSection, KEY_ARG6, szDefaultString, sz6, iSize, szFileName);
00057   XP_GetPrivateProfileString(szSection, KEY_ARG7, szDefaultString, sz7, iSize, szFileName);
00058 }
00059 
00060 ScriptItemStruct * readProfileSectionAndCreateScriptItemStruct(LPSTR szFileName, LPSTR szSection)
00061 {
00062   char szString[256];
00063 
00064   XP_GetPrivateProfileString(szSection, KEY_ACTION, szDefaultString, szString, sizeof(szString), szFileName);
00065 
00066   if(strcmp(szString, szDefaultString) == 0)
00067     return NULL;
00068 
00069   ScriptItemStruct * psis = NULL;
00070 
00071   const int iSize = 256;
00072 
00073   char sz1[iSize];
00074   char sz2[iSize];
00075   char sz3[iSize];
00076   char sz4[iSize];
00077   char sz5[iSize];
00078   char sz6[iSize];
00079   char sz7[iSize];
00080 
00081   getAllArgStrings(szFileName, szSection, sz1,sz2,sz3,sz4,sz5,sz6,sz7,iSize);
00082 
00083   DWORD dw1 = (DWORD)&sz1[0];
00084   DWORD dw2 = (DWORD)&sz2[0];
00085   DWORD dw3 = (DWORD)&sz3[0];
00086   DWORD dw4 = (DWORD)&sz4[0];
00087   DWORD dw5 = (DWORD)&sz5[0];
00088   DWORD dw6 = (DWORD)&sz6[0];
00089   DWORD dw7 = (DWORD)&sz7[0];
00090 
00091   char szDelay[32];
00092   XP_GetPrivateProfileString(szSection, KEY_DELAY, "0", szDelay, sizeof(szDelay), szFileName);
00093   DWORD dwDelay = (DWORD)atol(szDelay);
00094 
00095   if(strcmp(szString, STRING_NPN_VERSION) == 0)
00096     psis = makeScriptItemStruct(action_npn_version, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00097   else if(strcmp(szString, STRING_NPN_GETURL) == 0)
00098     psis = makeScriptItemStruct(action_npn_get_url, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00099   else if(strcmp(szString, STRING_NPN_GETURLNOTIFY) == 0)
00100     psis = makeScriptItemStruct(action_npn_get_url_notify, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00101   else if(strcmp(szString, STRING_NPN_POSTURL) == 0)
00102     psis = makeScriptItemStruct(action_npn_post_url, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00103   else if(strcmp(szString, STRING_NPN_POSTURLNOTIFY) == 0)
00104     psis = makeScriptItemStruct(action_npn_post_url_notify, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00105   else if(strcmp(szString, STRING_NPN_NEWSTREAM) == 0)
00106     psis = makeScriptItemStruct(action_npn_new_stream, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00107   else if(strcmp(szString, STRING_NPN_DESTROYSTREAM) == 0)
00108     psis = makeScriptItemStruct(action_npn_destroy_stream, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00109   else if(strcmp(szString, STRING_NPN_REQUESTREAD) == 0)
00110     psis = makeScriptItemStruct(action_npn_request_read, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00111   else if(strcmp(szString, STRING_NPN_WRITE) == 0)
00112     psis = makeScriptItemStruct(action_npn_write, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00113   else if(strcmp(szString, STRING_NPN_STATUS) == 0)
00114     psis = makeScriptItemStruct(action_npn_status, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00115   else if(strcmp(szString, STRING_NPN_USERAGENT) == 0)
00116     psis = makeScriptItemStruct(action_npn_user_agent, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00117   else if(strcmp(szString, STRING_NPN_MEMALLOC) == 0)
00118     psis = makeScriptItemStruct(action_npn_mem_alloc, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00119   else if(strcmp(szString, STRING_NPN_MEMFREE) == 0)
00120     psis = makeScriptItemStruct(action_npn_mem_free, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00121   else if(strcmp(szString, STRING_NPN_MEMFLUSH) == 0)
00122     psis = makeScriptItemStruct(action_npn_mem_flush, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00123   else if(strcmp(szString, STRING_NPN_RELOADPLUGINS) == 0)
00124     psis = makeScriptItemStruct(action_npn_reload_plugins, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00125   else if(strcmp(szString, STRING_NPN_GETJAVAENV) == 0)
00126     psis = makeScriptItemStruct(action_npn_get_java_env, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00127   else if(strcmp(szString, STRING_NPN_GETJAVAPEER) == 0)
00128     psis = makeScriptItemStruct(action_npn_get_java_peer, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00129   else if(strcmp(szString, STRING_NPN_GETVALUE) == 0)
00130     psis = makeScriptItemStruct(action_npn_get_value, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00131   else if(strcmp(szString, STRING_NPN_SETVALUE) == 0)
00132   {
00133     dw4 = (DWORD)XP_GetPrivateProfileInt(szSection, KEY_WIDTH, 0, szFileName);
00134     dw5 = (DWORD)XP_GetPrivateProfileInt(szSection, KEY_HEIGHT, 0, szFileName);
00135     psis = makeScriptItemStruct(action_npn_set_value, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00136   }
00137   else if(strcmp(szString, STRING_NPN_INVALIDATERECT) == 0)
00138   {
00139     dw3 = (DWORD)XP_GetPrivateProfileInt(szSection, KEY_TOP, 0, szFileName);
00140     dw4 = (DWORD)XP_GetPrivateProfileInt(szSection, KEY_LEFT, 0, szFileName);
00141     dw5 = (DWORD)XP_GetPrivateProfileInt(szSection, KEY_BOTTOM, 0, szFileName);
00142     dw6 = (DWORD)XP_GetPrivateProfileInt(szSection, KEY_RIGHT, 0, szFileName);
00143     psis = makeScriptItemStruct(action_npn_invalidate_rect, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00144   }
00145   else if(strcmp(szString, STRING_NPN_INVALIDATEREGION) == 0)
00146     psis = makeScriptItemStruct(action_npn_invalidate_region, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00147   else if(strcmp(szString, STRING_NPN_FORCEREDRAW) == 0)
00148     psis = makeScriptItemStruct(action_npn_force_redraw, dw1,dw2,dw3,dw4,dw5,dw6,dw7,dwDelay);
00149 
00150   return psis;
00151 }