软件著作权-源代码范本

合集下载

软件著作权-源代码范本

软件著作权-源代码范本

软件著作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline。

h>#include <tybs/dir.h>#include <tybs/entropy.h>#include 〈tybs/file。

h>#include 〈tybs/hash。

h>#include 〈tybs/os。

h>#include <tybs/platform.h〉#include 〈tybs/resource。

h〉#include 〈tybs/stdio.h〉#include 〈tybs/string.h>#include 〈tybs/task.h>#include 〈tybs/timer。

h〉#include 〈tybs/util。

h〉#include <tybscc/result.h〉#include 〈dns/dispatch。

h〉#include <dns/name.h〉#include <dns/result.h>#include <dns/view.h>#include 〈dst/result.h〉#define NS_MAIN 1#include <named/ns_smf_globals。

h〉#endif#ifdef DLZ#include 〈dlz/dlz_drivers。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybscc/>#include <dns/>#include <dns/>#include <dns/>#include <dns/>#include <dst/>#define NS_MAIN 1#include <named/>#endif#ifdef DLZ#include <dlz/>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type, const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks); if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE); if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) { if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")", #else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name)); if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\')) ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include ""#include <>#include <>#ifdef PHP_WIN32#include "win32/"#include "win32/"#include "win32/"#include <>#elif defined(NETWARE)#include <sys/>#ifdef USE_WINSOCK#include <>#endif#endif#if HAVE_SYS_TIME_H#include <sys/>#endif#endif#if HAVE_SIGNAL_H#include <>#endif#if HAVE_SETLOCALE#include <>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include "ext/standard/" #include ""#include "ext/standard/" #ifdef PHP_WIN32#include <>#include "win32/"#include "ext/standard/" #endif#include ""#include "Zend/"#if PHP_SIGCHILD#include <sys/>#include <sys/>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-") /* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit) {if (new_value) {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) { mode = PHP_DISPLAY_ERRORS_STDOUT;}}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp, "cli") || !strcmp, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){return FAILURE;}return SUCCESS;}#ifndef PHP_SAFE_MODE_EXEC_DIR# define PHP_SAFE_MODE_EXEC_DIR ""#endif#if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "#elif defined(PHP_WIN32)# define DEFAULT_SENDMAIL_PATH NULL#else# define DEFAULT_SENDMAIL_PATH "/usr/sbin/sendmail -t -i"#endifPHPAPI void php_log_err(char *log_message TSRMLS_DC){int fd = -1;char error_time_str[128];struct tm tmbuf;time_t error_time;/* Try to use the specified logging location. */if (PG(error_log) != NULL) {#ifdef HAVE_SYSLOG_Hif (!strcmp(PG(error_log), "syslog")) {php_syslog(LOG_NOTICE, "%.500s", log_message);return;}#endiffd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);if (fd != -1) {char *tmp;。

软件著作权-源代码范本

软件著作权-源代码范本

软件著作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS#include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h" #include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h" #endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length)int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;}return SUCCESS;}#ifndef PHP_SAFE_MODE_EXEC_DIR# define PHP_SAFE_MODE_EXEC_DIR ""#endif#if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)# define DEFAULT_SENDMAIL_PA TH PHP_PROG_SENDMAIL " -t -i "#elif defined(PHP_WIN32)# define DEFAULT_SENDMAIL_PA TH NULL#else# define DEFAULT_SENDMAIL_PA TH "/usr/sbin/sendmail -t -i"#endif。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conf];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMA T_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conf = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conf)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_create(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_(ns_g_conffile)) {result = tybs_(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *) {if (memstats != NULL) {free(memstats);memstats = NULL;}if ( == NULL)return;memstats = malloc(strlen() + 1);if (memstats)strcpy(memstats, );}ns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {char *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conf] == '/' || ns_g_conf] == '\\'))ns_main_earlywarning("config (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)"failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h" #include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h" #endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h" #include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision) {int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_))) {return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;。

软件著作权-源代码范本

软件著作权-源代码范本

软件著作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h> #include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX]; static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) { va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line); vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] " "[-d debuglevel]\n""[-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n""[-t chrootdir] [-u username] [-i pidfile]\n""[-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] " "[-f|-g] [-n number_of_cpus]\n""[-p port] [-s] [-t chrootdir] [-u username]\n" "[-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line); for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated)); if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg); if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg); return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs,unsigned int *ret) {for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv, ":C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS"); tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6"); if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS"); tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument; lwresd_g_conffile = tybs_commandline_argument; if (lwresd_g_useresolvconf)ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument, "debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument; break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument, "number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port"); if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port"); if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;软件著作权-源代码范本break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments"); }}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s", cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0,&ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy); tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr); tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0,ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL)); if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN,TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version, saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN,TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize, &ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize, &ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize, &ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles, &ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of " "configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s", tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) {scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) { if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__, "scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 && (ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\')) ns_main_earlywarning("config filename (-c %s) contains " "chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx); if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0) UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) { FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp); if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETWARE) #include <sys/timeval.h> #ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HAVE_SYS_TIME_H#include <sys/time.h>#endif#if HAVE_UNISTD_H#include <unistd.h>#endif#if HAVE_SIGNAL_H#include <signal.h>#endif#if HAVE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h" #include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h" #endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h" #include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-") /* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */}return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions")); while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC); s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC); }}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes")); while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */ return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, intvalue_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) { mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) { mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode !=PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool)php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode)。

