コード例 #1
0
ファイル: debug.c プロジェクト: masterdriverz/geekcode
void print_answer_struct(const struct answer *a)
{
	printf("struct answer %s (%p): "
		"answer: %d; is%s hidden; is%s dependant\n",
		a->name, a, a->answer,
		a->display ? " not" : "",
		a->dependant ? " not" : "");
	if (a->answer > 0) {
		printf("current elem: ");
		print_elem_struct(getcontent(a));
	}
}
コード例 #2
0
int PostObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = TSqlObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< int*>(_v) = getid(); break;
        case 1: *reinterpret_cast< int*>(_v) = getblog_id(); break;
        case 2: *reinterpret_cast< QString*>(_v) = gettitle(); break;
        case 3: *reinterpret_cast< QString*>(_v) = getcontent(); break;
        case 4: *reinterpret_cast< QDateTime*>(_v) = getcreated_at(); break;
        case 5: *reinterpret_cast< QDateTime*>(_v) = getupdated_at(); break;
        case 6: *reinterpret_cast< int*>(_v) = getlock_revision(); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setid(*reinterpret_cast< int*>(_v)); break;
        case 1: setblog_id(*reinterpret_cast< int*>(_v)); break;
        case 2: settitle(*reinterpret_cast< QString*>(_v)); break;
        case 3: setcontent(*reinterpret_cast< QString*>(_v)); break;
        case 4: setcreated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 5: setupdated_at(*reinterpret_cast< QDateTime*>(_v)); break;
        case 6: setlock_revision(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 7;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 7;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 7;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
コード例 #3
0
ファイル: geekcode.c プロジェクト: masterdriverz/geekcode
static const struct elem *xgetcontent(const struct answer *obj,
		const char *format, ...)
{
	const struct elem *content;
	va_list ap;
	va_start(ap, format);
	content = getcontent(obj);
	if (!content) {
		if (format)
			vfprintf(stderr, format, ap);
		else
			fputs("Error getting content\n", stderr);
		print_answer_struct(obj);
		exit(1);
	}
	return content;
}
コード例 #4
0
int main(int argc,char **argv)
{
    if(argc!=2) {
        std::cerr << "Required path to tests folder" << std::endl;
        return 1;
    }
    try {
        int block_size[]= { 1, -1, 5, 3, 10 };
        for(unsigned i=0; i<sizeof(block_size)/sizeof(block_size[0]); i++) {
            std::cout << "Testing for max-block-size = " << block_size[i] << std::endl;
            {
                cppcms::impl::multipart_parser parser;
                TEST(parser.set_content_type(test_1_content));
                cppcms::impl::multipart_parser::files_type files;
                random_consumer c(block_size[i],parser,files);
                TEST(c(test_1_file,strlen(test_1_file))==cppcms::impl::multipart_parser::eof);
                TEST(files.size()==7);
                TEST(files[0]->name()=="test1");
                TEST(files[0]->filename()=="foo.txt");
                TEST(files[0]->mime()=="text/plain");
                std::string content = getcontent(files[0]->data());
                TEST(content=="hello\r\n");
                TEST(files[1]->name()=="test2");
                TEST(files[1]->filename()=="");
                TEST(files[1]->mime()=="");
                TEST(getcontent(files[1]->data())=="שלום");
                TEST(getcontent(files[2]->data())=="x\r");
                TEST(getcontent(files[3]->data())=="x\r\n-");
                TEST(getcontent(files[4]->data())=="x\r\n--");
                TEST(getcontent(files[5]->data())=="x\r\n--x");
                TEST(getcontent(files[6]->data())=="x\r\n--x-");
            }
            {
                cppcms::impl::multipart_parser parser;
                TEST(parser.set_content_type(test_2_content));
                cppcms::impl::multipart_parser::files_type files;
                random_consumer c(block_size[i],parser,files);
                TEST(c(test_2_file,strlen(test_2_file))==cppcms::impl::multipart_parser::eof);
                TEST(files.size()==1);
                TEST(files[0]->name()=="test1");
                TEST(files[0]->filename()=="");
                TEST(files[0]->mime()=="");
                std::string content = getcontent(files[0]->data());
                TEST(content=="hello");
            }
            std::string boundaries[4]= {
                "multipart/form-data; boundary=---------------------------11395741071221114234100471568",
                "multipart/form-data; boundary=----WebKitFormBoundaryuYwgZwieYHQ3+AR8",
                "multipart/form-data; boundary=----------jrFLC4hxayof1KyJEgmmCw",
                "multipart/form-data; boundary=---------------------------7da3a5810028"
            };
            std::string filenames[4] = {
                "firefox",
                "chrome",
                "opera",
                "ie"
            };
            for(int i=0; i<4; i++) {
                std::cout << "-- Browser " << filenames[i] << std::endl;
                std::string file_name = std::string(argv[1])+"/multipart/" + filenames[i]+".txt";
                std::ifstream file(file_name.c_str(),std::ifstream::binary);
                if(!file) {
                    std::cerr << "Failed to open file " << file_name << std::endl;
                    return 1;
                }
                std::string content = getcontent(file);
                cppcms::impl::multipart_parser parser;
                TEST(parser.set_content_type(boundaries[i]));
                cppcms::impl::multipart_parser::files_type files;
                random_consumer c(block_size[i],parser,files);
                TEST(c(content.c_str(),content.size())==cppcms::impl::multipart_parser::eof);
                TEST(files.size()==3);
                TEST(files[0]->name()=="submit-name");
                TEST(files[0]->mime()=="" && files[0]->filename().empty());
                TEST(getcontent(files[0]->data())=="שלום");
                TEST(files[1]->name()=="file");
                TEST(files[1]->mime()=="text/plain");
                if(i==3) // IE
                    TEST(files[1]->filename()=="z:\\tmp\\שלום.txt" || files[1]->filename()=="z:tmpשלום.txt");
                else
                    TEST(files[1]->filename()=="שלום.txt");
                TEST(getcontent(files[1]->data())=="שלום עולם!\n");
                TEST(files[2]->name()=="submit");
                TEST(files[2]->mime().empty());
                TEST(files[2]->filename().empty());
                TEST(getcontent(files[2]->data())=="Send");
            }
        }

    }
    catch(std::exception const &e) {
        std::cerr << "Fail: " <<e.what() << std::endl;
        return 1;
    }
    std::cout << "Ok" << std::endl;
    return 0;
}
コード例 #5
0
ファイル: server2.c プロジェクト: quasi/shakey
void sendheader(int Errcode,char **url,int clientsocket)
{
  time_t tim;
  int i,datalen;
  struct stat size;
  char *ext, buffer[1024],charsize[20];
  printf("I am send header \n");
  if(Errcode == 200)
    {
      ext = findextention(*url);
      strcpy(buffer,"HTTP/1.1 200 OK\nDate: ");
      tim = time(&tim);
      strcat(buffer,ctime(&tim));
      strcat(buffer,"Server :AsUWish/1.0 (Unix)\n");
      strcat(buffer,"Connection: close\n");
      strcat(buffer,"Content-Type: ");
      getcontent(buffer,ext);
      strcat(buffer,"\nAccept-Ranges: bytes\n");
      strcat(buffer,"Content-Length: ");
      stat(*url,&size);
      sprintf(charsize,"%d\n\n",size.st_size);
      strcat(buffer,charsize);
    }
  else if(Errcode == 301)
    {
      strcpy(buffer,"HTTP/1.1 301 Moved Permanently\n");
      tim = time(&tim);
      strcat(buffer,ctime(&tim));
      strcat(buffer,"Server :AsUWish/1.0 (Unix)\n");
      strcat(buffer,"Location: http://");
      strcat(buffer,hostname);
      strcat(buffer,*url);
      strcat(buffer,"/\n");
      printf("I am going to add the location to the header\n");
      strcat(buffer,"Connection: close\n");
      strcat(buffer,"Content-Type: text/html\n");
      strcat(buffer,"Accept-Ranges: bytes\n");
      strcat(buffer,"Content-Length: ");
      stat(error301,&size);
      sprintf(charsize,"%d\n\n",size.st_size);
      strcat(buffer,charsize);
      printf("I am about to change url\n");
      *url = error301;
    }
  else if(Errcode == 403)
    {
      strcpy(buffer,"HTTP/1.1 403 Forbidden\n");
      tim = time(&tim);
      strcat(buffer,ctime(&tim));
      strcat(buffer,"Server :AsUWish/1.0 (Unix)\n");
      strcat(buffer,"Connection: close\n");
      strcat(buffer,"Content-Type: text/html\n");
      strcat(buffer,"Accept-Ranges: bytes\n");
      strcat(buffer,"Content-Length: ");
      stat(error403,&size);
      sprintf(charsize,"%d\n\n",size.st_size);
      strcat(buffer,charsize);
      printf("I am about to change url\n");
      *url = error403;
    }
  else if(Errcode == 400)
    {
      strcpy(buffer,"HTTP/1.1 400 Bad Request\n");
      tim = time(&tim);
      strcat(buffer,ctime(&tim));
      strcat(buffer,"Server :AsUWish/1.0 (Unix)\n");
      strcat(buffer,"Connection: close\n");
      strcat(buffer,"Content-Type: text/html\n");
      strcat(buffer,"Accept-Ranges: bytes\n");
      strcat(buffer,"Content-Length: ");
      stat(error403,&size);
      sprintf(charsize,"%d\n\n",size.st_size);
      strcat(buffer,charsize);
      printf("I am about to change url\n");
      *url = error400;
    }
  puts(buffer);
  write(clientsocket,buffer,strlen(buffer));
}
コード例 #6
0
ファイル: rnn.c プロジェクト: AlbertJP/envytools
static void parsecopyright(struct rnndb *db, char *file, xmlNode *node) {
	struct rnncopyright* copyright = &db->copyright;
	xmlAttr *attr = node->properties;
	while (attr) {
		if (!strcmp(attr->name, "year")) {
			unsigned firstyear = getnumattrib(db, file, node->line, attr);
			if(!copyright->firstyear || firstyear < copyright->firstyear)
				copyright->firstyear = firstyear;
		} else {
			fprintf (stderr, "%s:%d: wrong attribute \"%s\" for copyright\n", file, node->line, attr->name);
			db->estatus = 1;
		}
		attr = attr->next;
	}
	xmlNode *chain = node->children;
	while (chain) {
		if (chain->type != XML_ELEMENT_NODE) {
		} else if (!strcmp(chain->name, "license"))
			if(copyright->license) {
				if(strcmp(copyright->license, node->content)) {
					fprintf(stderr, "fatal error: multiple different licenses specified!\n");
					abort(); /* TODO: do something better here, but headergen, xml2html, etc. should not produce anything in this case */
				}
			} else
				copyright->license = getcontent(chain);
		else if (!strcmp(chain->name, "author")) {
			struct rnnauthor* author = calloc(sizeof *author, 1);
			xmlAttr* authorattr = chain->properties;
			xmlNode *authorchild = chain->children;
			author->contributions = getcontent(chain);
			while (authorattr) {
				if (!strcmp(authorattr->name, "name"))
					author->name = strdup(getattrib(db, file, chain->line, authorattr));
				else if (!strcmp(authorattr->name, "email"))
					author->email = strdup(getattrib(db, file, chain->line, authorattr));
				else {
					fprintf (stderr, "%s:%d: wrong attribute \"%s\" for author\n", file, chain->line, authorattr->name);
					db->estatus = 1;
				}
				authorattr = authorattr->next;
			}
			while(authorchild)  {
				if (authorchild->type != XML_ELEMENT_NODE) {
				} else if (!strcmp(authorchild->name, "nick")) {
					xmlAttr* nickattr = authorchild->properties;
					char* nickname = 0;
					while(nickattr) {
						if (!strcmp(nickattr->name, "name"))
							nickname = strdup(getattrib(db, file, authorchild->line, nickattr));
						else {
							fprintf (stderr, "%s:%d: wrong attribute \"%s\" for nick\n", file, authorchild->line, nickattr->name);
							db->estatus = 1;
						}
						nickattr = nickattr->next;
					}
					if(!nickname) {
						fprintf (stderr, "%s:%d: missing \"name\" attribute for nick\n", file, authorchild->line);
						db->estatus = 1;
					} else
						ADDARRAY(author->nicknames, nickname);
				} else {
					fprintf (stderr, "%s:%d: wrong tag in author: <%s>\n", file, authorchild->line, authorchild->name);
					db->estatus = 1;
				}
				authorchild = authorchild->next;
			}
			ADDARRAY(copyright->authors, author);
		} else {
			fprintf (stderr, "%s:%d: wrong tag in copyright: <%s>\n", file, chain->line, chain->name);
			db->estatus = 1;
		}
		chain = chain->next;
	}
}