Ignore:
Timestamp:
Sep 24, 2014, 9:34:21 PM (11 years ago)
Author:
dmik
Message:

icedtea-web: Merge version 1.5.1 from vendor to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/icedtea-web/plugin/icedteanp/IcedTeaPluginUtils.h

    r418 r429  
    4646#include <pthread.h>
    4747#include <stdio.h>
    48 
     48#include <stdlib.h>
     49#include <time.h>
     50#include <syslog.h>
     51#include <sys/time.h>
     52
     53#include <fcntl.h>
    4954#include <cstring>
    5055#include <iostream>
     
    5560#include <string>
    5661#include <vector>
     62#include <queue>
    5763
    5864#include <npapi.h>
    59 
    60 #if MOZILLA_VERSION_COLLAPSED < 1090100
    61 #include <npupp.h>
    62 #else
    63 #include <npapi.h>
     65#include <glib.h>
    6466#include <npruntime.h>
    65 #endif
    66 
    67 extern int plugin_debug; // defined in IcedTeaNPPlugin.cc
    68 
    69 #define PLUGIN_DEBUG(...) \
    70   do                                                          \
    71   {                                                           \
    72     if (plugin_debug)                                         \
    73     {                                                         \
    74       fprintf (stderr, "ITNPP Thread# %ld: ", pthread_self()); \
    75       fprintf (stderr, __VA_ARGS__);                          \
    76     }                                                         \
     67
     68#include "IcedTeaParseProperties.h"
     69
     70void *flush_pre_init_messages(void* data);
     71void push_pre_init_messages(char * ldm);
     72void reset_pre_init_messages();
     73
     74// debugging macro.
     75#define initialize_debug()                                                    \
     76  do                                                                          \
     77  {                                                                           \
     78    if (!debug_initiated) {                                                   \
     79      debug_initiated = true;                                                 \
     80      plugin_debug = getenv ("ICEDTEAPLUGIN_DEBUG") != NULL || is_debug_on(); \
     81      plugin_debug_headers = is_debug_header_on();                            \
     82      plugin_debug_to_file = is_logging_to_file();                            \
     83      plugin_debug_to_streams = is_logging_to_stds();                         \
     84      plugin_debug_to_system = is_logging_to_system();                        \
     85      plugin_debug_to_console = is_java_console_enabled();                    \
     86      if (plugin_debug_to_file) {                                             \
     87           IcedTeaPluginUtilities::initFileLog();                             \
     88      }                                                                       \
     89      if (plugin_debug_to_console) {                                          \
     90          /*initialisation done during jvm startup*/                          \
     91      }                                                                       \
     92      IcedTeaPluginUtilities::printDebugStatus();                             \
     93    }                                                                         \
     94  } while (0)
     95
     96
     97#define  HEADER_SIZE  500
     98#define  BODY_SIZE  500
     99#define  MESSAGE_SIZE  HEADER_SIZE + BODY_SIZE
     100#define  LDEBUG_MESSAGE_SIZE MESSAGE_SIZE+50
     101
     102//header is destination char array
     103#define CREATE_HEADER(ldebug_header)                   \
     104  do                                                   \
     105  {                                                    \
     106    char times[100];                                   \
     107    time_t t = time(NULL);                             \
     108    struct tm  p;                                      \
     109    localtime_r(&t, &p);                               \
     110    strftime(times, 100, "%a %b %d %H:%M:%S %Z %Y", &p);\
     111    const char *userNameforDebug = (getenv("USERNAME") == NULL) ? "unknown user" : getenv("USERNAME");  \
     112    /*this message is parsed in JavaConsole*/          \
     113    snprintf(ldebug_header, HEADER_SIZE, "[%s][ITW-C-PLUGIN][MESSAGE_DEBUG][%s][%s:%d] ITNPP Thread# %ld, gthread %p: ",        \
     114    userNameforDebug, times, __FILE__, __LINE__,  pthread_self(), g_thread_self ());                        \
    77115  } while (0)
     116 
     117
     118#define PLUGIN_DEBUG(...)              \
     119  do                                   \
     120  {                                    \
     121    initialize_debug();                \
     122    if (plugin_debug)  {               \
     123      char ldebug_header[HEADER_SIZE]; \
     124      char ldebug_body[BODY_SIZE];     \
     125      char ldebug_message[MESSAGE_SIZE];\
     126      if (plugin_debug_headers) {      \
     127        CREATE_HEADER(ldebug_header);  \
     128      } else {                         \
     129        sprintf(ldebug_header,"");     \
     130      }                                \
     131      snprintf(ldebug_body, BODY_SIZE,  __VA_ARGS__);                               \
     132      if (plugin_debug_to_streams) {   \
     133        snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body); \
     134        fprintf  (stdout, "%s", ldebug_message);\
     135      }                                \
     136      if (plugin_debug_to_file) {      \
     137        snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body);   \
     138        fprintf (plugin_file_log, "%s", ldebug_message);   \
     139        fflush(plugin_file_log);       \
     140      }                                \
     141      if (plugin_debug_to_console) {   \
     142        /*headers are always going to console*/            \
     143        if (!plugin_debug_headers){      \
     144          CREATE_HEADER(ldebug_header);  \
     145        }                                \
     146        snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body); \
     147        char ldebug_channel_message[LDEBUG_MESSAGE_SIZE];                               \
     148        struct timeval current_time;   \
     149        gettimeofday (&current_time, NULL);\
     150        if (jvm_up) {                  \
     151          snprintf(ldebug_channel_message, LDEBUG_MESSAGE_SIZE, "%s %ld %s", "plugindebug", current_time.tv_sec*1000000L+current_time.tv_usec, ldebug_message);   \
     152          push_pre_init_messages(ldebug_channel_message);                           \
     153        } else {                       \
     154          snprintf(ldebug_channel_message, LDEBUG_MESSAGE_SIZE, "%s %ld %s", "preinit_plugindebug", current_time.tv_sec*1000000L+current_time.tv_usec, ldebug_message);   \
     155          push_pre_init_messages(ldebug_channel_message);                            \
     156        }                              \
     157      }                                \
     158     if (plugin_debug_to_system){      \
     159     /*no debug messages to systemlog*/\
     160     }                                 \
     161    }                                  \
     162  } while (0)
     163
     164
     165#define PLUGIN_ERROR(...)              \
     166  do                                   \
     167  {                                    \
     168    initialize_debug();                \
     169    char ldebug_header[HEADER_SIZE];   \
     170    char ldebug_body[BODY_SIZE];       \
     171    char ldebug_message[MESSAGE_SIZE]; \
     172    if (plugin_debug_headers) {        \
     173      CREATE_HEADER(ldebug_header);    \
     174    } else {                           \
     175      sprintf(ldebug_header,"");       \
     176    }                                  \
     177    snprintf(ldebug_body, BODY_SIZE,  __VA_ARGS__);   \
     178    if (plugin_debug_to_streams) {     \
     179      snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body); \
     180      fprintf  (stderr, "%s", ldebug_message);                                    \
     181    }                                  \
     182    if (plugin_debug_to_file) {        \
     183      snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body); \
     184      fprintf (plugin_file_log, "%s", ldebug_message);   \
     185      fflush(plugin_file_log);         \
     186    }                                  \
     187    if (plugin_debug_to_console) {     \
     188      /*headers are always going to console*/            \
     189      if (!plugin_debug_headers){            \
     190        CREATE_HEADER(ldebug_header);  \
     191      }                                \
     192      snprintf(ldebug_message, MESSAGE_SIZE, "%s%s", ldebug_header, ldebug_body); \
     193      char ldebug_channel_message[LDEBUG_MESSAGE_SIZE];                               \
     194      struct timeval current_time;     \
     195      gettimeofday (&current_time, NULL);\
     196        if (jvm_up) {                  \
     197          snprintf(ldebug_channel_message, LDEBUG_MESSAGE_SIZE, "%s %ld %s", "pluginerror", current_time.tv_sec*1000000L+current_time.tv_usec, ldebug_message);   \
     198          push_pre_init_messages(ldebug_channel_message);                         \
     199        } else {                       \
     200          snprintf(ldebug_channel_message, LDEBUG_MESSAGE_SIZE, "%s %ld %s", "preinit_pluginerror", current_time.tv_sec*1000000L+current_time.tv_usec, ldebug_message);   \
     201          push_pre_init_messages(ldebug_channel_message);                         \
     202        }                              \
     203    }                                  \
     204    if (plugin_debug_to_system){      \
     205      /*java can not have prefix*/    \
     206      openlog("", LOG_NDELAY, LOG_USER);\
     207      syslog(LOG_ERR, "%s", "IcedTea-Web c-plugin - for more info see itweb-settings debug options or console. See http://icedtea.classpath.org/wiki/IcedTea-Web#Filing_bugs for help.");\
     208      syslog(LOG_ERR, "%s", "IcedTea-Web c-plugin error manual log:");\
     209      /*no headers to syslog*/        \
     210      syslog(LOG_ERR, "%s", ldebug_body);   \
     211      closelog();                     \
     212    }                                 \
     213   } while (0)
     214
    78215
    79216#define CHECK_JAVA_RESULT(result_data)                               \
     
    81218    if (((JavaResultData*) result_data)->error_occurred)             \
    82219    {                                                                \
    83         printf("Error: Error occurred on Java side: %s.\n",          \
     220        PLUGIN_ERROR("Error: Error occurred on Java side: %s.\n",    \
    84221               ((JavaResultData*) result_data)->error_msg->c_str()); \
    85222        return;                                                      \
     
    213350        static std::string NPVariantAsString(NPVariant variant);
    214351
     352        /* This must be freed with browserfunctions.memfree */
     353        static NPString NPStringCopy(const std::string& result);
     354
     355        /* This must be freed with browserfunctions.releasevariantvalue */
     356        static NPVariant NPVariantStringCopy(const std::string& result);
     357
     358        /* Returns an std::string represented by the given identifier. */
     359        static std::string NPIdentifierAsString(NPIdentifier id);
     360
    215361        /* Frees the given vector and the strings that its contents point to */
    216362        static void freeStringPtrVector(std::vector<std::string*>* v);
     
    244390        static void printNPVariant(NPVariant variant);
    245391
    246         static void NPVariantToString(NPVariant variant, std::string* result);
     392        static void NPVariantToString(NPVariant variant, std::string* result);
    247393
    248394        static bool javaResultToNPVariant(NPP instance,
     
    254400        static void storeInstanceID(void* member_ptr, NPP instance);
    255401
    256         static void     removeInstanceID(void* member_ptr);
    257 
    258         static NPP getInstanceFromMemberPtr(void* member_ptr);
     402        static void removeInstanceID(void* member_ptr);
     403
     404        /* Clear object_map. Useful for tests. */
     405        static void clearInstanceIDs();
     406
     407        static NPP getInstanceFromMemberPtr(void* member_ptr);
    259408
    260409        static NPObject* getNPObjectFromJavaKey(std::string key);
     
    264413        static void removeObjectMapping(std::string key);
    265414
     415        /* Clear object_map. Useful for tests. */
     416        static void clearObjectMapping();
     417
    266418        static void invalidateInstance(NPP instance);
    267419
     
    269421
    270422        static void decodeURL(const char* url, char** decoded_url);
     423
     424        /* Returns a vector of gchar* pointing to the elements of the vector string passed in*/
     425        static std::vector<gchar*> vectorStringToVectorGchar(const std::vector<std::string>* stringVec);
    271426
    272427        /* Posts call in async queue and waits till execution completes */
    273428        static void callAndWaitForResult(NPP instance, void (*func) (void *), AsyncCallThreadData* data);
     429
     430        /*cutting whitespaces from end and start of string*/
     431        static void trim(std::string& str);
     432        static bool file_exists(std::string filename);
     433        //file-loggers helpers
     434        static std::string generateLogFileName();
     435        static void initFileLog();
     436        static void printDebugStatus();
     437        static std::string getTmpPath();
     438        static std::string getRuntimePath();
    274439};
    275440
     
    338503};
    339504
     505
     506
    340507#endif // __ICEDTEAPLUGINUTILS_H__
Note: See TracChangeset for help on using the changeset viewer.