软件著作权-源代码范本

软件著作权-源代码范本

软件著作权-源代码范本之蔡仲巾千创作注意事项:罕见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不克不及出现开源代码,不克不及出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,缺乏60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页很多于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX]; static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) { va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Voidns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS"); tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument, "number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s", cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\')) ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETWARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#if HAVE_SYS_TIME_H#include <sys/time.h>#endif#if HAVE_UNISTD_H#include <unistd.h>#endif#if HAVE_SIGNAL_H#include <signal.h>#endif#if HAVE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h" #include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h" #include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout)if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) { mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) { mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) { mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) { mode = PHP_DISPLAY_ERRORS_STDOUT;if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) &&strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;}return SUCCESS;}。

软件著作权-源代码范本

软件著作权-源代码范本

软件著作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0)ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) {scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h"#include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h"#include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;}return SUCCESS;}。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件着作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,着作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named";static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMA T_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) {for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DA TE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h"#include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h"#include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL,。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybscc/>#include <dns/>#include <dns/>#include <dns/>#include <dns/>#include <dst/>#define NS_MAIN 1#include <named/>#endif#ifdef DLZ#include <dlz/>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) { va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type, const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);library_unexpected_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;fprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;ns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\')) ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) { FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS#include ""#include <>#include <>#ifdef PHP_WIN32#include "win32/"#include "win32/"#include "win32/"#include <>#elif defined(NETWARE)#include <sys/>#ifdef USE_WINSOCK#include <>#endif#endif#if HAVE_SYS_TIME_H#include <sys/>#endif#if HAVE_UNISTD_H#include <>#endif#if HAVE_SIGNAL_H#include <>#if HAVE_SETLOCALE#include <>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include "ext/standard/"#include ""#include "ext/standard/"#ifdef PHP_WIN32#include <>#include "win32/"#include "ext/standard/"#endif#include ""#include "Zend/"#if PHP_SIGCHILD#include <sys/>#include <sys/>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-") /* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) { mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp, "cli") || !strcmp, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMA T_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0)ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) {scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) {UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h"#include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h"#include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;}return SUCCESS;}#ifndef PHP_SAFE_MODE_EXEC_DIR# define PHP_SAFE_MODE_EXEC_DIR ""#endif#if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)# define DEFAULT_SENDMAIL_PA TH PHP_PROG_SENDMAIL " -t -i "#elif defined(PHP_WIN32)# define DEFAULT_SENDMAIL_PA TH NULL#else。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本-标准化文件发布号:(9456-EUATWK-MWUB-WUNN-INNUL-DDQTY-KII计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line); for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated)); if (dst == eob)strcpy(eob - sizeof(truncated), truncated);*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '':usage();if (tybs_commandline_option == '')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 "" : "s",ns_g_cpus, ns_g_cpus == 1 "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks); if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETWARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HAVE_SYS_TIME_H#include <sys/time.h>#endif#if HAVE_UNISTD_H#include <unistd.h>#endif#if HAVE_SIGNAL_H#include <signal.h>#endif#if HAVE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h" #include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h" #include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#define SAFE_FILENAME(f) ((f)(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}{char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length) {int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ini_entry->orig_value : NULL );} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi")); switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybscc/>#include <dns/>#include <dns/>#include <dns/>#include <dns/>#include <dst/>#define NS_MAIN 1#include <named/>#endif#ifdef DLZ#include <dlz/>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type, const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n"); }static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n"); }static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '':usage();if (tybs_commandline_option == '')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 "" : "s",ns_g_cpus, ns_g_cpus == 1 "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;char *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS#include ""#include <>#include <>#ifdef PHP_WIN32#include "win32/"#include "win32/"#include "win32/"#include <>#elif defined(NETWARE)#include <sys/>#ifdef USE_WINSOCK#include <>#endif#endif#if HAVE_SYS_TIME_H#include <sys/>#endif#if HAVE_UNISTD_H#include <>#endif#if HAVE_SIGNAL_H#include <>#if HAVE_SETLOCALE#include <>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include "ext/standard/"#include ""#include "ext/standard/"#ifdef PHP_WIN32#include <>#include "win32/"#include "ext/standard/"#endif#include ""#include "Zend/"#if PHP_SIGCHILD#include <sys/>#include <sys/>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)(f):"-") /* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision) {int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) { mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp, "cli") || !strcmp, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) &&strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra)。

软件著作权-源代码范本

软件著作权-源代码范本

软件著作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,。

NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷.格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h〉#include <tybs/dir。

h>#include <tybs/entropy.h〉#include <tybs/file.h>#include 〈tybs/hash。

h>#include 〈tybs/os.h〉#include 〈tybs/platform。

h>#include <tybs/resource。

h>#include 〈tybs/stdio。

h>#include 〈tybs/string。

h>#include <tybs/task。

h>#include 〈tybs/timer。

h>#include 〈tybs/util。

h>#include <tybscc/result。

h>#include <dns/dispatch.h〉#include <dns/name.h〉#include <dns/result.h>#include <dns/view.h>#include 〈dst/result.h〉#define NS_MAIN 1#include 〈named/ns_smf_globals。

h〉#endif#ifdef DLZ#include <dlz/dlz_drivers。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybscc/>#include <dns/>#include <dns/>#include <dns/>#include <dns/>#include <dst/>#define NS_MAIN 1#include <named/>#endif#ifdef DLZ#include <dlz/>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type, const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n"); }static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n"); }static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '':usage();if (tybs_commandline_option == '')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 "" : "s",ns_g_cpus, ns_g_cpus == 1 "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS#include ""#include <>#include <>#ifdef PHP_WIN32#include "win32/"#include "win32/"#include "win32/"#include <>#elif defined(NETWARE)#include <sys/>#ifdef USE_WINSOCK#include <>#endif#endif#if HAVE_SYS_TIME_H#include <sys/>#endif#if HAVE_UNISTD_H#include <>#endif#if HAVE_SIGNAL_H#include <>#endif#if HAVE_SETLOCALE#include <>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include "ext/standard/"#include ""#include "ext/standard/"#ifdef PHP_WIN32#include <>#include "win32/"#include "ext/standard/"#endif#include ""#include "Zend/"#if PHP_SIGCHILD#include <sys/>#include <sys/>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) { mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp, "cli") || !strcmp, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) &&strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;}return SUCCESS;}#ifndef PHP_SAFE_MODE_EXEC_DIR# define PHP_SAFE_MODE_EXEC_DIR ""。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}V oid ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMA T_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN,TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h"#include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h"#include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) &&。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMA T_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0)ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) {scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) {UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h"#include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h"#include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;}return SUCCESS;}#ifndef PHP_SAFE_MODE_EXEC_DIR# define PHP_SAFE_MODE_EXEC_DIR ""#endif#if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)# define DEFAULT_SENDMAIL_PA TH PHP_PROG_SENDMAIL " -t -i "#elif defined(PHP_WIN32)# define DEFAULT_SENDMAIL_PA TH NULL#else。

计算机软件著作权登记-源代码范本

计算机软件著作权登记-源代码范本

计算机软件着作权登记-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,着作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named";static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMA T_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n"); }static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '':usage();if (tybs_commandline_option == '')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 "" : "s",ns_g_cpus, ns_g_cpus == 1 "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) {scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h"#include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h"#include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");。

