Ejemplo n.º 1
0
END_TEST

START_TEST(test_json_send_empty)
{
    struct asfd *asfd;
    asfd=asfd_setup(BASE "/empty");
    fail_unless(!json_send(asfd, NULL, NULL, NULL, NULL, NULL, 0/*cache*/));
    tear_down(&asfd);
}
Ejemplo n.º 2
0
static void do_test_json_send_clients_with_backup(const char *path,
        struct sd *sd, int s, const char *specific_client)
{
    struct asfd *asfd;
    struct cstat *c=NULL;
    struct cstat *clist=NULL;
    const char *cnames[] = {"cli1", "cli2", "cli3", NULL};
    fail_unless(recursive_delete(CLIENTCONFDIR)==0);
    build_clientconfdir_files(cnames, NULL);
    fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
    assert_cstat_list(clist, cnames);
    for(c=clist; c; c=c->next)
    {
        c->permitted=1;
        c->protocol=PROTO_1;
        fail_unless((c->sdirs=setup_sdirs(c->protocol, c->name))!=NULL);
        build_storage_dirs((struct sdirs *)c->sdirs, sd, s);
        fail_unless(!cstat_set_backup_list(c));
        fail_unless(c->bu!=NULL);
        // Hack the cntr timestamps so that they are always the same.
        c->cntr->ent[(uint8_t)CMD_TIMESTAMP]->count=200;
        c->cntr->ent[(uint8_t)CMD_TIMESTAMP_END]->count=400;

    }
    asfd=asfd_setup(path);

    c=NULL;
    if(specific_client)
        fail_unless((c=cstat_get_by_name(clist, specific_client))!=NULL);

    fail_unless(!json_send(asfd, clist, c, NULL, NULL, NULL, 0/*cache*/));
    cstat_list_free_sdirs(clist);
    cstat_list_free(&clist);
    fail_unless(!recursive_delete(SDIRS));
    tear_down(&asfd);
}
Ejemplo n.º 3
0
int llamar_servicio_post(char *proxyHost)
{
    struct value        resJSON;
    struct soap         *soap           = soap_new();
    struct value        jsonRequest;
    struct _struct      estructuraPoC;
    struct value        title, body, userId;
    struct member       miembrosPoC[3];
    
    if (proxyHost && strlen(proxyHost) > 0) soap->proxy_host = proxyHost;
    
    printf("Ejemplo de llamada get recuperando JSON\n");
    printf("---------------------------------------\n");
    
    if (soap_post_connect(soap, "http://jsonplaceholder.typicode.com/posts", NULL, "application/json"))
    { 
        soap_print_fault(soap, stderr);
        printf("Error en la conexión con la API post.\n");
        goto finalizar;
    }
    
    // JSON con 3 miembros
    
    // Title
    title.__type        = SOAP_TYPE__string;
    char sTitle[10]     = "foo";
    title.ref           = sTitle;

    // body
    body.__type         = SOAP_TYPE__string;
    char sBody[10]      = "bar";
    body.ref            = sBody;
    
    // userId
    userId.__type       = SOAP_TYPE__int;
    int iUserId         = 1;
    userId.ref          = &iUserId;
    
    miembrosPoC[0].name     = "title";
    miembrosPoC[0].value    = title;
    miembrosPoC[1].name     = "body";
    miembrosPoC[1].value    = body;
    miembrosPoC[2].name     = "userId";
    miembrosPoC[2].value    = userId;
   
    estructuraPoC.__size = 3;
    estructuraPoC.member = miembrosPoC;
    
    jsonRequest.__type   = SOAP_TYPE__struct;
    jsonRequest.ref      = &estructuraPoC;
   
    if (json_send(soap, &jsonRequest))
    {
        soap_print_fault(soap, stderr);
        printf("Error en el envío JSON en la llamada post.\n");
        goto finalizar;
    }
    
    if (soap_end_send(soap))
    {
        soap_print_fault(soap, stderr);
        printf("Error al finalizar envío JSON en la llamada post.");
        goto finalizar;
    }
    
    if (soap_begin_recv(soap))
    {
        soap_print_fault(soap, stderr);
        printf("Error en el inicio de la recepción JSON en la API post.");
        goto finalizar;
    }
   
    if (json_recv(soap, &resJSON))
    {
        soap_print_fault(soap, stderr);
        printf("Error en la obtención del JSON en la API post.\n");
        goto finalizar;
    }
   
    if (soap_end_recv(soap))
    {
        soap_print_fault(soap, stderr);
        printf("Error en la finalización de la API post.\n");
        goto finalizar;
    }
    
    if (resJSON.__type == SOAP_TYPE__struct)
    {
        struct _struct *estructuraJSON;
        estructuraJSON = (struct _struct *)resJSON.ref;
        
        int i;
        for (i=0; i < estructuraJSON->__size; i++)
        {
            printf("%s: ", (estructuraJSON->member + i)->name);
            if ((estructuraJSON->member + i)->value.__type == SOAP_TYPE__string)
            {
                printf("Cadena: %s\n", (estructuraJSON->member + i)->value.ref);
            }
            else if ((estructuraJSON->member + i)->value.__type == SOAP_TYPE__int)
            {
                printf("Entero: %ld\n", *(int*)((estructuraJSON->member + i)->value.ref));
            }
        }
    }
    else
    {
        printf("Se recibe un JSON no esperado.\n");
        goto finalizar;
    }
    
    printf("Ha finalizado correctamente la llamada post\n");
    printf("------------------------------------------\n");
    
    finalizar:
   
    soap_destroy(soap);
    soap_end(soap);
    soap_free(soap);
    
    return 0;
}
Ejemplo n.º 4
0
static int parse_client_data(struct asfd *srfd,
	struct cstat *clist, struct conf **confs)
{
	int ret=0;
	char *command=NULL;
	char *client=NULL;
	char *backup=NULL;
	char *logfile=NULL;
	char *browse=NULL;
	const char *cp=NULL;
	struct cstat *cstat=NULL;
        struct bu *bu=NULL;
//printf("got client data: '%s'\n", srfd->rbuf->buf);

