Пример #1
0
static void
print_allowed_operations ()
{
	print_information("/h : print this help");
	print_information("/l : list chat users");
	print_information("/q : quit chat");
}
Пример #2
0
static void
handle_signals (GDBusConnection *connection,
        const gchar *sender_name,
        const gchar *object_path,
        const gchar *interface_name,
        const gchar *signal_name,
        GVariant *parameters,
        gpointer user_data)
{
	if (g_strcmp0 (signal_name, "message") == 0)
	{
		gchar *nick,*body;
		g_variant_get (parameters, "(&s&s)", &nick, &body);
		g_print ("%s: %s\n",nick,body);
	}
	else if (g_strcmp0 (signal_name, "users_list") == 0)
	{
		gchar *list;
		g_variant_get (parameters, "(&s)", &list);
		print_information(list);
	}
	else if (g_strcmp0 (signal_name, "left_chat") == 0)
	{
		gchar *nick;
		g_variant_get (parameters, "(&s)", &nick);
		print_information(g_strdup_printf("%s has left the chat!",nick));
	}
	else if (g_strcmp0 (signal_name, "joined_chat") == 0)
	{
		gchar *nick;
		g_variant_get (parameters, "(&s)", &nick);
		print_information(g_strdup_printf("%s has joined the chat!",nick));
	}
}
Пример #3
0
void				parse_file(int fd, char *str, int arg)
{
	t_header	header;
	t_list		*lbls;
	t_list		*cmds;

	lbls = NULL;
	cmds = NULL;
	g_data.cmds = &cmds;
	g_data.lbls = &lbls;
	ft_head(fd, &header);
	ft_body(fd, &header, &lbls, &cmds);
	if (cmds == NULL)
		ft_tok_error(END, ft_strdup("(null)"), NULL, 0);
	if (arg > 0)
		print_information(&header, lbls, cmds);
	else
		binary(&header, cmds, str);
	ft_lstdel(&lbls, free_lbl);
	ft_lstdel(&cmds, free_cmd);
}
Пример #4
0
static void print_session(sdp_printer_t *p, sdp_session_t const *sdp)
{
  p->pr_ok = 1;

  if (p->pr_ok && sdp->sdp_version)
    print_version(p, sdp->sdp_version);
  if (p->pr_ok && sdp->sdp_origin)
    print_origin(p, sdp->sdp_origin);
  if (p->pr_ok && sdp->sdp_subject)
    print_subject(p, sdp->sdp_subject);
  if (p->pr_ok && sdp->sdp_information)
    print_information(p, sdp->sdp_information);
  if (p->pr_ok && sdp->sdp_uri)
    print_uri(p, sdp->sdp_uri);
  if (p->pr_ok && sdp->sdp_emails)
    print_emails(p, sdp->sdp_emails);
  if (p->pr_ok && sdp->sdp_phones)
    print_phones(p, sdp->sdp_phones);
  if (p->pr_ok && sdp->sdp_connection)
    print_connection(p, sdp->sdp_connection);
  if (p->pr_ok && sdp->sdp_bandwidths)
    print_bandwidths(p, sdp->sdp_bandwidths);
  if (p->pr_ok)
    print_time(p, sdp->sdp_time);
  if (p->pr_ok && sdp->sdp_time) {
    if (p->pr_ok && sdp->sdp_time->t_repeat)
      print_repeat(p, sdp->sdp_time->t_repeat);
    if (p->pr_ok && sdp->sdp_time->t_zone)
      print_zone(p, sdp->sdp_time->t_zone);
  }
  if (p->pr_ok && sdp->sdp_key)
    print_key(p, sdp->sdp_key);
  if (p->pr_ok && sdp->sdp_charset)
    print_charset(p, sdp->sdp_charset);
  if (p->pr_ok && sdp->sdp_attributes)
    print_attributes(p, sdp->sdp_attributes);
  if (p->pr_ok && sdp->sdp_media)
    print_media(p, sdp, sdp->sdp_media);
}
Пример #5
0
static void print_media(sdp_printer_t *p,
			sdp_session_t const *sdp,
			sdp_media_t const *m)
{
  char const *media, *proto;
  sdp_rtpmap_t *rm;

  sdp_mode_t session_mode = sdp_sendrecv;

  if (!p->pr_mode_manual)
    session_mode = sdp_attribute_mode(sdp->sdp_attributes, sdp_sendrecv);

  for (;m ; m = m->m_next) {
    switch (m->m_type) {
    case sdp_media_audio:       media = "audio"; break;
    case sdp_media_video:       media = "video"; break;
    case sdp_media_application: media = "application"; break;
    case sdp_media_data:        media = "data"; break;
    case sdp_media_control:     media = "control"; break;
    case sdp_media_message:     media = "message"; break;
    case sdp_media_image  :     media = "image"; break;
    default:                    media = m->m_type_name;
    }

    switch (m->m_proto) {
    case sdp_proto_tcp:   proto = "tcp"; break;
    case sdp_proto_udp:   proto = "udp"; break;
    case sdp_proto_rtp:   proto = "RTP/AVP"; break;
    case sdp_proto_srtp:  proto = "RTP/SAVP"; break;
    case sdp_proto_udptl: proto = "udptl"; break;
    case sdp_proto_msrp:  proto = "TCP/MSRP"; break;
    case sdp_proto_msrps:  proto = "TCP/TLS/MSRP"; break;
    case sdp_proto_tls:   proto = "tls"; break;
    default:              proto = m->m_proto_name; break;
    }

    if (m->m_number_of_ports <= 1)
      sdp_printf(p, "m=%s %u %s", media, m->m_port, proto);
    else
      sdp_printf(p, "m=%s %u/%u %s",
		 media, m->m_port, m->m_number_of_ports, proto);

    if (m->m_rtpmaps) {
      for (rm = m->m_rtpmaps; rm; rm = rm->rm_next) {
	if (rm->rm_any)
	  sdp_printf(p, " *");
	else
	  sdp_printf(p, " %u", (unsigned)rm->rm_pt);
      }
    }
    else if (m->m_format) {
      sdp_list_t *l = m->m_format;
      for (; l; l = l->l_next)
	sdp_printf(p, " %s", l->l_text);
    }
    else {
      sdp_printf(p, " 19");      /* SDP syntax requires at least one format.
				    19 is used by nobody, right?. */
    }


    sdp_printf(p, CRLF);

    if (m->m_information)
      print_information(p, m->m_information);
    if (m->m_connections)
#ifdef nomore
    if (m->m_connections != sdp->sdp_connection)
#endif
      print_connection_list(p, m->m_connections);
    if (m->m_bandwidths)
      print_bandwidths(p, m->m_bandwidths);
    if (m->m_key)
      print_key(p, m->m_key);

    for (rm = m->m_rtpmaps; rm; rm = rm->rm_next) {
      if (!rm->rm_predef || p->pr_all_rtpmaps)
	sdp_printf(p, "a=rtpmap:%u %s/%lu%s%s" CRLF,
		   rm->rm_pt, rm->rm_encoding, rm->rm_rate,
		   rm->rm_params ? "/" : "",
		   rm->rm_params ? rm->rm_params : "");
      if (rm->rm_fmtp)
	sdp_printf(p, "a=fmtp:%u %s" CRLF,
		   rm->rm_pt, rm->rm_fmtp);
    }

    if (!p->pr_mode_manual && !m->m_rejected &&
	(m->m_mode != (unsigned int)session_mode || p->pr_mode_always)) {
      switch (m->m_mode) {
      case sdp_inactive:
	sdp_printf(p, "a=inactive" CRLF);
	break;
      case sdp_sendonly:
	sdp_printf(p, "a=sendonly" CRLF);
	break;
      case sdp_recvonly:
	sdp_printf(p, "a=recvonly" CRLF);
	break;
      case sdp_sendrecv:
	sdp_printf(p, "a=sendrecv" CRLF);
	break;
      default:
	break;
      }
    }

    if (p->pr_mode_manual)
      print_attributes(p, m->m_attributes);
    else
      print_attributes_without_mode(p, m->m_attributes);
  }
}
Пример #6
0
/* Program extracts from Chapter 5 of
Пример #7
0
int execute_arguments(char *program_name, struct hash_map_t *arguments) {
    /* allocates space for the possible argument
    to be executed from the arguments map */
    void *value;

    /* allocates the value to be used to verify the
    exitence of error from the function */
    ERROR_CODE return_value;

    /* sets space for the flag that will control if
    the service should be run or not, this is used
    for certain situations (mostyle test) where the
    service is not meant to be run */
    char run_service = TRUE;

    /* tries to retrieve the help argument from the arguments
    map in case the value exists prints the help value and then
    exits the current system */
    get_value_string_hash_map(arguments, (unsigned char *) "help", &value);
    if(value != NULL) {
        return help();
    }

    /* tries to retrieve the version argument from the arguments
    map in case the value exists prints the version value and then
    exits the current system */
    get_value_string_hash_map(arguments, (unsigned char *) "version", &value);
    if(value != NULL) {
        return version();
    }

    /* retrieves the test argument value from the arguments map
    and in case it's set starts the test process runing a series
    of test functions in sequence */
    get_value_string_hash_map(arguments, (unsigned char *) "test", &value);
    if(value != NULL) {
        return test();
    }

    /* retrieves the speed argument value from the arguments map
    and in case it's set starts the speed measuring and disables
    the runnig of the service */
    get_value_string_hash_map(arguments, (unsigned char *) "speed", &value);
    if(value != NULL) {
        return speed();
    }

    /* tries to retrieve the daemon argument from the
    arguments map in case the value is set daemonizes
    the current process so that it remains in background
    and returns to the caller process immediately, otherwise
    prints the viriatum information into the standard
    output "file", the label should be standard */
    get_value_string_hash_map(arguments, (unsigned char *) "daemon", &value);
    if(value != NULL) {
        daemonize();
    }
    else {
        print_information();
    }

    /* tries to retrieve the local argument from the arguments
    map in case the value exists localizes the current service
    so that any file read is read from the current directory */
    get_value_string_hash_map(arguments, (unsigned char *) "local", &value);
    if(value != NULL) {
        localize();
    }

    /* in cas the flag that control if the service must be run is
    unset the control flow must be returned immediately (avoids
    running service) */
    if(run_service == FALSE) {
        RAISE_NO_ERROR;
    }

    /* runs the service, with the given arguments, this call
    should block the program control flow until an event
    stop the running of the main loop */
    return_value = run_service_s(program_name, arguments);

    /* tests the error code for error in case it exists
    prints a message indicating the problem that occurred */
    if(IS_ERROR_CODE(return_value)) {
        V_ERROR_F("Problem running service (%s)\n", (char *) GET_ERROR());
        RAISE_AGAIN(return_value);
    }

    /* returns the normal result value as no problems has
    occured during the execution of the command */
    RAISE_NO_ERROR;
}
Пример #8
0
void print_footer(void) {
    FILE *footer = stdout;
    int counter = 0;
    int max_length = 0;
    int max_addr_length = 0;
    int pad = 0;

    max_length = addr_alias();

    if(CREATE_DEFINE == 1) {
        if(total_ip_addr != 0) {
            fputc('\n', write_define);
            fprintf(write_define, "# IP address\n");

            while(counter < total_ip_addr) {
                if(max_addr_length < strlen(ip_addr_tbl[print_to_ip[counter]])) {
                    max_addr_length = strlen(ip_addr_tbl[print_to_ip[counter]]);
                }

                counter++;
            }

            counter = 0;
            while(counter < total_ip_addr) {
                fprintf(write_define, "ip [%s] ", ip_addr_tbl[print_to_ip[counter]]);

                pad = strlen(ip_addr_tbl[print_to_ip[counter]]);
                while(pad < max_addr_length) {
                    fputc(' ', write_define);
                    pad++;
                }

                if(strlen(alias[print_to_ip[counter]]) != 0) {
                    fprintf(write_define, "[%s] ", alias[print_to_ip[counter]]);
                    pad = strlen(alias[print_to_ip[counter]]);
                } else {
                    fprintf(write_define, "[ ] ");
                    pad = max_length;
                }

                while(pad < max_length) {
                    fputc(' ', write_define);
                    pad++;
                }

                fprintf(write_define, "[ ]\n");
                counter++;
            }
        }

        if(total_mac_addr != 0) {
            fputc('\n', write_define);
            fprintf(write_define, "# MAC address\n");

            counter = 0;
            max_addr_length = 0;
            while(counter < total_mac_addr) {
                if(max_addr_length < strlen(mac_addr_tbl[print_to_mac[counter]])) {
                    max_addr_length = strlen(mac_addr_tbl[print_to_mac[counter]]);
                }

                counter++;
            }

            counter = 0;
            while(counter < total_mac_addr) {
                fprintf(write_define, "mac [%s] ", mac_addr_tbl[print_to_mac[counter]]);

                pad = strlen(mac_addr_tbl[print_to_mac[counter]]);
                while(pad < max_addr_length) {
                    fputc(' ', write_define);
                    pad++;
                }

                fprintf(write_define, "[ ]\n");
                counter++;
            }
        }
    }

    if(HTML == 1) {
        footer = fopen("footer.html", "w");
        if(footer == NULL) {
            perror("footer.html");
            exit(1);
        }

        fprintf(footer, "<HTML>\n");
        fprintf(footer, "<HEAD>\n");
        fprintf(footer, "<TITLE>");
        fprintf(footer, "flow v.%s", DATE);
        fprintf(footer, "</TITLE>\n");
        fprintf(footer, "</HEAD>\n");
        fprintf(footer, "<BODY BGCOLOR=\"#FFFFFF\">\n");
        fprintf(footer, "<PRE>\n");
    }

    if((total_ip_addr != 0) || (total_mac_addr != 0)) {
        if(HTML != 1) {
            fputc('\n', footer);
        }

        if((HTML == 1) && (total_pkts > 1000)) {
            fprintf(footer, "<STRONG>FLOW LIST</STRONG>\n");

            counter = 0;
            while(counter <= total_pkts / 1000) {
                fprintf(footer,
                        "    <A HREF=\"./body-%02d.html\" TARGET=\"body\">%05d - ",
                        counter,
                        counter * 1000 + 1);

                if(counter == total_pkts / 1000) {
                    fprintf(footer, "%05d</A>", total_pkts);
                } else {
                    fprintf(footer, "%05d</A>", (counter + 1) * 1000);
                }

                counter++;
            }

            fprintf(footer, "\n");
            fprintf(footer, "</PRE>\n");
            fprintf(footer, "<HR>\n");
            fprintf(footer, "<PRE>\n");
        }

        print_addr_tbl(footer, max_length);

        if(HTML == 1) {
            fprintf(footer, "</PRE>\n");
            fprintf(footer, "<P>\n");
            fprintf(footer, "<PRE>");
        }

        fputc('\n', footer);
    }

    print_information(footer);

    if(HTML == 1) {
        fprintf(footer, "</PRE>\n");
        fprintf(footer, "<HR>\n");
        fprintf(footer, "<P ALIGN=\"right\">\n");
        fprintf(footer, "<STRONG><I>Generated by flow v.%s by <A HREF=\"mailto:[email protected]\">TAHI Project</A></I></STRONG>\n", DATE);
        fprintf(footer, "</P>\n");
        fprintf(footer, "</BODY>\n");
        fprintf(footer, "</HTML>\n");

        fclose(footer);
    }

    return;
}
Пример #9
0
static gboolean
handle_input (GIOChannel *io_channel, gpointer *data)
{
	GIOStatus ret;
	GError *error;
	GVariant *value;
	gchar *input;
	gsize *len;

	error = NULL;

	ret = g_io_channel_read_line (io_channel, &input, len, NULL, &error);
	if (ret == G_IO_STATUS_ERROR)
	{
		g_error ("Error reading: %s\n", error->message);
		return FALSE;
	}

	input = g_regex_replace(disallowed_chars,input,g_utf8_strlen(input,MAX_CHAR),0,g_strdup(""),0,NULL);

	if (input[0] == '/')
	{
		// Special options - handle the allowed ones
		switch (input[1])
		{
			case 'h':
				print_allowed_operations();
				break;
			case 'l':
				g_dbus_connection_call (connection,
										   NULL,
										   object_path,
										   INTERFACE_PATH,
										   "ListUsers",
										   g_variant_new ("(s)", opt_name),
										   NULL,
										   G_DBUS_CALL_FLAGS_NONE,
										   -1,
										   NULL,
										   NULL,
										   &error);
				break;
			case 'q':
				g_dbus_connection_call (connection,
										   NULL,
										   object_path,
										   INTERFACE_PATH,
										   "QuitChat",
										   g_variant_new ("(s)", opt_name),
										   NULL,
										   G_DBUS_CALL_FLAGS_NONE,
										   -1,
										   NULL,
										   NULL,
										   &error);
				print_information(g_strdup_printf("KTHXBYE %s!",opt_name));
				g_main_loop_unref (loop);
				g_main_loop_quit (loop);
				break;
			default:
				print_information("Unknown command! Use \"/h\" for help.");
				break;
		}
	}
	else
	{
		g_dbus_connection_call (connection,
								   NULL,
								   object_path,
								   INTERFACE_PATH,
								   "SendMessage",
								   g_variant_new ("(ss)", opt_name, input),
								   NULL,
								   G_DBUS_CALL_FLAGS_NONE,
								   -1,
								   NULL,
								   NULL,
								   &error);
		g_free(input);
	}
	return TRUE;
}