软件著作权-源代码范本

软件著作权-源代码范本

软件着作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,着作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybs/>#include <tybscc/>#include <dns/>#include <dns/>#include <dns/>#include <dns/>#include <dst/>#define NS_MAIN 1#include <named/>#endif#ifdef DLZ#include <dlz/>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) { va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type, const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0)ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '':usage();if (tybs_commandline_option == '')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 "" : "s",ns_g_cpus, ns_g_cpus == 1 "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\')) ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS#include ""#include <>#include <>#ifdef PHP_WIN32#include "win32/"#include "win32/"#include "win32/"#include <>#elif defined(NETWARE)#include <sys/>#ifdef USE_WINSOCK#include <>#endif#if HAVE_SYS_TIME_H#include <sys/>#endif#if HAVE_UNISTD_H#include <>#endif#if HAVE_SIGNAL_H#include <>#endif#if HAVE_SETLOCALE#include <>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include "ext/standard/"#include ""#include "ext/standard/"#ifdef PHP_WIN32#include <>#include "win32/"#include "ext/standard/"#endif#include ""#include "Zend/"#if PHP_SIGCHILD#include <sys/>#include <sys/>#endif#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""#include ""/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)(f):"-") /* {{{ PHP_INI_MHstatic PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp, "cli") || !strcmp, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;}return SUCCESS;}#ifndef PHP_SAFE_MODE_EXEC_DIR# define PHP_SAFE_MODE_EXEC_DIR ""#endif#if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "#elif defined(PHP_WIN32)# define DEFAULT_SENDMAIL_PATH NULL#else# define DEFAULT_SENDMAIL_PATH "/usr/sbin/sendmail -t -i"#endifPHPAPI void php_log_err(char *log_message TSRMLS_DC){int fd = -1;char error_time_str[128];struct tm tmbuf;time_t error_time;/* Try to use the specified logging location. */if (PG(error_log) != NULL) {#ifdef HAVE_SYSLOG_Hif (!strcmp(PG(error_log), "syslog")) {php_syslog(LOG_NOTICE, "%.500s", log_message);return;}#endiffd = VCWD_OPEN_MODE(PG(error_log), O_CREAT | O_APPEND | O_WRONLY, 0644);if (fd != -1) {char *tmp;int len;time(&error_time);strftime(error_time_str, sizeof(error_time_str), "%d-%b-%Y %H:%M:%S", php_localtime_r(&error_time, &tmbuf));len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);#ifdef PHP_WIN32php_flock(fd, 2);#endifwrite(fd, tmp, len);。

软件著作权-源代码例范本

软件著作权-源代码例范本

