static void tray_provider_configure (ParoleProviderPlugin *provider, GtkWidget *parent) { TrayProvider *tray; tray = TRAY_PROVIDER (provider); configure_plugin (tray, parent); }
static void configure_selected (void) { pthread_mutex_lock (& mutex); int count = index_count (loadeds); for (int i = 0; i < count; i ++) { LoadedPlugin * loaded = index_get (loadeds, i); if (loaded->selected) configure_plugin (loaded); } pthread_mutex_unlock (& mutex); }
int32_t main #endif (int argc,const char *argv[]) { char *retbuf,*line,*jsonargs,*transportstr,registerbuf[MAX_JSON_FIELD]; struct plugin_info *plugin; double startmilli; cJSON *argjson; int32_t max,sendflag,sleeptime=1,len = 0; #ifndef BUNDLED portable_OS_init(); #endif milliseconds2(); max = 1000000; retbuf = malloc(max+1); plugin = calloc(1,sizeof(*plugin));// + PLUGIN_EXTRASIZE); //plugin->extrasize = PLUGIN_EXTRASIZE; plugin->ppid = OS_getppid(); strcpy(plugin->name,PLUGINSTR); if ( 0 ) { int32_t i; for (i=0; i<argc; i++) printf("(%s) ",argv[i]); printf("argc.%d\n",argc); } //printf("%s (%s).argc%d parent PID.%d\n",plugin->name,argv[0],argc,plugin->ppid); plugin->timeout = 1; if ( argc <= 2 ) { jsonargs = (argc > 1) ? stringifyM((char *)argv[1]) : stringifyM("{}"); configure_plugin(retbuf,max,plugin,jsonargs,-1); free(jsonargs); //fprintf(stderr,"PLUGIN_RETURNS.[%s]\n",retbuf), fflush(stdout); return(0); } randombytes((uint8_t *)&plugin->myid,sizeof(plugin->myid)); plugin->permanentflag = atoi(argv[1]); plugin->daemonid = calc_nxt64bits(argv[2]); #ifdef BUNDLED plugin->bundledflag = 1; #endif transportstr = get_localtransport(plugin->bundledflag); sprintf(plugin->connectaddr,"%s://SuperNET.agents",transportstr); sprintf(plugin->bindaddr,"%s://%llu",transportstr,(long long)plugin->daemonid); jsonargs = (argc >= 3) ? ((char *)argv[3]) : 0; configure_plugin(retbuf,max,plugin,jsonargs,1); printf("CONFIGURED.(%s) argc.%d: %s myid.%llu daemonid.%llu NXT.%s serviceNXT.%s\n",plugin->name,argc,plugin->permanentflag != 0 ? "PERMANENT" : "WEBSOCKET",(long long)plugin->myid,(long long)plugin->daemonid,plugin->NXTADDR,plugin->SERVICENXT);//,jsonargs!=0?jsonargs:""); if ( init_pluginsocks(plugin,plugin->permanentflag,plugin->myid,plugin->daemonid,plugin->timeout) == 0 ) { argjson = cJSON_Parse(jsonargs); if ( (len= registerAPI(registerbuf,sizeof(registerbuf)-1,plugin,argjson)) > 0 ) { //fprintf(stderr,">>>>>>>>>>>>>>> plugin.(%s) sends REGISTER SEND.(%s)\n",plugin->name,registerbuf); nn_local_broadcast2(plugin->pushsock,0,0,(uint8_t *)registerbuf,(int32_t)strlen(registerbuf)+1), plugin->numsent++; } else printf("error register API\n"); if ( argjson != 0 ) free_json(argjson); } else printf("error init_pluginsocks\n"); while ( OS_getppid() == plugin->ppid ) { retbuf[0] = 0; if ( (len= nn_recv(plugin->pullsock,&line,NN_MSG,0)) > 0 ) { len = (int32_t)strlen(line); //printf("(s%d r%d) <<<<<<<<<<<<<< %s.RECEIVED (%s).%d -> bind.(%s) connect.(%s) %s\n",plugin->numsent,plugin->numrecv,plugin->name,line,len,plugin->bindaddr,plugin->connectaddr,plugin->permanentflag != 0 ? "PERMANENT" : "WEBSOCKET"), fflush(stdout); if ( (len= process_plugin_json(retbuf,max,&sendflag,plugin,plugin->permanentflag,plugin->daemonid,plugin->myid,line)) > 0 ) { if ( plugin->bundledflag == 0 ) printf("%s\n",retbuf), fflush(stdout); if ( sendflag != 0 ) { nn_local_broadcast2(plugin->pushsock,0,0,(uint8_t *)retbuf,(int32_t)strlen(retbuf)+1), plugin->numsent++; //fprintf(stderr,">>>>>>>>>>>>>> returned.(%s)\n",retbuf); } } //else printf("null return from process_plugin_json\n"); nn_freemsg(line); } else { startmilli = milliseconds2(); if ( PLUGNAME(_idle)(plugin) == 0 ) { if ( plugin->sleepmillis != 0 ) { sleeptime = plugin->sleepmillis - (milliseconds2() - startmilli); //printf("%s sleepmillis.%d sleeptime.%d\n",plugin->name,plugin->sleepmillis,sleeptime); if ( sleeptime > 0 ) msleep2(sleeptime); } } } } fprintf(stderr,"ppid.%d changed to %d\n",plugin->ppid,OS_getppid()); PLUGNAME(_shutdown)(plugin,len); // rc == 0 -> parent process died nn_shutdown(plugin->pushsock,0); if ( plugin->pushsock != plugin->pullsock ) nn_shutdown(plugin->pullsock,0); free(plugin); return(len); }
/** * Entry point for the plugin. */ void * LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) { struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; struct GNUNET_TRANSPORT_PluginFunctions *api; struct Plugin *plugin; int res; if (NULL == env->receive) { /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully initialze the plugin or the API */ api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); api->cls = NULL; api->address_pretty_printer = &http_plugin_address_pretty_printer; api->address_to_string = &http_plugin_address_to_string; api->string_to_address = &http_string_to_address; return api; } plugin = GNUNET_malloc (sizeof (struct Plugin)); plugin->env = env; plugin->outbound_sessions = 0; plugin->inbound_sessions = 0; api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); api->cls = plugin; api->disconnect = &http_plugin_disconnect; api->address_pretty_printer = &http_plugin_address_pretty_printer; api->check_address = &http_plugin_address_suggested; api->address_to_string = &http_plugin_address_to_string; api->string_to_address = &http_string_to_address; api->get_session = &http_get_session; api->send = &http_plugin_send; #if BUILD_HTTPS plugin->name = "transport-https"; plugin->protocol = "https"; #else plugin->name = "transport-http"; plugin->protocol = "http"; #endif /* Configure plugin from configuration */ res = configure_plugin (plugin); if (res == GNUNET_SYSERR) { GNUNET_free_non_null (plugin->server_addr_v4); GNUNET_free_non_null (plugin->server_addr_v6); GNUNET_free (plugin); GNUNET_free (api); return NULL; } /* checking IPv6 support */ http_check_ipv6 (plugin); /* Start client */ res = client_start (plugin); if (res == GNUNET_SYSERR) { GNUNET_free_non_null (plugin->server_addr_v4); GNUNET_free_non_null (plugin->server_addr_v6); GNUNET_free (plugin); GNUNET_free (api); return NULL; } /* Start server */ if (plugin->client_only == GNUNET_NO) { res = server_start (plugin); if (res == GNUNET_SYSERR) { server_stop (plugin); client_stop (plugin); GNUNET_free_non_null (plugin->server_addr_v4); GNUNET_free_non_null (plugin->server_addr_v6); GNUNET_free (plugin); GNUNET_free (api); return NULL; } } /* Report addresses to transport service */ start_report_addresses (plugin); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Plugin `%s' loaded\n", plugin->name); return api; }