	cp=srfd->rbuf->buf;

	// The client monitor will send an initial blank line to kick things
	// off. Until it is sent, we will not even have entered the code
	// in this file. So, without it, data from the parent will not have
	// been read, and the monitor client will be given incomplete
	// information for its first response.
	// Just ignore the new line at this point, it has served its purpose.
	if(srfd->rbuf->len==1
	  && !strcmp(cp, "\n"))
	{
		ret=0;
		goto end;
	}
	command=get_str(&cp, "j:", 0);
	client=get_str(&cp, "c:", 0);
	backup=get_str(&cp, "b:", 0);
	logfile=get_str(&cp, "l:", 0);
	browse=get_str(&cp, "p:", 1);

	if(command)
	{
		if(!strcmp(command, "pretty-print-on"))
		{
			json_set_pretty_print(1);
			if(json_send_warn(srfd, "Pretty print on"))
				goto error;
		}
		else if(!strcmp(command, "pretty-print-off"))
		{
			json_set_pretty_print(0);
			if(json_send_warn(srfd, "Pretty print off"))
				goto error;
		}
		else
		{
			if(json_send_warn(srfd, "Unknown command"))
				goto error;
		}
		goto end;
	}

	if(browse)
	{
		free_w(&logfile);
		if(!(logfile=strdup_w("manifest", __func__)))
			goto error;
		strip_trailing_slashes(&browse);
	}

//dump_cbno(clist, "pcd");

	if(client && *client)
	{
		if(!(cstat=cstat_get_by_name(clist, client)))
		{
			if(json_send_warn(srfd, "Could not find client"))
				goto error;
			goto end;
		}

		if(cstat_set_backup_list(cstat))
		{
			if(json_send_warn(srfd, "Could not get backup list"))
				goto error;
			goto end;
			
		}
	}
	if(cstat && backup)
	{
		unsigned long bno=0;
		if(!(bno=strtoul(backup, NULL, 10)))
		{
			if(json_send_warn(srfd, "Could not get backup number"))
				goto error;
			goto end;
		}
		for(bu=cstat->bu; bu; bu=bu->prev)
			if(bu->bno==bno) break;

		if(!bu)
		{
			if(json_send_warn(srfd, "Backup not found"))
				goto error;
			goto end;
		}
	}
	if(logfile)
	{
		if(strcmp(logfile, "manifest")
		  && strcmp(logfile, "backup")
		  && strcmp(logfile, "restore")
		  && strcmp(logfile, "verify")
		  && strcmp(logfile, "backup_stats")
		  && strcmp(logfile, "restore_stats")
		  && strcmp(logfile, "verify_stats"))
		{
			if(json_send_warn(srfd, "File not supported"))
				goto error;
			goto end;
		}
	}
/*
	printf("client: %s\n", client?:"");
	printf("backup: %s\n", backup?:"");
	printf("logfile: %s\n", logfile?:"");
*/

	if(cstat)
	{
		if(!cstat->run_status)
			cstat_set_run_status(cstat);
	}
	else for(cstat=clist; cstat; cstat=cstat->next)
	{
		if(!cstat->run_status)
			cstat_set_run_status(cstat);
	}

	if(json_send(srfd, clist, cstat, bu, logfile, browse,
		get_int(confs[OPT_MONITOR_BROWSE_CACHE])))
			goto error;

	goto end;
error:
	ret=-1;
end:
	free_w(&client);
	free_w(&backup);
	free_w(&logfile);
	free_w(&browse);
	return ret;
}