Exemple #1
0
static gboolean
on_shutdown (gpointer user_data)
{
	debug_enter ("liferea_shutdown");

	/* prevents signal handler from calling us a second time */
	if (runState == STATE_SHUTDOWN)
		return FALSE;
		
	runState = STATE_SHUTDOWN;

	/* order is important ! */
	itemlist_free ();
	update_deinit ();
	db_deinit ();
	social_free ();

	liferea_shell_destroy ();
#ifdef USE_SM
	/* unplug */
	session_end ();
#endif
	conf_deinit ();
	
	gtk_main_quit ();
	
	debug_exit ("liferea_shutdown");
	return FALSE;
}
Exemple #2
0
int main(int argc, char *argv[])
{
  session *s;

  session_init(&argc, &argv, &s, "Pingpong_A.spr");

  if (argc < 3) return EXIT_FAILURE;
  int M = atoi(argv[1]);
  int N = atoi(argv[2]);
  printf("M: %d, N: %d\n", M, N);

  role *B = s->r(s, "B");

  int val[M];
  size_t sz = M;
  long long start_time = sc_time();

  int i;
  for (i=0; i<N; i++) {
    memset(val, i, M * sizeof(int));
    send_int_array(val, (size_t)M, B);
    sz = M;
    recv_int_array(val, &sz, B);
  }

  long long end_time = sc_time();

  printf("%s: Time elapsed: %f sec\n", s->name, sc_time_diff(start_time, end_time));

  session_end(s);

  return EXIT_SUCCESS;
}
Exemple #3
0
void		session_delete(t_session *session)
{
  t_context	*context;
  t_session	*tmp;
  t_session	*tmp2;

  session_end(session);
  context = get_context_ptr((void *)0);
  VERBOSE(printf("\033[%d;1m<%03d> - session delete\033[m\n",
		 COLOR(session->id), session->id));
  tmp = context->sessions;
  if (tmp == session)
    {
      context->sessions = tmp->next;
      session_free(tmp);
      return ;
    }
  tmp2 = tmp;
  tmp = tmp->next;
  for (tmp2 = tmp, tmp = tmp->next; tmp && tmp != session;
       tmp = tmp->next, tmp2 = tmp2->next)
    ;
  if (tmp == session)
    {
      tmp2->next = tmp->next;
      session_free(tmp);
    }
  return ;
}
int switch_action(struct config *c)
{
    char *statew;
    char state;

    if (0 < login(c)) {
        return 1;
    }

    switch (c->device.actor_command) {
        case CMD_ON:
            state = switch_on(c->avm.hostname, session_id, c->device.ain);
            break;
        case CMD_OFF:
            state = switch_off(c->avm.hostname, session_id, c->device.ain);
            break;
        case CMD_TOGGLE:
            state = switch_toggle(c->avm.hostname, session_id, c->device.ain);
            break;
        default:
            break;
    }

    if (SWITCH_STATE_ON == state) {
        statew = "on";
    } else {
        statew = "off";
    }

    utlog(LOG_NOTICE, "  %s was turned %s\n", c->device.ain, statew);
    session_end(c->avm.hostname, session_id);
    session_id = NULL;
    return 0;
}
void
zxy_end_send_file(
        zxy_request_context *context
        )
{
    session_end(context);
    zxy_destroy_request_context(context);
}
void music_messaging_done_session(const int session)
{
	MMConversation *mmconv = (MMConversation *)g_list_nth_data(conversations, session);
	
	purple_notify_message(plugin_pointer, PURPLE_NOTIFY_MSG_INFO, "Session",
						"Session Complete", NULL, NULL, NULL);
	
	session_end(mmconv);
}
void
zxy_end_request(
        zxy_request_context *context,
        zxy_http_status status
        )
{
    evhtp_send_reply(context->request, status);
    session_end(context);
    zxy_destroy_request_context(context);
}
int main(void)
{
    setlocale(LC_CTYPE, "");

    const char *config_file = "avm-motion-trigger.conf";
    struct config c = get_config(config_file);

    char *session_id = session_start(c.avm.hostname, c.avm.username,
            c.avm.password);

    size_t max_ains = 32;
    char* ains[max_ains];

    int found = switches_list(c.avm.hostname, session_id, ains, max_ains);

    if (0 == found) {
        printf(" * No switches found!\n");
    } else {
        for(short i = 0; i < found; i++) {

            char *name = switch_name(c.avm.hostname, session_id, ains[i]);

            printf("    * Found: %s\n", ains[i]);
            printf("        * Name: %s\n", name);

            if (SWITCH_PRESENT == switch_present(c.avm.hostname,
                        session_id, ains[i])) {
                printf("        * Present: yes (connected)\n");
            } else {
                printf("        * Present: no (not connected)\n");
            }

            if (SWITCH_STATE_ON == switch_state(c.avm.hostname,
                        session_id, ains[i])) {
                printf("        * State: on\n");
            } else {
                printf("        * State: off\n");
            }

            if (i < found-1) {
                printf("\n");
            }

            free(name);
            free(ains[i]);
        }
    }

    session_end(c.avm.hostname, session_id);
    free_config(&c);

    return 0;
}
Exemple #9
0
int disconnect (int *maxfds, fd_set *readfds, int *num_clients, client_data *fd_array, char *msg) {

	char *posSpace = NULL;
	char name[MAX_SIZE_USERNAME];
	int i, bchar;
	int client_sockfd;

	if(strlen(msg) < MIN_SIZE_USERNAME+12 || strlen(msg) > MAX_SIZE_USERNAME+12) { // "/disconnect " = 12
		printf(BLUE"[PROGRAM] Error command : Username too short or too long.\n[PROGRAM] Please use \"/disconnect username\"."RESET"\n\n");
		return -1;
	}

	if((posSpace = strchr(msg, ' ')) == NULL){
    printf(BLUE"[PROGRAM] Error command. Please use \"/disconnect username\"."RESET"\n\n");
    return -1;
  }
	if(strcpy(name, posSpace+1) == NULL) {
		printf(BLUE"[PROGRAM] Error command. Please use \"/disconnect username\"."RESET"\n\n");
		return -1;
	}
	name[strlen(name) - 1] = '\0';
	for(i=0 ; i < strlen(name) ; i++) {
    bchar = (isalnum((unsigned char) name[i])) ? 0 : 1;
    if(bchar) {break;}
  }
  if (bchar) {
    printf(BLUE"[PROGRAM] Error command : Username must only be composed of alphanumeric characters.\n[PROGRAM] Please use \"/disconnect username\".\n"RESET"\n\n");
    return -1;
  }

	if((client_sockfd = search_client_fd_by_name(name, fd_array, num_clients)) < 0) {
		printf(BLUE"Client is not connected"RESET"\n\n");
		return -1;
	}
	/* Fin de l'initialisation / gestion d'erreurs : on alloue de la mémoire */
	message *discomsg = (message *) malloc(sizeof(message));
	if (fd_array[search_client_array_by_fd(client_sockfd, fd_array, num_clients)].fd_transfer != 0) {
		printf(BLUE"[PROGRAM] Transfer aborted"RESET"\n");
		transfer_aborted(discomsg);
		send_msg(discomsg, &client_sockfd, readfds, fd_array, num_clients);
		close(fd_array[search_client_array_by_fd(client_sockfd, fd_array, num_clients)].fd_transfer);
		fd_array[search_client_array_by_fd(client_sockfd, fd_array, num_clients)].fd_transfer = 0;
	}
	session_end(discomsg);
	send_msg(discomsg, &client_sockfd, readfds, fd_array, num_clients);
	exitClient(client_sockfd, readfds, fd_array, num_clients);
	free((*discomsg).msg_content);
	free(discomsg);
	return 0;

}
Exemple #10
0
static void reset_serial_session(int signal)
{
    int i;

    session_end();
    if(signal) {
        /* Signal end-of-session inband with zero length packet. */
        for(i=0;i<4;i++)
            uart_write(0x5a);
        for(i=0;i<4;i++)
            uart_write(0x00);
    }
    session_start();
}
Exemple #11
0
static void regular_main(void)
{
    puts("Accepting sessions on Ethernet.");
    network_init();
    net_server_init();
    moninj_init();

    session_end();
    while(1) {
        lwip_service();
        kloader_service_essential_kmsg();
        net_server_service();
    }
}
Exemple #12
0
int main(int argc, char *argv[])
{
  session *s;
  session_init(&argc, &argv, &s, "Protocol_R2.spr");
  session_dump(s);

  long long barrier_start = sc_time();
  barrier(s->r(s, "_Others"), "R0");
  long long barrier_end = sc_time();

  sc_print_version();
  printf("%s: Barrier time: %f sec\n", s->name, sc_time_diff(barrier_start, barrier_end));

  session_end(s);

  return EXIT_SUCCESS;
}
Exemple #13
0
void session_manager_destroy( struct session_manager * self )
{
    int32_t i = 0;

    if ( self->table->count > 0 )
    {
        syslog( LOG_WARNING,
                "%s(Index=%u): the number of residual active session is %d .", __FUNCTION__, self->index, self->table->count );
    }

    for ( i = 0; i < self->table->size; ++i )
    {
        struct hashnode * head = self->table->entries + i;
        struct hashnode * node = self->table->entries + i;

        while ( node )
        {
            struct hashnode * n = node;
            struct session * s = n->session;

            // 下个节点
            node = n->next;

            // 销毁会话
            if ( s != NULL )
            {
                session_end( s, s->id );
                n->session = NULL;
            }

            // head是table创建的, 所以不需要销毁
            if ( head != n ) free( n );
        }
    }

    if ( self->table->entries != NULL )
    {
        free( self->table->entries );
        self->table->entries = NULL;
    }

    free( self );
}
static void music_button_toggled (GtkWidget *widget, gpointer data)
{
	MMConversation *mmconv = mmconv_from_conv(((MMConversation *) data)->conv);
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) 
    {
		if (((MMConversation *) data)->requested)
		{
			start_session(mmconv);
			send_request_confirmed(mmconv);
		}
		else
		{
			((MMConversation *) data)->originator = TRUE;
			send_request((MMConversation *) data);
		}
    } else {
		session_end((MMConversation *)data);
    }
}
static void
gaim_gtk_quit(void)
{
	/* XXX? */
	/* YYY is there an XXX here? */

	/* captain's log, stardate... */
	/* LOG system_log(log_quit, NULL, NULL, OPT_LOG_BUDDY_SIGNON | OPT_LOG_MY_SIGNON); */
#ifdef USE_SM
	/* unplug */
	session_end();
#endif

	/* Save the plugins we have loaded for next time. */
	gaim_gtk_plugins_save();

	/* and end it all... */
	gtk_main_quit();
}
Exemple #16
0
void session_destroy(SESSION_HANDLE session)
{
	/* Codes_SRS_SESSION_01_036: [If session is NULL, session_destroy shall do nothing.] */
	if (session != NULL)
	{
		SESSION_INSTANCE* session_instance = (SESSION_INSTANCE*)session;

		session_end(session, NULL, NULL);

		/* Codes_SRS_SESSION_01_034: [session_destroy shall free all resources allocated by session_create.] */
		/* Codes_SRS_SESSION_01_035: [The endpoint created in session_create shall be freed by calling connection_destroy_endpoint.] */
		connection_destroy_endpoint(session_instance->endpoint);
		if (session_instance->link_endpoints != NULL)
		{
			amqpalloc_free(session_instance->link_endpoints);
		}

		amqpalloc_free(session);
	}
}
Exemple #17
0
int main() {
    running = 1;
    signal(SIGINT, interrupt_handler);
    printf("Starting server\n");

    if(!init_server_socket(&sock, PORT))
        return -1;

    //A linked list might not be the most efficient for this
    llist client_sessions;
    llist_init(&client_sessions);

    queue message_queue;
    queue_init(&message_queue);

    //TODO: initialise thread pool
    const int num_workers = 4;
    pthread_t workers[num_workers];
    for(int i=0; i<num_workers; i++) {
        pthread_create(&workers[i], NULL, worker_run, (void*)&message_queue);
    }
    
    //select stuff
    fd_set readsocketset;
    fd_set writesocketset;
    fd_set errorsocketset;
    struct timeval timeout;

    while(running) {
        timeout.tv_sec = 1;
        timeout.tv_usec = 0;
        
        printf("1\n");
        build_socket_list(&client_sessions, &readsocketset);
        FD_ZERO(&readsocketset);
        FD_SET(sock, &readsocketset);

        int s = select(client_sessions.len, &readsocketset, 0, 0, &timeout);
        printf("2\n");
        if(s < 0) {
            printf("ERROR: Select error\n");
            exit(1);
        }
        //if we have a new connection create a new session
        if(FD_ISSET(sock, &readsocketset)) {
            int csock = check_for_connections(sock);
            session clientSession;
            session_init(&clientSession, csock);
            llist_append(&client_sessions, (void*)&clientSession);
        }

        printf("2\n");
        //check if each session exists in the read socket thingE
        llist_node *cur = client_sessions.head;
        while(cur != NULL) {
            int sock = ((session*)cur->data)->sock;
            //check readsocketset
            if(FD_ISSET(sock, &readsocketset)) 
                client_read_data((session*)cur->data);
            //check writesocketset
            //check errorset
            cur = cur->next;
        }

        //TODO:
        //parse the messages
        //add parsed message to the queue

        //send messages on the queue (Should this be done here?)
    }
    printf("Exiting..\n");
    
    //free memory
    llist_node *cur = client_sessions.head;
    while(cur != NULL) {
        session *sess = (session*)cur->data;
        session_end(sess);
        free(sess);
        cur = cur->next;
    }
    llist_free(&client_sessions);
    close(sock);

    pthread_exit(NULL);
}