软件著作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_WARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) { va_list args;if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type, const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format, va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HAVE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HAVE_LIBSCF */#ifdef PATH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PATH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PATH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HAVE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HAVE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DATE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\')) ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HAVE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HAVE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS#include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETWARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HAVE_SYS_TIME_H#include <sys/time.h>#endif#if HAVE_UNISTD_H#include <unistd.h>#endif#if HAVE_SIGNAL_H#include <signal.h>#endif#if HAVE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h" #include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h" #endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h" #include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length) {int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) { mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;}return SUCCESS;}#ifndef PHP_SAFE_MODE_EXEC_DIR# define PHP_SAFE_MODE_EXEC_DIR ""#endif#if defined(PHP_PROG_SENDMAIL) && !defined(NETWARE)# define DEFAULT_SENDMAIL_PATH PHP_PROG_SENDMAIL " -t -i "#elif defined(PHP_WIN32)# define DEFAULT_SENDMAIL_PATH NULL#else# define DEFAULT_SENDMAIL_PATH "/usr/sbin/sendmail -t -i"#endifPHPAPI void php_log_err(char *log_message TSRMLS_DC)。

软件著作权-源代码范本

软件著作权-源代码范本

软件著作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续40页,不足80页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于45行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMA T_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();return;}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] "" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);return (tmp);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) {scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) {if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS #include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h"#include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h"#endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h"#include "SAPI.h"#include "rfc1867.h"/* }}} */#ifndef ZTSphp_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length){int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");}break;case PHP_DISPLAY_ERRORS_STDOUT:if (cgi_or_cli ) {PUTS("STDOUT");} else {PUTS("On");}break;default:PUTS("Off");break;}}static PHP_INI_MH(OnUpdateErrorLog){/* Only do the safemode/open_basedir check at runtime */if ((stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) && strcmp(new_value, "syslog")) {if (PG(safe_mode) && (!php_checkuid(new_value, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {return FAILURE;}if (PG(open_basedir) && php_check_open_basedir(new_value TSRMLS_CC)) {return FAILURE;}}OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);return SUCCESS;}static PHP_INI_MH(OnChangeMailForceExtra){/* Don't allow changing it in htaccess */if (stage == PHP_INI_STAGE_HTACCESS) {return FAILURE;。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

软件著作权-源代码范本注意事项:常见的源代码包含:C语言,VB,C++,JAVA,.NET等。

提交的代码必须是源代码的开头载入程序,第30页必须断开,第60页是软件的程序结尾,代码中不得出现与申请表内容不符合的日期,著作权人,软件名字等,不能出现开源代码,不能出现任何版权纠纷。

格式要求:一、源代码应提交前、后各连续30页,不足60页的,应当全部提交。

二、源代码页眉应标注软件的名称和版本号,应当与申请表中名称完全一致,页眉右上应标注页码,源代码每页不少于50行。

范例如下:#include <tybs/commandline.h>#include <tybs/dir.h>#include <tybs/entropy.h>#include <tybs/file.h>#include <tybs/hash.h>#include <tybs/os.h>#include <tybs/platform.h>#include <tybs/resource.h>#include <tybs/stdio.h>#include <tybs/string.h>#include <tybs/task.h>#include <tybs/timer.h>#include <tybs/util.h>#include <tybscc/result.h>#include <dns/dispatch.h>#include <dns/name.h>#include <dns/result.h>#include <dns/view.h>#include <dst/result.h>#define NS_MAIN 1#include <named/ns_smf_globals.h>#endif#ifdef DLZ#include <dlz/dlz_drivers.h>#endifstatic tybs_boolean_t want_stats = TYBS_FALSE;static char program_name[TYBS_DIR_NAMEMAX] = "named"; static char absolute_conffile[TYBS_DIR_PATHMAX];static char saved_command_line[512];static char version[512];static unsigned int maxsocks = 0;voidns_main_earlywarning(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_W ARNING,format, args);} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);}Void ns_main_earlyfatal(const char *format, ...) {va_list args;va_start(args, format);if (ns_g_lctx != NULL) {tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to early fatal error)");} else {fprintf(stderr, "%s: ", program_name);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}va_end(args);exit(1);}static voidassertion_failed(const char *file, int line, tybs_assertiontype_t type,const char *cond){if (ns_g_lctx != NULL) {tybs_assertion_setcallback(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: %s(%s) failed", file, line,tybs_assertion_typetotext(type), cond);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to assertion failure)");} else {fprintf(stderr, "%s:%d: %s(%s) failed\n",file, line, tybs_assertion_typetotext(type), cond);fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_fatal_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_error_setfatal(NULL);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"%s:%d: fatal error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,format, args);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_CRITICAL,"exiting (due to fatal error in library)");} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}if (ns_g_coreok)abort();exit(1);}static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args) TYBS_FORMAT_PRINTF(3, 0);static voidlibrary_unexpected_error(const char *file, int line, const char *format,va_list args){if (ns_g_lctx != NULL) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,"%s:%d: unexpected error:", file, line);tybs_log_vwrite(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_MAIN, TYBS_LOG_ERROR,format, args);} else {fprintf(stderr, "%s:%d: fatal error: ", file, line);vfprintf(stderr, format, args);fprintf(stderr, "\n");fflush(stderr);}}static voidlwresd_usage(void) {fprintf(stderr,"usage: lwresd [-4|-6] [-c conffile | -C resolvconffile] ""[-d debuglevel]\n"" [-f|-g] [-n number_of_cpus] [-p port] ""[-P listen-port] [-s]\n"" [-t chrootdir] [-u username] [-i pidfile]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidusage(void) {if (ns_g_lwresdonly) {lwresd_usage();}fprintf(stderr,"usage: named [-4|-6] [-c conffile] [-d debuglevel] ""[-f|-g] [-n number_of_cpus]\n"" [-p port] [-s] [-t chrootdir] [-u username]\n"" [-m {usage|trace|record|size|mctx}]\n");}static voidsave_command_line(int argc, char *argv[]) {int i;char *src;char *dst;char *eob;const char truncated[] = "...";tybs_boolean_t quoted = TYBS_FALSE;dst = saved_command_line;eob = saved_command_line + sizeof(saved_command_line);for (i = 1; i < argc && dst < eob; i++) {*dst++ = ' ';src = argv[i];while (*src != '\0' && dst < eob) {if (quoted || isalnum(*src & 0xff) ||*src == '-' || *src == '_' ||*src == '.' || *src == '/') {*dst++ = *src++;quoted = TYBS_FALSE;} else {*dst++ = '\\';quoted = TYBS_TRUE;}}}INSIST(sizeof(saved_command_line) >= sizeof(truncated));if (dst == eob)strcpy(eob - sizeof(truncated), truncated);else*dst = '\0';}static intparse_int(char *arg, const char *desc) {char *endp;int tmp;long int ltmp;ltmp = strtol(arg, &endp, 10);tmp = (int) ltmp;if (*endp != '\0')ns_main_earlyfatal("%s '%s' must be numeric", desc, arg);if (tmp < 0 || tmp != ltmp)ns_main_earlyfatal("%s '%s' out of range", desc, arg);}static struct flag_def {const char *name;unsigned int value;} mem_debug_flags[] = {{ "trace", TYBS_MEM_DEBUGTRACE },{ "record", TYBS_MEM_DEBUGRECORD },{ "usage", TYBS_MEM_DEBUGUSAGE },{ "size", TYBS_MEM_DEBUGSIZE },{ "mctx", TYBS_MEM_DEBUGCTX },{ NULL, 0 }};static voidset_flags(const char *arg, struct flag_def *defs, unsigned int *ret) { for (;;) {const struct flag_def *def;const char *end = strchr(arg, ',');int arglen;if (end == NULL)end = arg + strlen(arg);arglen = end - arg;for (def = defs; def->name != NULL; def++) {if (arglen == (int)strlen(def->name) &&memcmp(arg, def->name, arglen) == 0) {*ret |= def->value;goto found;}}ns_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);found:if (*end == '\0')break;arg = end + 1;}}static voidparse_command_line(int argc, char *argv[]) {int ch;int port;tybs_boolean_t disable6 = TYBS_FALSE;tybs_boolean_t disable4 = TYBS_FALSE;save_command_line(argc, argv);tybs_commandline_errprint = TYBS_FALSE;while ((ch = tybs_commandline_parse(argc, argv,"46c:C:d:fgi:lm:n:N:p:P:""sS:t:T:u:vVx:")) != -1) {switch (ch) {case '4':if (disable4)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv4() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv4 not supported by OS");tybs_net_disableipv6();disable6 = TYBS_TRUE;break;case '6':if (disable6)ns_main_earlyfatal("cannot specify -4 and -6");if (tybs_net_probeipv6() != TYBS_R_SUCCESS)ns_main_earlyfatal("IPv6 not supported by OS");tybs_net_disableipv4();disable4 = TYBS_TRUE;break;case 'c':ns_g_conffile = tybs_commandline_argument;lwresd_g_conffile = tybs_commandline_argument;if (lwresd_g_useresolvconf)ns_main_earlyfatal("cannot specify -c and -C");ns_g_conffileset = TYBS_TRUE;break;case 'C':lwresd_g_resolvconffile = tybs_commandline_argument;if (ns_g_conffileset)ns_main_earlyfatal("cannot specify -c and -C");lwresd_g_useresolvconf = TYBS_TRUE;break;case 'd':ns_g_debuglevel = parse_int(tybs_commandline_argument,"debug level");break;case 'f':ns_g_foreground = TYBS_TRUE;break;case 'g':ns_g_foreground = TYBS_TRUE;ns_g_logstderr = TYBS_TRUE;break;/* XXXBEW -i should be removed */case 'i':lwresd_g_defaultpidfile = tybs_commandline_argument;break;case 'l':ns_g_lwresdonly = TYBS_TRUE;break;case 'm':set_flags(tybs_commandline_argument, mem_debug_flags, &tybs_mem_debugging);break;case 'N': /* Deprecated. */case 'n':ns_g_cpus = parse_int(tybs_commandline_argument,"number of cpus");if (ns_g_cpus == 0)ns_g_cpus = 1;break;case 'p':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);ns_g_port = port;break;/* XXXBEW Should -P be removed? */case 'P':port = parse_int(tybs_commandline_argument, "port");if (port < 1 || port > 65535)ns_main_earlyfatal("port '%s' out of range",tybs_commandline_argument);lwresd_g_listenport = port;break;case 's':want_stats = TYBS_TRUE;break;case 'S':maxsocks = parse_int(tybs_commandline_argument,"max number of sockets");break;case 't':ns_g_chrootdir = tybs_commandline_argument;break;case 'T':if (strcmp(tybs_commandline_argument, "clienttest") == 0) ns_g_clienttest = TYBS_TRUE;elsefprintf(stderr, "unknown -T flag '%s\n",tybs_commandline_argument);break;case 'u':ns_g_username = tybs_commandline_argument;break;case 'v':printf("BIND %s\n", ns_g_version);exit(0);case 'V':printf("BIND %s built with %s\n", ns_g_version,ns_g_configargs);exit(0);case '?':usage();if (tybs_commandline_option == '?')exit(0);ns_main_earlyfatal("unknown option '-%c'",tybs_commandline_option);default:ns_main_earlyfatal("parsing options returned %d", ch);}}argc -= tybs_commandline_index;argv += tybs_commandline_index;if (argc > 0) {usage();ns_main_earlyfatal("extra command line arguments");}}static tybs_result_tcreate_managers(void) {tybs_result_t result;unsigned int socks;#ifdef TYBS_PLATFORM_USETHREADSunsigned int cpus_detected;#endif#ifdef TYBS_PLATFORM_USETHREADScpus_detected = tybs_os_ncpus();if (ns_g_cpus == 0)ns_g_cpus = cpus_detected;tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER, TYBS_LOG_INFO, "found %u CPU%s, using %u worker thread%s",cpus_detected, cpus_detected == 1 ? "" : "s",ns_g_cpus, ns_g_cpus == 1 ? "" : "s");#elsens_g_cpus = 1;#endifresult = tybs_taskmgr_create(ns_g_mctx, ns_g_cpus, 0, &ns_g_taskmgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_taskmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_timermgr_create(ns_g_mctx, &ns_g_timermgr);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_timermgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_socketmgr_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_socketmgr_getmaxsockets(ns_g_socketmgr, &socks);if (result == TYBS_R_SUCCESS) {tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,TYBS_LOG_INFO, "using up to %u sockets", socks);}result = tybs_entropy_create(ns_g_mctx, &ns_g_entropy);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_entropy_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}result = tybs_hash_create(ns_g_mctx, ns_g_entropy, DNS_NAME_MAXWIRE);if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_hash_create() failed: %s",tybs_result_totext(result));return (TYBS_R_UNEXPECTED);}return (TYBS_R_SUCCESS);}static voiddestroy_managers(void) {ns_lwresd_shutdown();tybs_entropy_detach(&ns_g_entropy);if (ns_g_fallbackentropy != NULL)tybs_entropy_detach(&ns_g_fallbackentropy);tybs_taskmgr_destroy(&ns_g_taskmgr);tybs_timermgr_destroy(&ns_g_timermgr);tybs_socketmgr_destroy(&ns_g_socketmgr);tybs_hash_destroy();}static voidsetup(void) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifns_os_inituserinfo(ns_g_username);ns_os_tzset();ns_os_opendevnull();#ifdef HA VE_LIBSCFresult = ns_smf_get_instance(&instance, 0, ns_g_mctx);if (result == TYBS_R_SUCCESS)ns_smf_got_instance = 1;elsens_smf_got_instance = 0;if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);#endif /* HA VE_LIBSCF */#ifdef PA TH_RANDOMDEVif (ns_g_chrootdir != NULL) {result = tybs_entropy_create(ns_g_mctx, &ns_g_fallbackentropy);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_entropy_create() failed: %s",tybs_result_totext(result));result = tybs_entropy_createfilesource(ns_g_fallbackentropy,PA TH_RANDOMDEV);if (result != TYBS_R_SUCCESS) {ns_main_earlywarning("could not open pre-chroot ""entropy source %s: %s",PA TH_RANDOMDEV,tybs_result_totext(result));tybs_entropy_detach(&ns_g_fallbackentropy);}}#endifns_os_chroot(ns_g_chrootdir);ns_os_minprivs();result = ns_log_init(TYBS_TF(ns_g_username != NULL));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("ns_log_init() failed: %s",tybs_result_totext(result));if (!ns_g_foreground)ns_os_daemonize();result = tybs_app_start();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_app_start() failed: %s",tybs_result_totext(result));tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "starting BIND %s%s", ns_g_version,saved_command_line);tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "built with %s", ns_g_configargs);(void)tybs_resource_getlimit(tybs_resource_stacksize,&ns_g_initstacksize);(void)tybs_resource_getlimit(tybs_resource_datasize,&ns_g_initdatasize);(void)tybs_resource_getlimit(tybs_resource_coresize,&ns_g_initcoresize);(void)tybs_resource_getlimit(tybs_resource_openfiles,&ns_g_initopenfiles);if (! tybs_file_isabsolute(ns_g_conffile)) {result = tybs_file_absolutepath(ns_g_conffile,absolute_conffile,sizeof(absolute_conffile));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("could not construct absolute path of ""configuration file: %s",tybs_result_totext(result));ns_g_conffile = absolute_conffile;}result = tybs_time_now(&ns_g_boottime);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_time_now() failed: %s",tybs_result_totext(result));result = create_managers();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("create_managers() failed: %s",tybs_result_totext(result));ns_builtin_init();#ifdef DLZresult = dlz_drivers_init();if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("dlz_drivers_init() failed: %s",tybs_result_totext(result));#endifns_server_create(ns_g_mctx, &ns_g_server);}static voidcleanup(void) {destroy_managers();ns_server_destroy(&ns_g_server);ns_builtin_deinit();#ifdef DLZdlz_drivers_clear();#endifdns_name_destroy();tybs_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_MAIN, TYBS_LOG_NOTICE, "exiting");ns_log_shutdown();}static char *memstats = NULL;voidns_main_setmemstats(const char *filename) {if (memstats != NULL) {free(memstats);memstats = NULL;}if (filename == NULL)return;memstats = malloc(strlen(filename) + 1);if (memstats)strcpy(memstats, filename);}#ifdef HA VE_LIBSCFtybs_result_tns_smf_get_instance(char **ins_name, int debug, tybs_mem_t *mctx) { scf_handle_t *h = NULL;int namelen;char *instance;REQUIRE(ins_name != NULL && *ins_name == NULL);if ((h = scf_handle_create(SCF_VERSION)) == NULL) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_create() failed: %s",scf_strerror(scf_error()));return (TYBS_R_FAILURE);}if (scf_handle_bind(h) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_handle_bind() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((namelen = scf_myname(h, NULL, 0)) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if ((instance = tybs_mem_allocate(mctx, namelen + 1)) == NULL) { UNEXPECTED_ERROR(__FILE__, __LINE__,"ns_smf_get_instance memory ""allocation failed: %s",tybs_result_totext(TYBS_R_NOMEMORY));scf_handle_destroy(h);return (TYBS_R_FAILURE);}if (scf_myname(h, instance, namelen + 1) == -1) {if (debug)UNEXPECTED_ERROR(__FILE__, __LINE__,"scf_myname() failed: %s",scf_strerror(scf_error()));scf_handle_destroy(h);tybs_mem_free(mctx, instance);return (TYBS_R_FAILURE);}scf_handle_destroy(h);*ins_name = instance;return (TYBS_R_SUCCESS);}#endifintmain(int argc, char *argv[]) {tybs_result_t result;#ifdef HA VE_LIBSCFchar *instance = NULL;#endifstrlcat(version,#ifdef __DATE__"named version: BIND " VERSION " (" __DA TE__ ")",#else"named version: BIND " VERSION,#endifsizeof(version));result = tybs_file_progname(*argv, program_name, sizeof(program_name));if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("program name too long");if (strcmp(program_name, "lwresd") == 0)ns_g_lwresdonly = TYBS_TRUE;tybs_assertion_setcallback(assertion_failed);tybs_error_setfatal(library_fatal_error);tybs_error_setunexpected(library_unexpected_error);ns_os_init(program_name);dns_result_register();dst_result_register();tybscc_result_register();parse_command_line(argc, argv);if (ns_g_chrootdir != NULL) {int len = strlen(ns_g_chrootdir);if (strncmp(ns_g_chrootdir, ns_g_conffile, len) == 0 &&(ns_g_conffile[len] == '/' || ns_g_conffile[len] == '\\'))ns_main_earlywarning("config filename (-c %s) contains ""chroot path (-t %s)",ns_g_conffile, ns_g_chrootdir);}result = tybs_mem_create(0, 0, &ns_g_mctx);if (result != TYBS_R_SUCCESS)ns_main_earlyfatal("tybs_mem_create() failed: %s",tybs_result_totext(result));tybs_mem_setname(ns_g_mctx, "main", NULL);setup();do {result = tybs_app_run();if (result == TYBS_R_RELOAD) {ns_server_reloadwanted(ns_g_server);} else if (result != TYBS_R_SUCCESS) {UNEXPECTED_ERROR(__FILE__, __LINE__,"tybs_app_run(): %s",tybs_result_totext(result));result = TYBS_R_SUCCESS;}} while (result != TYBS_R_SUCCESS);#ifdef HA VE_LIBSCFif (ns_smf_want_disable == 1) {result = ns_smf_get_instance(&instance, 1, ns_g_mctx);if (result == TYBS_R_SUCCESS && instance != NULL) { if (smf_disable_instance(instance, 0) != 0)UNEXPECTED_ERROR(__FILE__, __LINE__,"smf_disable_instance() ""failed for %s : %s",instance,scf_strerror(scf_error()));}if (instance != NULL)tybs_mem_free(ns_g_mctx, instance);}#endif /* HA VE_LIBSCF */cleanup();if (want_stats) {tybs_mem_stats(ns_g_mctx, stdout);tybs_mutex_stats(stdout);}if (ns_g_memstatistics && memstats != NULL) {FILE *fp = NULL;result = tybs_stdio_open(memstats, "w", &fp);if (result == TYBS_R_SUCCESS) {tybs_mem_stats(ns_g_mctx, fp);tybs_mutex_stats(fp);tybs_stdio_close(fp);}}tybs_mem_destroy(&ns_g_mctx);tybs_mem_checkdestroyed(stderr);ns_main_setmemstats(NULL);tybs_app_finish();ns_os_closedevnull();ns_os_shutdown();return (0);}#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS#include "php.h"#include <stdio.h>#include <fcntl.h>#ifdef PHP_WIN32#include "win32/time.h"#include "win32/signal.h"#include "win32/php_win32_globals.h"#include <process.h>#elif defined(NETW ARE)#include <sys/timeval.h>#ifdef USE_WINSOCK#include <novsock2.h>#endif#endif#if HA VE_SYS_TIME_H#include <sys/time.h>#endif#if HA VE_UNISTD_H#include <unistd.h>#endif#if HA VE_SIGNAL_H#include <signal.h>#endif#if HA VE_SETLOCALE#include <locale.h>#endif#include "zend.h"#include "zend_extensions.h"#include "php_ini.h"#include "php_globals.h"#include "php_main.h"#include "fopen_wrappers.h"#include "ext/standard/php_standard.h" #include "php_variables.h"#include "ext/standard/credits.h"#ifdef PHP_WIN32#include <io.h>#include "win32/php_registry.h"#include "ext/standard/flock_compat.h" #endif#include "php_syslog.h"#include "Zend/zend_exceptions.h"#if PHP_SIGCHILD#include <sys/types.h>#include <sys/wait.h>#endif#include "zend_compile.h"#include "zend_execute.h"#include "zend_highlight.h"#include "zend_indent.h"#include "zend_extensions.h"#include "zend_ini.h"#include "php_content_types.h"#include "php_ticks.h"#include "php_logos.h"#include "php_streams.h"#include "php_open_temporary_file.h" #include "SAPI.h"#include "rfc1867.h"php_core_globals core_globals;#elsePHPAPI int core_globals_id;#endif#define SAFE_FILENAME(f) ((f)?(f):"-")/* {{{ PHP_INI_MH*/static PHP_INI_MH(OnSetPrecision){int i = atoi(new_value);if (i >= 0) {EG(precision) = i;return SUCCESS;} else {return FAILURE;}}static PHP_INI_MH(OnChangeMemoryLimit){if (new_value) {PG(memory_limit) = zend_atoi(new_value, new_value_length);} else {PG(memory_limit) = 1<<30; /* effectively, no limit */ }return zend_set_memory_limit(PG(memory_limit));}static void php_disable_functions(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_functions"))) {return;}e = PG(disable_functions) = strdup(INI_STR("disable_functions"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_function(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}if (s) {zend_disable_function(s, e-s TSRMLS_CC);}}static void php_disable_classes(TSRMLS_D){char *s = NULL, *e;if (!*(INI_STR("disable_classes"))) {return;}e = PG(disable_classes) = strdup(INI_STR("disable_classes"));while (*e) {switch (*e) {case ' ':case ',':if (s) {*e = '\0';zend_disable_class(s, e-s TSRMLS_CC);s = NULL;}break;default:if (!s) {s = e;}break;}e++;}if (s) {zend_disable_class(s, e-s TSRMLS_CC);}}static PHP_INI_MH(OnUpdateTimeout){EG(timeout_seconds) = atoi(new_value);if (stage==PHP_INI_STAGE_STARTUP) {/* Don't set a timeout on startup, only per-request */return SUCCESS;}zend_unset_timeout(TSRMLS_C);zend_set_timeout(EG(timeout_seconds));return SUCCESS;}static int php_get_display_errors_mode(char *value, int value_length) {int mode;if (!value) {return PHP_DISPLAY_ERRORS_STDOUT;}if (value_length == 2 && !strcasecmp("on", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 3 && !strcasecmp("yes", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 4 && !strcasecmp("true", value)) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else if (value_length == 6 && !strcasecmp(value, "stderr")) {mode = PHP_DISPLAY_ERRORS_STDERR;} else if (value_length == 6 && !strcasecmp(value, "stdout")) {mode = PHP_DISPLAY_ERRORS_STDOUT;} else {mode = atoi(value);if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {mode = PHP_DISPLAY_ERRORS_STDOUT;}}return mode;}static PHP_INI_MH(OnUpdateDisplayErrors){PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length);return SUCCESS;}static PHP_INI_DISP(display_errors_mode){int mode, tmp_value_length, cgi_or_cli;char *tmp_value;TSRMLS_FETCH();if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );tmp_value_length = ini_entry->orig_value_length;} else if (ini_entry->value) {tmp_value = ini_entry->value;tmp_value_length = ini_entry->value_length;} else {tmp_value = NULL;tmp_value_length = 0;}mode = php_get_display_errors_mode(tmp_value, tmp_value_length);cgi_or_cli = (!strcmp(sapi_, "cli") || !strcmp(sapi_, "cgi"));switch (mode) {case PHP_DISPLAY_ERRORS_STDERR:if (cgi_or_cli ) {PUTS("STDERR");} else {PUTS("On");。

相关文档
最新文档