• 关于 break-all 的搜索结果

回答

通过设置accs样式,参考如下css样式:width: 500rpx; display:-webkit-box; -webkit-line-clamp:1; overflow:hidden; text-overflow:ellipsis; -webkit-box-orient:vertical; word-break:break-all;

保持可爱mmm 2020-05-05 18:26:56 0 浏览量 回答数 0

回答

<h2 style="width:300px;width:300px;word-break:break-all;word-wrap:break-word">https://s3-us-west-1.amazonaws.com/web.noblehouse/41678</h2>

小旋风柴进 2019-12-02 02:11:11 0 浏览量 回答数 0

回答

,不是inline-block的原因。加两个属性 word-wrap: break-word; 和 word-break: break-all; 就可解决。

杨冬芳 2019-12-02 02:28:43 0 浏览量 回答数 0

试用中心

为您提供0门槛上云实践机会,企业用户最高免费12个月

回答

在div上面使用flex height: 200px; width: 200px; background-color: red; display: flex; justify-content: space-around; flex-direction: column; align-items: center; word-break: break-all;

杨冬芳 2019-12-02 02:43:43 0 浏览量 回答数 0

回答

word-break:break-all;word-wrap:break-word;

小旋风柴进 2019-12-02 02:37:42 0 浏览量 回答数 0

回答

容器增加css word-wrap: break-word; word-break:break-all;

小旋风柴进 2019-12-02 02:37:57 0 浏览量 回答数 0

回答

p { word-wrap: break-word;//自动换行 word-break: break-all;//英文单词断行 }

杨冬芳 2019-12-02 02:55:35 0 浏览量 回答数 0

回答

text-align:justify; text-justify:inter-ideograph;###### @我在堵城之巅 你的问题解决了吗? 我也遇到了这个问题######回复 @我在堵城之巅 : word-wrap: break-word; 删掉试试######试了呢 没有反应 安卓机真是让我醉了######p{    width: 96%;    color: #222;    line-height: 24px;    margin-bottom: 3%;    font-size: 16px;    font-family: "微软雅黑",SimSun,SimHei;    text-align: justify;    text-justify: distribute-all-lines;    word-wrap: break-word;    display: inline-block;    text-justify: kashida;    margin:0 5px 0 5px;    text-indent: 2em;    text-justify:inter-ideograph; } ######你这个解决了吗?我也是这个问题

kun坤 2020-06-04 11:07:06 0 浏览量 回答数 0

回答

解决办法:word-break:break-all;word-wrap:break-word;连续英文被当做一个单词了(阿拉伯数字也存在这种情况),而中文每个是独立的。换行依赖于单词边界。

a123456678 2019-12-02 02:23:13 0 浏览量 回答数 0

问题

网络分析

nicenelly 2019-12-01 20:56:33 1207 浏览量 回答数 0

回答

不设置行高也可以居中 <div style="height: 32px; background: lightblue; width: 100px; font-size: 12px; display: table-cell; vertical-align: middle; overflow:hidden; word-break: break-all;"> 1231111112 </div>

杨冬芳 2019-12-02 02:41:21 0 浏览量 回答数 0

问题

IE7下如何使用css解决pre标签内内容自动换行?

a123456678 2019-12-01 19:32:36 901 浏览量 回答数 1

回答

flag_item这个样式谁在用,看图也没看出来问题换行了啥意思啊,你发的图不就换行了吗想不换行,你可再试试下面几种方法display:inline-block; white-space:nowrap; word-break:break-all;

小旋风柴进 2019-12-02 02:05:58 0 浏览量 回答数 0

问题

统计分析(1)

nicenelly 2019-12-01 20:56:27 929 浏览量 回答数 0

回答

//源码文件 student_manage.c #include #include #include #define MAX_NAME_LEN 64 #define MAX_ID_LEN 16 #define MAX_STUDENT_NR 100 typedef struct student { char ID[MAX_ID_LEN]; char name[MAX_NAME_LEN]; } student_t; student_t g_student_array[MAX_STUDENT_NR]; int g_count = 0; void read_data(char * filename) { FILE *pFile = NULL; char *pstr = NULL; int count = 0; int i = 0; pFile = fopen(filename, "r"); if (!pFile) { perror("fopen"); goto l_out; } do { pstr = fgets(g_student_array[count].ID, MAX_ID_LEN, pFile); if (!pstr) { goto l_error; } pstr[strlen(pstr)-1] = '\0'; pstr = fgets(g_student_array[count].name, MAX_NAME_LEN, pFile); if (!pstr) { goto l_error; } pstr[strlen(pstr)-1] = '\0'; count++; } while (count < MAX_STUDENT_NR); l_error: if (!feof(pFile)) { perror("fgets"); } g_count = count; fclose(pFile); l_out: return; } int find_student_by_id(char *id) { int i; int rc = 0; for (i = 0; i < g_count; i++) { if (! strcmp(g_student_array[i].ID, id)) { printf("id:%s name:%s\n", g_student_array[i].ID, g_student_array[i].name); rc = 1; break; } } if (i == g_count) { printf("don't find student with id %s\n", id); } return rc; } void print_data() { int i; printf("All Student Info:\n"); for (i = 0; i < g_count; i++) { printf("id:%s name:%s\n", g_student_array[i].ID, g_student_array[i].name); } } int main(int argc, char **argv) { char * filename = "name.txt"; char * id = "Z0002"; printf("------------------------------------------------\n"); printf("Stage1, read data from file %s ...\n", filename); read_data("name.txt"); printf("------------------------------------------------\n"); printf("Stage2, print info ...\n"); print_data(); printf("------------------------------------------------\n"); printf("Stage3, find studnent with id(%s)\n", id); find_student_by_id(id); } //示例文件 name.txt Z0001 张三 Z0002 李四 Z0003 王五

a123456678 2019-12-02 02:17:08 0 浏览量 回答数 0

问题

将日期时间添加到列表中,而不重新排序日期和时间值

kun坤 2019-12-27 11:23:20 0 浏览量 回答数 1

问题

什么是特征工程?(1)

nicenelly 2019-12-01 22:09:08 1465 浏览量 回答数 0

问题

验证码图片与SESSION中的值不同步 - 服务报错

montos 2020-06-04 14:01:03 5 浏览量 回答数 1

问题

验证码图片与SESSION中的值不同步:报错 

kun坤 2020-06-04 21:16:03 4 浏览量 回答数 1

回答

word-break:break-all;

1199526811358522 2019-12-02 00:57:51 0 浏览量 回答数 0

回答

可以在 标签里加一个 ,对这个 进行限宽 <style> span { display: inline-block; width: 50px; white-space:nowrap; word-break:keep-all; overflow:hidden; text-overflow:ellipsis; } </style> <a><span>adfdasfasdfadfafadfafasf</span> ></a>

a123456678 2019-12-02 02:23:17 0 浏览量 回答数 0

回答

你发的这些东西看不出问题, 这只不过是设置SDL音频播放参数和回调接口而已. 得看看你是如何解码的, 有没有把解码出来的数据弄丢, 不然是不会有噪音的...######我把源码发上来了 你帮我看一下 拜托了######回复 @bruce_hou : 没看到你的代码, 我也不知道怎么回事.######具体怎么处理啊 能不能详细的说一下######我把源码发上来 #include "libavformat/avformat.h" #include "libswscale/swscale.h" #include <SDL/SDL.h> #include <SDL/SDL_thread.h> #ifdef main #undef main #endif #include <stdio.h> #include <math.h> #define SDL_AUDIO_BUFFER_SIZE 1024 #define MAX_AUDIOQ_SIZE (5 * 16 * 1024) #define MAX_VIDEOQ_SIZE (5 * 256 * 1024) #define AV_SYNC_THRESHOLD 0.01 #define AV_NOSYNC_THRESHOLD 10.0 #define FF_ALLOC_EVENT (SDL_USEREVENT) #define FF_REFRESH_EVENT (SDL_USEREVENT + 1) #define FF_QUIT_EVENT (SDL_USEREVENT + 2) #define VIDEO_PICTURE_QUEUE_SIZE 1 typedef struct PacketQueue { AVPacketList *first_pkt, *last_pkt; int nb_packets; int size; SDL_mutex *mutex; SDL_cond *cond; } PacketQueue; typedef struct VideoPicture { SDL_Overlay *bmp; int width, height; int allocated; double pts; } VideoPicture; typedef struct VideoState { AVFormatContext *pFormatCtx; int videoStream, audioStream; double audio_clock; AVStream *audio_st; PacketQueue audioq; uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2]; unsigned int audio_buf_size; unsigned int audio_buf_index; AVPacket audio_pkt; uint8_t *audio_pkt_data; int audio_pkt_size; int audio_hw_buf_size; double frame_timer; double frame_last_pts; double frame_last_delay; double video_clock; ///<pts of last decoded frame / predicted pts of next decoded frame AVStream *video_st; PacketQueue videoq; VideoPicture pictq[VIDEO_PICTURE_QUEUE_SIZE]; int pictq_size, pictq_rindex, pictq_windex; SDL_mutex *pictq_mutex; SDL_cond *pictq_cond; SDL_Thread *parse_tid; SDL_Thread *video_tid; char filename[1024]; int quit; } VideoState; SDL_Surface *screen; VideoState *global_video_state; void packet_queue_init(PacketQueue *q) { memset(q, 0, sizeof(PacketQueue)); q->mutex = SDL_CreateMutex(); q->cond = SDL_CreateCond(); } int packet_queue_put(PacketQueue *q, AVPacket *pkt) { AVPacketList *pkt1; if(av_dup_packet(pkt) < 0) { return -1; } pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList)); if (!pkt1) return -1; pkt1->pkt = *pkt; pkt1->next = NULL; SDL_LockMutex(q->mutex); if (!q->last_pkt) q->first_pkt = pkt1; else q->last_pkt->next = pkt1; q->last_pkt = pkt1; q->nb_packets++; q->size += pkt1->pkt.size; SDL_CondSignal(q->cond); SDL_UnlockMutex(q->mutex); return 0; } static int packet_queue_get(PacketQueue *q, AVPacket *pkt, int block) { AVPacketList *pkt1; int ret; SDL_LockMutex(q->mutex); for(;;) { if(global_video_state->quit) { ret = -1; break; } pkt1 = q->first_pkt; if (pkt1) { q->first_pkt = pkt1->next; if (!q->first_pkt) q->last_pkt = NULL; q->nb_packets--; q->size -= pkt1->pkt.size; *pkt = pkt1->pkt; av_free(pkt1); ret = 1; break; } else if (!block) { ret = 0; break; } else { SDL_CondWait(q->cond, q->mutex); } } SDL_UnlockMutex(q->mutex); return ret; } double get_audio_clock(VideoState *is) { double pts; int hw_buf_size, bytes_per_sec, n; pts = is->audio_clock; hw_buf_size = is->audio_buf_size - is->audio_buf_index; bytes_per_sec = 0; n = is->audio_st->codec->channels * 2; if(is->audio_st) { bytes_per_sec = is->audio_st->codec->sample_rate * n; } if(bytes_per_sec) { pts -= (double)hw_buf_size / bytes_per_sec; } return pts; } int audio_decode_frame(VideoState *is, uint8_t *audio_buf, int buf_size, double *pts_ptr) { int len1, data_size, n; AVPacket *pkt = &is->audio_pkt; double pts; for(;;) { while(is->audio_pkt_size > 0) { data_size = buf_size; len1 = avcodec_decode_audio2(is->audio_st->codec, (int16_t *)audio_buf, &data_size, is->audio_pkt_data, is->audio_pkt_size); if(len1 < 0) { is->audio_pkt_size = 0; break; } is->audio_pkt_data += len1; is->audio_pkt_size -= len1; if(data_size <= 0) { continue; } pts = is->audio_clock; *pts_ptr = pts; n = 2 * is->audio_st->codec->channels; is->audio_clock += (double)data_size / (double)(n * is->audio_st->codec->sample_rate); return data_size; } if(pkt->data) av_free_packet(pkt); if(is->quit) { return -1; } if(packet_queue_get(&is->audioq, pkt, 1) < 0) { return -1; } is->audio_pkt_data = pkt->data; is->audio_pkt_size = pkt->size; if(pkt->pts != AV_NOPTS_VALUE) { is->audio_clock = av_q2d(is->audio_st->time_base)*pkt->pts; } } } void audio_callback(void *userdata, Uint8 *stream, int len) { VideoState *is = (VideoState *)userdata; int len1, audio_size; double pts; while(len > 0) { if(is->audio_buf_index >= is->audio_buf_size) { audio_size = audio_decode_frame(is, is->audio_buf, sizeof(is->audio_buf), &pts); if(audio_size < 0) { is->audio_buf_size = 1024; memset(is->audio_buf, 0, is->audio_buf_size); } else { is->audio_buf_size = audio_size; } is->audio_buf_index = 0; } len1 = is->audio_buf_size - is->audio_buf_index; if(len1 > len) len1 = len; memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1); len -= len1; stream += len1; is->audio_buf_index += len1; } } static Uint32 sdl_refresh_timer_cb(Uint32 interval, void *opaque) { SDL_Event event; event.type = FF_REFRESH_EVENT; event.user.data1 = opaque; SDL_PushEvent(&event); return 0; } static void schedule_refresh(VideoState *is, int delay) { SDL_AddTimer(delay, sdl_refresh_timer_cb, is); } void video_display(VideoState *is) { SDL_Rect rect; VideoPicture *vp; AVPicture pict; float aspect_ratio; int w, h, x, y; int i; vp = &is->pictq[is->pictq_rindex]; if(vp->bmp) { if(is->video_st->codec->sample_aspect_ratio.num == 0) { aspect_ratio = 0; } else { aspect_ratio = av_q2d(is->video_st->codec->sample_aspect_ratio) * is->video_st->codec->width / is->video_st->codec->height; } if(aspect_ratio <= 0.0) { aspect_ratio = (float)is->video_st->codec->width / (float)is->video_st->codec->height; } h = screen->h; w = ((int)(h * aspect_ratio)) & -3; if(w > screen->w) { w = screen->w; h = ((int)(w / aspect_ratio)) & -3; } x = (screen->w - w) / 2; y = (screen->h - h) / 2; rect.x = x; rect.y = y; rect.w = w; rect.h = h; SDL_DisplayYUVOverlay(vp->bmp, &rect); } } void video_refresh_timer(void *userdata) { VideoState *is = (VideoState *)userdata; VideoPicture *vp; double actual_delay, delay, sync_threshold, ref_clock, diff; if(is->video_st) { if(is->pictq_size == 0) { schedule_refresh(is, 1); } else { vp = &is->pictq[is->pictq_rindex]; delay = vp->pts - is->frame_last_pts; if(delay <= 0 || delay >= 1.0) { delay = is->frame_last_delay; } is->frame_last_delay = delay; is->frame_last_pts = vp->pts; ref_clock = get_audio_clock(is); diff = vp->pts - ref_clock; sync_threshold = (delay > AV_SYNC_THRESHOLD) ? delay : AV_SYNC_THRESHOLD; if(fabs(diff) < AV_NOSYNC_THRESHOLD) { if(diff <= -sync_threshold) { delay = 0; } else if(diff >= sync_threshold) { delay = 2 * delay; } } is->frame_timer += delay; actual_delay = is->frame_timer - (av_gettime() / 1000000.0); if(actual_delay < 0.010) { actual_delay = 0.010; } schedule_refresh(is, (int)(actual_delay * 1000 + 0.5)); video_display(is); if(++is->pictq_rindex == VIDEO_PICTURE_QUEUE_SIZE) { is->pictq_rindex = 0; } SDL_LockMutex(is->pictq_mutex); is->pictq_size--; SDL_CondSignal(is->pictq_cond); SDL_UnlockMutex(is->pictq_mutex); } } else { schedule_refresh(is, 100); } } void alloc_picture(void *userdata) { VideoState *is = (VideoState *)userdata; VideoPicture *vp; vp = &is->pictq[is->pictq_windex]; if(vp->bmp) { // we already have one make another, bigger/smaller SDL_FreeYUVOverlay(vp->bmp); } // Allocate a place to put our YUV image on that screen vp->bmp = SDL_CreateYUVOverlay(is->video_st->codec->width, is->video_st->codec->height, SDL_YV12_OVERLAY, screen); vp->width = is->video_st->codec->width; vp->height = is->video_st->codec->height; SDL_LockMutex(is->pictq_mutex); vp->allocated = 1; SDL_CondSignal(is->pictq_cond); SDL_UnlockMutex(is->pictq_mutex); } int queue_picture(VideoState *is, AVFrame *pFrame, double pts) { VideoPicture *vp; //int dst_pix_fmt; AVPicture pict; SDL_LockMutex(is->pictq_mutex); while(is->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE && !is->quit) { SDL_CondWait(is->pictq_cond, is->pictq_mutex); } SDL_UnlockMutex(is->pictq_mutex); if(is->quit) return -1; // windex is set to 0 initially vp = &is->pictq[is->pictq_windex]; if(!vp->bmp || vp->width != is->video_st->codec->width || vp->height != is->video_st->codec->height) { SDL_Event event; vp->allocated = 0; event.type = FF_ALLOC_EVENT; event.user.data1 = is; SDL_PushEvent(&event); SDL_LockMutex(is->pictq_mutex); while(!vp->allocated && !is->quit) { SDL_CondWait(is->pictq_cond, is->pictq_mutex); } SDL_UnlockMutex(is->pictq_mutex); if(is->quit) { return -1; } } static struct SwsContext *img_convert_ctx; if (img_convert_ctx == NULL) { img_convert_ctx = sws_getContext(is->video_st->codec->width, is->video_st->codec->height, is->video_st->codec->pix_fmt, is->video_st->codec->width, is->video_st->codec->height, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL); if (img_convert_ctx == NULL) { fprintf(stderr, "Cannot initialize the conversion context\n"); exit(1); } } if(vp->bmp) { SDL_LockYUVOverlay(vp->bmp); //dst_pix_fmt = PIX_FMT_YUV420P; pict.data[0] = vp->bmp->pixels[0]; pict.data[1] = vp->bmp->pixels[2]; pict.data[2] = vp->bmp->pixels[1]; pict.linesize[0] = vp->bmp->pitches[0]; pict.linesize[1] = vp->bmp->pitches[2]; pict.linesize[2] = vp->bmp->pitches[1]; // Convert the image into YUV format that SDL uses sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, is->video_st->codec->height, pict.data, pict.linesize); SDL_UnlockYUVOverlay(vp->bmp); vp->pts = pts; if(++is->pictq_windex == VIDEO_PICTURE_QUEUE_SIZE) { is->pictq_windex = 0; } SDL_LockMutex(is->pictq_mutex); is->pictq_size++; SDL_UnlockMutex(is->pictq_mutex); } return 0; } double synchronize_video(VideoState *is, AVFrame *src_frame, double pts) { double frame_delay; if(pts != 0) { is->video_clock = pts; } else { pts = is->video_clock; } frame_delay = av_q2d(is->video_st->codec->time_base); frame_delay += src_frame->repeat_pict * (frame_delay * 0.5); is->video_clock += frame_delay; return pts; } uint64_t global_video_pkt_pts = AV_NOPTS_VALUE; int our_get_buffer(struct AVCodecContext *c, AVFrame *pic) { int ret = avcodec_default_get_buffer(c, pic); uint64_t *pts = (uint64_t *)av_malloc(sizeof(uint64_t)); *pts = global_video_pkt_pts; pic->opaque = pts; return ret; } void our_release_buffer(struct AVCodecContext *c, AVFrame *pic) { if(pic) av_freep(&pic->opaque); avcodec_default_release_buffer(c, pic); } int video_thread(void *arg) { VideoState *is = (VideoState *)arg; AVPacket pkt1, *packet = &pkt1; int len1, frameFinished; AVFrame *pFrame; double pts; pFrame = avcodec_alloc_frame(); for(;;) { if(packet_queue_get(&is->videoq, packet, 1) < 0) { // means we quit getting packets break; } pts = 0; // Save global pts to be stored in pFrame in first call global_video_pkt_pts = packet->pts; // Decode video frame len1 = avcodec_decode_video(is->video_st->codec, pFrame, &frameFinished, packet->data, packet->size); if(packet->dts == AV_NOPTS_VALUE && pFrame->opaque && *(uint64_t*)pFrame->opaque != AV_NOPTS_VALUE) { pts = *(uint64_t *)pFrame->opaque; } else if(packet->dts != AV_NOPTS_VALUE) { pts = packet->dts; } else { pts = 0; } pts *= av_q2d(is->video_st->time_base); // Did we get a video frame? if(frameFinished) { pts = synchronize_video(is, pFrame, pts); if(queue_picture(is, pFrame, pts) < 0) { break; } } av_free_packet(packet); } av_free(pFrame); return 0; } int stream_component_open(VideoState *is, int stream_index) { AVFormatContext *pFormatCtx = is->pFormatCtx; AVCodecContext *codecCtx; AVCodec *codec; SDL_AudioSpec wanted_spec, spec; if(stream_index < 0 || stream_index >= pFormatCtx->nb_streams) { return -1; } // Get a pointer to the codec context for the video stream codecCtx = pFormatCtx->streams[stream_index]->codec; if(codecCtx->codec_type == CODEC_TYPE_AUDIO) { // Set audio settings from codec info wanted_spec.freq = codecCtx->sample_rate; wanted_spec.format = AUDIO_S16SYS; wanted_spec.channels = codecCtx->channels; wanted_spec.silence = 0; wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE; wanted_spec.callback = audio_callback; wanted_spec.userdata = is; if(SDL_OpenAudio(&wanted_spec, &spec) < 0) { fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError()); return -1; } is->audio_hw_buf_size = spec.size; } codec = avcodec_find_decoder(codecCtx->codec_id); if(!codec || (avcodec_open(codecCtx, codec) < 0)) { fprintf(stderr, "Unsupported codec!\n"); return -1; } switch(codecCtx->codec_type) { case CODEC_TYPE_AUDIO: is->audioStream = stream_index; is->audio_st = pFormatCtx->streams[stream_index]; is->audio_buf_size = 0; is->audio_buf_index = 0; memset(&is->audio_pkt, 0, sizeof(is->audio_pkt)); packet_queue_init(&is->audioq); SDL_PauseAudio(0); break; case CODEC_TYPE_VIDEO: is->videoStream = stream_index; is->video_st = pFormatCtx->streams[stream_index]; is->frame_timer = (double)av_gettime() / 1000000.0; is->frame_last_delay = 40e-3; packet_queue_init(&is->videoq); is->video_tid = SDL_CreateThread(video_thread, is); codecCtx->get_buffer = our_get_buffer; codecCtx->release_buffer = our_release_buffer; break; default: break; } return 0; } int decode_interrupt_cb(void) { return (global_video_state && global_video_state->quit); } int decode_thread(void *arg) { VideoState *is = (VideoState *)arg; AVFormatContext *pFormatCtx; AVPacket pkt1, *packet = &pkt1; int video_index = -1; int audio_index = -1; int i; is->videoStream=-1; is->audioStream=-1; global_video_state = is; // will interrupt blocking functions if we quit! url_set_interrupt_cb(decode_interrupt_cb); // Open video file if(av_open_input_file(&pFormatCtx, is->filename, NULL, 0, NULL)!=0) return -1; // Couldn't open file is->pFormatCtx = pFormatCtx; // Retrieve stream information if(av_find_stream_info(pFormatCtx)<0) return -1; // Couldn't find stream information // Dump information about file onto standard error dump_format(pFormatCtx, 0, is->filename, 0); // Find the first video stream for(i=0; i<pFormatCtx->nb_streams; i++) { if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO && video_index < 0) { video_index=i; } if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_AUDIO && audio_index < 0) { audio_index=i; } } if(audio_index >= 0) { stream_component_open(is, audio_index); } if(video_index >= 0) { stream_component_open(is, video_index); } if(is->videoStream < 0 || is->audioStream < 0) { fprintf(stderr, "%s: could not open codecs\n", is->filename); goto fail; } // main decode loop for(;;) { if(is->quit) { break; } // seek stuff goes here if(is->audioq.size > MAX_AUDIOQ_SIZE || is->videoq.size > MAX_VIDEOQ_SIZE) { SDL_Delay(10); continue; } if(av_read_frame(is->pFormatCtx, packet) < 0) { if(url_ferror(pFormatCtx->pb) == 0) { SDL_Delay(100); continue; } else { break; } } // Is this a packet from the video stream? if(packet->stream_index == is->videoStream) { packet_queue_put(&is->videoq, packet); } else if(packet->stream_index == is->audioStream) { packet_queue_put(&is->audioq, packet); } else { av_free_packet(packet); } } while(!is->quit) { SDL_Delay(100); } fail: { SDL_Event event; event.type = FF_QUIT_EVENT; event.user.data1 = is; SDL_PushEvent(&event); } return 0; } int main(int argc, char *argv[]) { SDL_Event event; VideoState *is; is = (VideoState *)av_mallocz(sizeof(VideoState)); if(argc < 2) { fprintf(stderr, "Usage: test <file>\n"); exit(1); } // Register all formats and codecs av_register_all(); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); exit(1); } // Make a screen to put our video #ifndef __DARWIN__ screen = SDL_SetVideoMode(640, 480, 0, 0); #else screen = SDL_SetVideoMode(640, 480, 24, 0); #endif if(!screen) { fprintf(stderr, "SDL: could not set video mode - exiting\n"); exit(1); } //pstrcpy(is->filename, sizeof(is->filename), argv[1]); strcpy(is->filename,argv[1]); is->pictq_mutex = SDL_CreateMutex(); is->pictq_cond = SDL_CreateCond(); schedule_refresh(is, 40); is->parse_tid = SDL_CreateThread(decode_thread, is); if(!is->parse_tid) { av_free(is); return -1; } for(;;) { SDL_WaitEvent(&event); switch(event.type) { case FF_QUIT_EVENT: case SDL_QUIT: is->quit = 1; SDL_Quit(); exit(0); break; case FF_ALLOC_EVENT: alloc_picture(event.user.data1); break; case FF_REFRESH_EVENT: video_refresh_timer(event.user.data1); break; default: break; } } return 0; } 你帮我看一下######你有没有最新的ffmpeg转码示范代码啊######回复 @Jack.arain : 给我一个示范代码好不,这上面的代码是一个示范代码,我把 avcodec_decode_audio3,######看了下代码, 不知道你用的是哪个版本的ffmpeg, 但你这个代码是非常老的了, 另外, 在ffmpeg后期的版本中, avcodec_decode_audio函数可能解码出来的数据要比实际的数据要长, 需要使用av_samples_get_buffer_size来获得实际大小.###### C++我不懂,不过音视频解码的内核我写过不少。如果内核解别的不出错,那么噪音基本来源于输出的音频PCM的BUF不干净或者输入的频段信息有缺失,某个通道没有数据进入。前者你的输出BUF可能被别的代码(包括解码本身)写操作过。你查下有没有内存泄露的问题。后者,是你的输入不全的问题。更大概率是后者。前者要定期加入噪音的概率还是比较小。 这类问题的检测方法是外围做最简单的调用。验证调用方法和内核模块都没有问题。然后再堆叠其他系统模块上去。 ######的确是旧的代码,现在新的都用上了avcodec_decode_audio4了,你的ffmpeg库是什么版本的,新的版本有libswresample,可以帮你的音频做重采样,这样播放出来就不会有噪声了,如果想看事例代码,就看你的ffmpeg源码里的ffplay.c吧,里面的接口都和你的ffmpeg对应的,看看人家是怎么处理音频的,希望对你有用。

爱吃鱼的程序员 2020-06-05 13:33:51 0 浏览量 回答数 0

问题

css截取标题固定长度

a123456678 2019-12-01 19:29:37 989 浏览量 回答数 1

问题

怎么让文字对齐图片的下边缘

a123456678 2019-12-01 19:29:46 843 浏览量 回答数 1

回答

Re关于PHPsdk中的listobject函数问题 如果楼主出错了,可以将错误码贴出来,看看OSS返回的错误信息,是不是有帮助。 感觉在递归遍历的时候,每次100个,20W需要递归2000次。 我看循环处理可能更好些。下面是一个python的伪代码,楼主凑合看吧。 例如:     prefix = “”     marker = ""     delimiter = ''     maxkeys = '1000' 每次拿一千个     all_object_list = []     while 1:         res = oss.get_bucket(bucket, prefix, marker, delimiter, maxkeys) //每次拿一千个         if res.status != 200: //不是200表示出错             return res         body = res.read()         (tmp_object_list, marker) = get_object_list_marker_from_xml(body) // 从返回的Body中解析出object list和next marker,并将next marker的值返给maker         all_object_list.extend(tmp_object_list)         if len(marker) == 0: //如果marker为空,表示停止循环             break //从body中解析出object list和next marker def get_object_list_marker_from_xml(body):     object_meta_list = []     next_marker = ""     hh = GetBucketXml(body) //解析body中的xml得到一个结构体,结构体中有object list,有next marker,也有是否结束的标志。都在xml中     object_meta_list = ParseToGetObjectList(hh)     if hh.is_truncated: //表明list bucket的结果没有结束,还有object         next_marker = hh.nextmarker //获得下一次的marker     return (object_meta_list, next_marker) ------------------------- 回楼主堕落了信仰的帖子 在OSS中实际只有object的概念,并没有目录的概念,所以拿到所有的object list就可以直接操作了。

wood23 2019-12-02 02:36:54 0 浏览量 回答数 0

回答

Nginx是一个轻量级的,高性能的Web服务器以及反向代理和邮箱 (IMAP/POP3)代理服务器。它运行在UNIX,GNU /linux,BSD 各种版本,Mac OS X,Solaris和Windows。根据调查统计,6%的网站使用Nginx Web服务器。Nginx是少数能处理C10K问题的服务器之一。跟传统的服务器不同,Nginx不依赖线程来处理请求。相反,它使用了更多的可扩展的事 件驱动(异步)架构。Nginx为一些高流量的网站提供动力,比如WordPress,人人网,腾讯,网易等。这篇文章主要是介绍如何提高运行在 Linux或UNIX系统的Nginx Web服务器的安全性。 默认配置文件和Nginx端口 /usr/local/nginx/conf/ – Nginx配置文件目录,/usr/local/nginx/conf/nginx.conf是主配置文件 /usr/local/nginx/html/ – 默认网站文件位置 /usr/local/nginx/logs/ – 默认日志文件位置 Nginx HTTP默认端口 : TCP 80 Nginx HTTPS默认端口: TCP 443 你可以使用以下命令来测试Nginx配置文件准确性。 /usr/local/nginx/sbin/nginx -t 将会输出: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful 执行以下命令来重新加载配置文件。 /usr/local/nginx/sbin/nginx -s reload 执行以下命令来停止服务器。 /usr/local/nginx/sbin/nginx -s stop 一、配置SELinux 注意:对于云服务器 ECS,参阅 ECS 使用须知 ,基于兼容性、稳定性考虑,请勿开启 SELinux。 安全增强型 Linux(SELinux)是一个Linux内核的功能,它提供支持访问控制的安全政策保护机制。它可以防御大部分攻击。下面我们来看如何启动基于centos/RHEL系统的SELinux。 安装SELinux rpm -qa | grep selinux libselinux-1.23.10-2 selinux-policy-targeted-1.23.16-6 如果没有返回任何结果,代表没有安装 SELinux,如果返回了类似上面的结果,则说明系统安装了 SELinux。 布什值锁定 运行命令getsebool -a来锁定系统。 getsebool -a | less getsebool -a | grep off getsebool -a | grep o 二、通过分区挂载允许最少特权 服务器上的网页/html/php文件单独分区。例如,新建一个分区/dev/sda5(第一逻辑分区),并且挂载在/nginx。确保 /nginx是以noexec, nodev and nosetuid的权限挂载。以下是我的/etc/fstab的挂载/nginx的信息: LABEL=/nginx /nginx ext3 defaults,nosuid,noexec,nodev 1 2 注意:你需要使用fdisk和mkfs.ext3命令创建一个新分区。 三、配置/etc/sysctl.conf强化Linux安全 你可以通过编辑/etc/sysctl.conf来控制和配置Linux内核、网络设置。 Avoid a smurf attack net.ipv4.icmp_echo_ignore_broadcasts = 1 Turn on protection for bad icmp error messages net.ipv4.icmp_ignore_bogus_error_responses = 1 Turn on syncookies for SYN flood attack protection net.ipv4.tcp_syncookies = 1 Turn on and log spoofed, source routed, and redirect packets net.ipv4.conf.all.log_martians = 1 net.ipv4.conf.default.log_martians = 1 No source routed packets here net.ipv4.conf.all.accept_source_route = 0 net.ipv4.conf.default.accept_source_route = 0 Turn on reverse path filtering net.ipv4.conf.all.rp_filter = 1 net.ipv4.conf.default.rp_filter = 1 Make sure no one can alter the routing tables net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv4.conf.all.secure_redirects = 0 net.ipv4.conf.default.secure_redirects = 0 Don’t act as a router net.ipv4.ip_forward = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects = 0 Turn on execshild kernel.exec-shield = 1 kernel.randomize_va_space = 1 Tuen IPv6 net.ipv6.conf.default.router_solicitations = 0 net.ipv6.conf.default.accept_ra_rtr_pref = 0 net.ipv6.conf.default.accept_ra_pinfo = 0 net.ipv6.conf.default.accept_ra_defrtr = 0 net.ipv6.conf.default.autoconf = 0 net.ipv6.conf.default.dad_transmits = 0 net.ipv6.conf.default.max_addresses = 1 Optimization for port usefor LBs Increase system file descriptor limit fs.file-max = 65535 Allow for more PIDs (to reduce rollover problems); may break some programs 32768 kernel.pid_max = 65536 Increase system IP port limits net.ipv4.ip_local_port_range = 2000 65000 Increase TCP max buffer size setable using setsockopt() net.ipv4.tcp_rmem = 4096 87380 8388608 net.ipv4.tcp_wmem = 4096 87380 8388608 Increase Linux auto tuning TCP buffer limits min, default, and max number of bytes to use set max to at least 4MB, or higher if you use very high BDP paths Tcp Windows etc net.core.rmem_max = 8388608 net.core.wmem_max = 8388608 net.core.netdev_max_backlog = 5000 net.ipv4.tcp_window_scaling = 1 四、删除所有不需要的Nginx模块 你需要直接通过编译Nginx源代码使模块数量最少化。通过限制只允许web服务器访问模块把风险降到最低。你可以只配置安装nginx你所需要的模块。例如,禁用SSL和autoindex模块你可以执行以下命令: ./configure –without-http_autoindex_module –without-http_ssi_module make make install 通过以下命令来查看当编译nginx服务器时哪个模块能开户或关闭: ./configure –help | less 禁用你用不到的nginx模块。 (可选项)更改nginx版本名称。 编辑文件/http/ngx_http_header_filter_module.c: vi +48 src/http/ngx_http_header_filter_module.c 找到行: static char ngx_http_server_string[] = “Server: nginx” CRLF; static char ngx_http_server_full_string[] = “Server: ” NGINX_VER CRLF; 按照以下行修改: static char ngx_http_server_string[] = “Server: Ninja Web Server” CRLF; static char ngx_http_server_full_string[] = “Server: Ninja Web Server” CRLF; 保存并关闭文件。现在你可以编辑服务器了。增加以下代码到nginx.conf文件来关闭nginx版本号的显示。 server_tokens off 五、使用mod_security(只适合后端Apache服务器) mod_security为Apache提供一个应用程序级的防火墙。为后端Apache Web服务器安装mod_security,这会阻止很多注入式攻击。 六、安装SELinux策略以强化Nginx Web服务器 默认的SELinux不会保护Nginx Web服务器,但是你可以安装和编译保护软件。 1、安装编译SELinux所需环境支持 yum -y install selinux-policy-targeted selinux-policy-devel 2、下载SELinux策略以强化Nginx Web服务器。 cd /opt wget ‘http://downloads.sourceforge.net/project/selinuxnginx/se-ngix_1_0_10.tar.gz?use_mirror=nchc’ 3、解压文件 tar -zxvf se-ngix_1_0_10.tar.gz 4、编译文件 cd se-ngix_1_0_10/nginx make 将会输出如下: Compiling targeted nginx module /usr/bin/checkmodule: loading policy configuration from tmp/nginx.tmp /usr/bin/checkmodule: policy configuration loaded /usr/bin/checkmodule: writing binary representation (version 6) to tmp/nginx.mod Creating targeted nginx.pp policy package rm tmp/nginx.mod.fc tmp/nginx.mod 5、安装生成的nginx.pp SELinux模块: /usr/sbin/semodule -i nginx.pp 七、基于Iptables防火墙的限制 下面的防火墙脚本阻止任何除了允许: 来自HTTP(TCP端口80)的请求 来自ICMP ping的请求 ntp(端口123)的请求输出 smtp(TCP端口25)的请求输出 #!/bin/bash IPT=”/sbin/iptables” IPS Get server public ip SERVER_IP=$(ifconfig eth0 | grep ‘inet addr:’ | awk -F’inet addr:’ ‘{ print $2}’ | awk ‘{ print $1}’) LB1_IP=”204.54.1.1″ LB2_IP=”204.54.1.2″ Do some smart logic so that we can use damm script on LB2 too OTHER_LB=”" SERVER_IP=”" [[ "$SERVER_IP" == "$LB1_IP" ]] && OTHER_LB=”$LB2_IP” || OTHER_LB=”$LB1_IP” [[ "$OTHER_LB" == "$LB2_IP" ]] && OPP_LB=”$LB1_IP” || OPP_LB=”$LB2_IP” IPs PUB_SSH_ONLY=”122.xx.yy.zz/29″ FILES BLOCKED_IP_TDB=/root/.fw/blocked.ip.txt SPOOFIP=”127.0.0.0/8 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 169.254.0.0/16 0.0.0.0/8 240.0.0.0/4 255.255.255.255/32 168.254.0.0/16 224.0.0.0/4 240.0.0.0/5 248.0.0.0/5 192.0.2.0/24″ BADIPS=$( [[ -f ${BLOCKED_IP_TDB} ]] && egrep -v “^#|^$” ${BLOCKED_IP_TDB}) Interfaces PUB_IF=”eth0″ # public interface LO_IF=”lo” # loopback VPN_IF=”eth1″ # vpn / private net start firewall echo “Setting LB1 $(hostname) Firewall…” DROP and close everything $IPT -P INPUT DROP $IPT -P OUTPUT DROP $IPT -P FORWARD DROP Unlimited lo access $IPT -A INPUT -i ${LO_IF} -j ACCEPT $IPT -A OUTPUT -o ${LO_IF} -j ACCEPT Unlimited vpn / pnet access $IPT -A INPUT -i ${VPN_IF} -j ACCEPT $IPT -A OUTPUT -o ${VPN_IF} -j ACCEPT Drop sync $IPT -A INPUT -i ${PUB_IF} -p tcp ! –syn -m state –state NEW -j DROP Drop Fragments $IPT -A INPUT -i ${PUB_IF} -f -j DROP $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags ALL FIN,URG,PSH -j DROP $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags ALL ALL -j DROP Drop NULL packets $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags ALL NONE -m limit –limit 5/m –limit-burst 7 -j LOG –log-prefix ” NULL Packets “ $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags ALL NONE -j DROP $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags SYN,RST SYN,RST -j DROP Drop XMAS $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags SYN,FIN SYN,FIN -m limit –limit 5/m –limit-burst 7 -j LOG –log-prefix ” XMAS Packets “ $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags SYN,FIN SYN,FIN -j DROP Drop FIN packet scans $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags FIN,ACK FIN -m limit –limit 5/m –limit-burst 7 -j LOG –log-prefix ” Fin Packets Scan “ $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags FIN,ACK FIN -j DROP $IPT -A INPUT -i ${PUB_IF} -p tcp –tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP Log and get rid of broadcast / multicast and invalid $IPT -A INPUT -i ${PUB_IF} -m pkttype –pkt-type broadcast -j LOG –log-prefix ” Broadcast “ $IPT -A INPUT -i ${PUB_IF} -m pkttype –pkt-type broadcast -j DROP $IPT -A INPUT -i ${PUB_IF} -m pkttype –pkt-type multicast -j LOG –log-prefix ” Multicast “ $IPT -A INPUT -i ${PUB_IF} -m pkttype –pkt-type multicast -j DROP $IPT -A INPUT -i ${PUB_IF} -m state –state INVALID -j LOG –log-prefix ” Invalid “ $IPT -A INPUT -i ${PUB_IF} -m state –state INVALID -j DROP Log and block spoofed ips $IPT -N spooflist for ipblock in $SPOOFIP do $IPT -A spooflist -i ${PUB_IF} -s $ipblock -j LOG –log-prefix ” SPOOF List Block “ $IPT -A spooflist -i ${PUB_IF} -s $ipblock -j DROP done $IPT -I INPUT -j spooflist $IPT -I OUTPUT -j spooflist $IPT -I FORWARD -j spooflist Allow ssh only from selected public ips for ip in ${PUB_SSH_ONLY} do $IPT -A INPUT -i ${PUB_IF} -s ${ip} -p tcp -d ${SERVER_IP} –destination-port 22 -j ACCEPT $IPT -A OUTPUT -o ${PUB_IF} -d ${ip} -p tcp -s ${SERVER_IP} –sport 22 -j ACCEPT done allow incoming ICMP ping pong stuff $IPT -A INPUT -i ${PUB_IF} -p icmp –icmp-type 8 -s 0/0 -m state –state NEW,ESTABLISHED,RELATED -m limit –limit 30/sec -j ACCEPT $IPT -A OUTPUT -o ${PUB_IF} -p icmp –icmp-type 0 -d 0/0 -m state –state ESTABLISHED,RELATED -j ACCEPT allow incoming HTTP port 80 $IPT -A INPUT -i ${PUB_IF} -p tcp -s 0/0 –sport 1024:65535 –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT $IPT -A OUTPUT -o ${PUB_IF} -p tcp –sport 80 -d 0/0 –dport 1024:65535 -m state –state ESTABLISHED -j ACCEPT allow outgoing ntp $IPT -A OUTPUT -o ${PUB_IF} -p udp –dport 123 -m state –state NEW,ESTABLISHED -j ACCEPT $IPT -A INPUT -i ${PUB_IF} -p udp –sport 123 -m state –state ESTABLISHED -j ACCEPT allow outgoing smtp $IPT -A OUTPUT -o ${PUB_IF} -p tcp –dport 25 -m state –state NEW,ESTABLISHED -j ACCEPT $IPT -A INPUT -i ${PUB_IF} -p tcp –sport 25 -m state –state ESTABLISHED -j ACCEPT add your other rules here ####################### drop and log everything else $IPT -A INPUT -m limit –limit 5/m –limit-burst 7 -j LOG –log-prefix ” DEFAULT DROP “ $IPT -A INPUT -j DROP exit 0 八、控制缓冲区溢出攻击 编辑nginx.conf,为所有客户端设置缓冲区的大小限制。 vi /usr/local/nginx/conf/nginx.conf 编辑和设置所有客户端缓冲区的大小限制如下: Start: Size Limits & Buffer Overflows client_body_buffer_size 1K; client_header_buffer_size 1k; client_max_body_size 1k; large_client_header_buffers 2 1k; END: Size Limits & Buffer Overflows 解释: 1、client_body_buffer_size 1k-(默认8k或16k)这个指令可以指定连接请求实体的缓冲区大小。如果连接请求超过缓存区指定的值,那么这些请求实体的整体或部分将尝试写入一个临时文件。 2、client_header_buffer_size 1k-指令指定客户端请求头部的缓冲区大小。绝大多数情况下一个请求头不会大于1k,不过如果有来自于wap客户端的较大的cookie它可能会大于 1k,Nginx将分配给它一个更大的缓冲区,这个值可以在large_client_header_buffers里面设置。 3、client_max_body_size 1k-指令指定允许客户端连接的最大请求实体大小,它出现在请求头部的Content-Length字段。 如果请求大于指定的值,客户端将收到一个”Request Entity Too Large” (413)错误。记住,浏览器并不知道怎样显示这个错误。 4、large_client_header_buffers-指定客户端一些比较大的请求头使用的缓冲区数量和大小。请求字段不能大于一个缓冲区大小,如果客户端发送一个比较大的头,nginx将返回”Request URI too large” (414) 同样,请求的头部最长字段不能大于一个缓冲区,否则服务器将返回”Bad request” (400)。缓冲区只在需求时分开。默认一个缓冲区大小为操作系统中分页文件大小,通常是4k或8k,如果一个连接请求最终将状态转换为keep- alive,它所占用的缓冲区将被释放。 你还需要控制超时来提高服务器性能并与客户端断开连接。按照如下编辑: Start: Timeouts client_body_timeout 10; client_header_timeout 10; keepalive_timeout 5 5; send_timeout 10; End: Timeouts 1、client_body_timeout 10;-指令指定读取请求实体的超时时间。这里的超时是指一个请求实体没有进入读取步骤,如果连接超过这个时间而客户端没有任何响应,Nginx将返回一个”Request time out” (408)错误。 2、client_header_timeout 10;-指令指定读取客户端请求头标题的超时时间。这里的超时是指一个请求头没有进入读取步骤,如果连接超过这个时间而客户端没有任何响应,Nginx将返回一个”Request time out” (408)错误。 3、keepalive_timeout 5 5; – 参数的第一个值指定了客户端与服务器长连接的超时时间,超过这个时间,服务器将关闭连接。参数的第二个值(可选)指定了应答头中Keep-Alive: timeout=time的time值,这个值可以使一些浏览器知道什么时候关闭连接,以便服务器不用重复关闭,如果不指定这个参数,nginx不会在应 答头中发送Keep-Alive信息。(但这并不是指怎样将一个连接“Keep-Alive”)参数的这两个值可以不相同。 4、send_timeout 10; 指令指定了发送给客户端应答后的超时时间,Timeout是指没有进入完整established状态,只完成了两次握手,如果超过这个时间客户端没有任何响应,nginx将关闭连接。 九、控制并发连接 你可以使用NginxHttpLimitZone模块来限制指定的会话或者一个IP地址的特殊情况下的并发连接。编辑nginx.conf: Directive describes the zone, in which the session states are stored i.e. store in slimits. 1m can handle 32000 sessions with 32 bytes/session, set to 5m x 32000 session limit_zone slimits $binary_remote_addr 5m; Control maximum number of simultaneous connections for one session i.e. restricts the amount of connections from a single ip address limit_conn slimits 5; 上面表示限制每个远程IP地址的客户端同时打开连接不能超过5个。 十、只允许我们的域名的访问 如果机器人只是随机扫描服务器的所有域名,那拒绝这个请求。你必须允许配置的虚拟域或反向代理请求。你不必使用IP地址来拒绝。 Only requests to our Host are allowed i.e. nixcraft.in, images.nixcraft.in and www.nixcraft.in if ($host !~ ^(nixcraft.in|www.nixcraft.in|images.nixcraft.in)$ ) { return 444; } 十一、限制可用的请求方法 GET和POST是互联网上最常用的方法。 Web服务器的方法被定义在RFC 2616。如果Web服务器不要求启用所有可用的方法,它们应该被禁用。下面的指令将过滤只允许GET,HEAD和POST方法: Only allow these request methods if ($request_method !~ ^(GET|HEAD|POST)$ ) { return 444; } Do not accept DELETE, SEARCH and other methods 更多关于HTTP方法的介绍 GET方法是用来请求,如文件http://www.moqifei.com/index.php。 HEAD方法是一样的,除非该服务器的GET请求无法返回消息体。 POST方法可能涉及到很多东西,如储存或更新数据,或订购产品,或通过提交表单发送电子邮件。这通常是使用服务器端处理,如PHP,Perl和Python等脚本。如果你要上传的文件和在服务器处理数据,你必须使用这个方法。 十二、如何拒绝一些User-Agents? 你可以很容易地阻止User-Agents,如扫描器,机器人以及滥用你服务器的垃圾邮件发送者。 Block download agents if ($http_user_agent ~* LWP::Simple|BBBike|wget) { return 403; } 阻止Soso和有道的机器人: Block some robots if ($http_user_agent ~* Sosospider|YodaoBot) { return 403; } 十三、如何防止图片盗链 图片或HTML盗链的意思是有人直接用你网站的图片地址来显示在他的网站上。最终的结果,你需要支付额外的宽带费用。这通常是在论坛和博客。我强烈建议您封锁,并阻止盗链行为。 Stop deep linking or hot linking location /images/ { valid_referers none blocked www.example.com example.com; if ($invalid_referer) { return 403; } } 例如:重定向并显示指定图片 valid_referers blocked www.example.com example.com; if ($invalid_referer) { rewrite ^/images/uploads.*.(gif|jpg|jpeg|png)$ http://www.examples.com/banned.jpg last } 十四、目录限制 你可以对指定的目录设置访问权限。所有的网站目录应该一一的配置,只允许必须的目录访问权限。 通过IP地址限制访问 你可以通过IP地址来限制访问目录/admin/: location /docs/ { block one workstation deny 192.168.1.1; allow anyone in 192.168.1.0/24 allow 192.168.1.0/24; drop rest of the world deny all; } 通过密码保护目录 首先创建密码文件并增加“user”用户: mkdir /usr/local/nginx/conf/.htpasswd/ htpasswd -c /usr/local/nginx/conf/.htpasswd/passwd user 编辑nginx.conf,加入需要保护的目录: Password Protect /personal-images/ and /delta/ directories location ~ /(personal-images/.|delta/.) { auth_basic “Restricted”; auth_basic_user_file /usr/local/nginx/conf/.htpasswd/passwd; } 一旦密码文件已经生成,你也可以用以下的命令来增加允许访问的用户: htpasswd -s /usr/local/nginx/conf/.htpasswd/passwd userName 十五、Nginx SSL配置 HTTP是一个纯文本协议,它是开放的被动监测。你应该使用SSL来加密你的用户内容。 创建SSL证书 执行以下命令: cd /usr/local/nginx/conf openssl genrsa -des3 -out server.key 1024 openssl req -new -key server.key -out server.csr cp server.key server.key.org openssl rsa -in server.key.org -out server.key openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt 编辑nginx.conf并按如下来更新: server { server_name example.com; listen 443; ssl on; ssl_certificate /usr/local/nginx/conf/server.crt; ssl_certificate_key /usr/local/nginx/conf/server.key; access_log /usr/local/nginx/logs/ssl.access.log; error_log /usr/local/nginx/logs/ssl.error.log; } 重启nginx: /usr/local/nginx/sbin/nginx -s reload 十六、Nginx与PHP安全建议 PHP是流行的服务器端脚本语言之一。如下编辑/etc/php.ini文件: Disallow dangerous functions disable_functions = phpinfo, system, mail, exec Try to limit resources Maximum execution time of each script, in seconds max_execution_time = 30 Maximum amount of time each script may spend parsing request data max_input_time = 60 Maximum amount of memory a script may consume (8MB) memory_limit = 8M Maximum size of POST data that PHP will accept. post_max_size = 8M Whether to allow HTTP file uploads. file_uploads = Off Maximum allowed size for uploaded files. upload_max_filesize = 2M Do not expose PHP error messages to external users display_errors = Off Turn on safe mode safe_mode = On Only allow access to executables in isolated directory safe_mode_exec_dir = php-required-executables-path Limit external access to PHP environment safemode_allowed_env_vars = PHP Restrict PHP information leakage expose_php = Off Log all errors log_errors = On Do not register globals for input data register_globals = Off Minimize allowable PHP post size post_max_size = 1K Ensure PHP redirects appropriately cgi.force_redirect = 0 Disallow uploading unless necessary file_uploads = Off Enable SQL safe mode sql.safe_mode = On Avoid Opening remote files allow_url_fopen = Off 十七、如果可能让Nginx运行在一个chroot监狱 把nginx放在一个chroot监狱以减小潜在的非法进入其它目录。你可以使用传统的与nginx一起安装的chroot。如果可能,那使用FreeBSD jails,Xen,OpenVZ虚拟化的容器概念。 十八、在防火墙级限制每个IP的连接数 网络服务器必须监视连接和每秒连接限制。PF和Iptales都能够在进入你的nginx服务器之前阻止最终用户的访问。 Linux Iptables:限制每次Nginx连接数 下面的例子会阻止来自一个IP的60秒钟内超过15个连接端口80的连接数。 /sbin/iptables -A INPUT -p tcp –dport 80 -i eth0 -m state –state NEW -m recent –set /sbin/iptables -A INPUT -p tcp –dport 80 -i eth0 -m state –state NEW -m recent –update –seconds 60 –hitcount 15 -j DROP service iptables save 请根据你的具体情况来设置限制的连接数。 十九:配置操作系统保护Web服务器 像以上介绍的启动SELinux.正确设置/nginx文档根目录的权限。Nginx以用户nginx运行。但是根目录(/nginx或者/usr /local/nginx/html)不应该设置属于用户nginx或对用户nginx可写。找出错误权限的文件可以使用如下命令: find /nginx -user nginx find /usr/local/nginx/html -user nginx 确保你更所有权为root或其它用户,一个典型的权限设置 /usr/local/nginx/html/ ls -l /usr/local/nginx/html/ 示例输出: -rw-r–r– 1 root root 925 Jan 3 00:50 error4xx.html -rw-r–r– 1 root root 52 Jan 3 10:00 error5xx.html -rw-r–r– 1 root root 134 Jan 3 00:52 index.html 你必须删除由vi或其它文本编辑器创建的备份文件: find /nginx -name ‘.?’ -not -name .ht -or -name ‘~’ -or -name ‘.bak’ -or -name ‘.old*’ find /usr/local/nginx/html/ -name ‘.?’ -not -name .ht -or -name ‘~’ -or -name ‘.bak’ -or -name ‘.old*’ 通过find命令的-delete选项来删除这些文件。 二十、限制Nginx连接传出 黑客会使用工具如wget下载你服务器本地的文件。使用Iptables从nginx用户来阻止传出连接。ipt_owner模块试图匹配本地产生的数据包的创建者。下面的例子中只允许user用户在外面使用80连接。 /sbin/iptables -A OUTPUT -o eth0 -m owner –uid-owner vivek -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT 通过以上的配置,你的nginx服务器已经非常安全了并可以发布网页。可是,你还应该根据你网站程序查找更多的安全设置资料。例如,wordpress或者第三方程序。

KB小秘书 2019-12-02 02:06:56 0 浏览量 回答数 0

回答

找到答案了,还是wiki给力阿。 atime updates are by far the biggest IO performance deficiency that Linux has today. Getting rid of atime updates would give us more everyday Linux performance than all the pagecache speedups of the past 10 years, _combined_. As of 2.6.30 (9 June 2009), Linux defaults to relatime,[3] so that it will not update atime on all file reads. The behavior offers sufficient performance for most purposes and should not break any significant applications. Extended discussion of filesystem performance preceded the decision.[4] Indeed, relatime by default was the first patch Linux applied following the 2.6.29 release. In initial patches relatime only updated atime if atime < mtime or atime < ctime;######经实验,正确。和光标移动无关(之前是恰好修改文件后进行了光标移动)######atime是最近访问时间。。。。顾名思义。。。你cat一下它就会变了。。。。。######cat 后,access time没有改变。###### 引用来自“$_$”的答案 atime是最近访问时间。。。。顾名思义。。。你cat一下它就会变了。。。。。 你的机器上是变的吗? 这是我的结果: chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ stat AUTHORS   File: `AUTHORS'   Size: 365           Blocks: 8          IO Block: 4096   regular file Device: 803h/2051d    Inode: 9439976     Links: 1 Access: (0664/-rw-rw-r--)  Uid: ( 1000/  chenqi)   Gid: ( 1000/  chenqi) Access: 2012-08-29 18:57:35.430069290 +0800 Modify: 2012-08-29 18:57:35.354069292 +0800 Change: 2012-08-29 18:57:35.354069292 +0800  Birth: - chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ cat AUTHORS Tim Ansell <mithro@mithis.net> Phil Blundell <pb@handhelds.org> Seb Frankengul <seb@frankengul.org> Holger Freyther <holger@moiji-mobile.com> Marcin Juszkiewicz <marcin@juszkiewicz.com.pl> Chris Larson <kergoth@handhelds.org> Ulrich Luckas <luckas@musoft.de> Mickey Lauer <mickey@Vanille.de> Richard Purdie <rpurdie@rpsys.net> Holger Schurig <holgerschurig@gmx.de> chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ stat AUTHORS   File: `AUTHORS'   Size: 365           Blocks: 8          IO Block: 4096   regular file Device: 803h/2051d    Inode: 9439976     Links: 1 Access: (0664/-rw-rw-r--)  Uid: ( 1000/  chenqi)   Gid: ( 1000/  chenqi) Access: 2012-08-29 18:57:35.430069290 +0800 Modify: 2012-08-29 18:57:35.354069292 +0800 Change: 2012-08-29 18:57:35.354069292 +0800  Birth: - chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ date Wed Aug 29 19:04:17 CST 2012 chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ ###### 引用来自“ChenQi”的答案 引用来自“$_$”的答案 atime是最近访问时间。。。。顾名思义。。。你cat一下它就会变了。。。。。 你的机器上是变的吗? 这是我的结果: chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ stat AUTHORS   File: `AUTHORS'   Size: 365           Blocks: 8          IO Block: 4096   regular file Device: 803h/2051d    Inode: 9439976     Links: 1 Access: (0664/-rw-rw-r--)  Uid: ( 1000/  chenqi)   Gid: ( 1000/  chenqi) Access: 2012-08-29 18:57:35.430069290 +0800 Modify: 2012-08-29 18:57:35.354069292 +0800 Change: 2012-08-29 18:57:35.354069292 +0800  Birth: - chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ cat AUTHORS Tim Ansell <mithro@mithis.net> Phil Blundell <pb@handhelds.org> Seb Frankengul <seb@frankengul.org> Holger Freyther <holger@moiji-mobile.com> Marcin Juszkiewicz <marcin@juszkiewicz.com.pl> Chris Larson <kergoth@handhelds.org> Ulrich Luckas <luckas@musoft.de> Mickey Lauer <mickey@Vanille.de> Richard Purdie <rpurdie@rpsys.net> Holger Schurig <holgerschurig@gmx.de> chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ stat AUTHORS   File: `AUTHORS'   Size: 365           Blocks: 8          IO Block: 4096   regular file Device: 803h/2051d    Inode: 9439976     Links: 1 Access: (0664/-rw-rw-r--)  Uid: ( 1000/  chenqi)   Gid: ( 1000/  chenqi) Access: 2012-08-29 18:57:35.430069290 +0800 Modify: 2012-08-29 18:57:35.354069292 +0800 Change: 2012-08-29 18:57:35.354069292 +0800  Birth: - chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ date Wed Aug 29 19:04:17 CST 2012 chenqi@chenqi-OptiPlex-760:~/poky/bitbake$ 我的是变的 Jiang@local ~/tmp/test $ stat test   文件:"test"   大小:0         块:0          IO 块:4096   普通空文件 设备:11h/17d Inode:268877      硬链接:1 权限:(0644/-rw-r--r--)  Uid:( 1000/      Jiang)   Gid:( 1000/      Jiang) 最近访问:2012-08-29 19:06:22.200085281 +0800 最近更改:2012-08-29 19:06:22.200085281 +0800 最近改动:2012-08-29 19:06:22.200085281 +0800 创建时间:- Jiang@local ~/tmp/test $ cat test  Jiang@local ~/tmp/test $ stat test   文件:"test"   大小:0         块:0          IO 块:4096   普通空文件 设备:11h/17d Inode:268877      硬链接:1 权限:(0644/-rw-r--r--)  Uid:( 1000/      Jiang)   Gid:( 1000/      Jiang) 最近访问:2012-08-29 19:06:51.364086914 +0800 最近更改:2012-08-29 19:06:22.200085281 +0800 最近改动:2012-08-29 19:06:22.200085281 +0800 Jiang@local ~/tmp/test $ echo hello > test Jiang@local ~/tmp/test $ stat test   文件:"test"   大小:6         块:8          IO 块:4096   普通文件 设备:11h/17d Inode:268877      硬链接:1 权限:(0644/-rw-r--r--)  Uid:( 1000/      Jiang)   Gid:( 1000/      Jiang) 最近访问:2012-08-29 19:06:51.364086914 +0800 最近更改:2012-08-29 19:08:02.916090921 +0800 最近改动:2012-08-29 19:08:02.916090921 +0800 创建时间:- Jiang@local ~/tmp/test $ !cat cat test  hello Jiang@local ~/tmp/test $ stat test   文件:"test"   大小:6         块:8          IO 块:4096   普通文件 设备:11h/17d Inode:268877      硬链接:1 权限:(0644/-rw-r--r--)  Uid:( 1000/      Jiang)   Gid:( 1000/      Jiang) 最近访问:2012-08-29 19:08:28.600092359 +0800 最近更改:2012-08-29 19:08:02.916090921 +0800 最近改动:2012-08-29 19:08:02.916090921 +0800 创建时间:- ######你看,你的access time也不是很准确阿。当你echo hello > test后,test的access time没有改变。

kun坤 2020-06-06 16:58:38 0 浏览量 回答数 0

回答

目前,Ray支持部分引用计数。(完整的参考计数将很快发布)。简而言之,当传递给远程函数的object_id未序列化时,引用引用的计数方式与引用Python的计数方式相同。这意味着,如果result_transformed是由Python收集的垃圾,result_transformed则应取消固定血浆存储中的,并在将对象清除为LRU时将其清除。(为清楚起见,不会清除具有某些引用计数的固定对象)。 我还假设存在一些奇怪的引用计数,例如循环引用。result_transformed运行该脚本时,我可以验证它是否被驱逐了。因此,我认为result_transformed本身不是问题。可能存在许多问题。就我而言,我发现当我将ipython用作输入(IN)时,它会创建对python对象的引用。(例如,当您看到某个对象的值时,OUT [number]可以引用您的对象)。 In [2]: import psutil ...: import gc ...: import ray ...: from time import sleep ...: import numpy as np ...: @ray.remote ...: def calc_similarity(sims, offset): ...: # Fake some work for 100 ms. ...: sleep(0.10) ...: return True ...: ...: if __name__ == "__main__": ...: # Initialize RAY to use all of the processors. ...: num_cpus = psutil.cpu_count(logical=False) ...: ray.init(num_cpus=num_cpus) ...: ...: num_docs = 1000000 ...: num_dimensions = 300 ...: chunk_size = 128 ...: sim_pct = 0.82 ...: ...: # Initialize the array ...: index = np.random.random((num_docs, num_dimensions)).astype(dtype=np.float32) ...: index_array = np.arange(num_docs).reshape(1, num_docs) ...: index_array_id = ray.put(index_array) ...: ...: calc_results = [] ...: i = 0 ...: for count, start_doc_no in enumerate(range(0, num_docs, chunk_size)): ...: i += 1 ...: size = min( chunk_size, num_docs - (start_doc_no) + 1 ) ...: # Get the query vector out of the index. ...: query_vector = index[start_doc_no:start_doc_no+size] ...: # Calculate the matrix multiplication. ...: result_transformed = np.matmul(index, query_vector.T).T ...: # Serialize the result matrix out for each client. ...: result_id = ray.put(result_transformed) ...: if i == 1: ...: # The first result_id binary number should be stored in result_id_special ...: # In this way, we can verify if this object id is evicted after filling up our ...: # plasma store by some random numpy array ...: # If this object id is not evicted, that means it is pinned, meaning if is ...: # not properly reference counted. ...: first_object_id = result_id.binary() ...: # Simulate multi-threading extracting the results of a cosine similarity calculation ...: for offset in range(chunk_size): ...: calc_results.append(calc_similarity.remote(sims=result_id, offset=offset )) ...: # , index_array=index_array_id)) ...: res = ray.get(calc_results) ...: calc_results.clear() ...: print('ref count to result_id {}'.format(len(gc.get_referrers(result_id)))) ...: print('Total number of ref counts in a ray cluster. {}'.format(ray.worker.global_worker.core_worker.get_all_reference_counts())) ...: if i == 5: ...: break ...: # It should contain the object id of the ...: print('first object id: {}'.format(first_object_id)) ...: print('fill up plasma store by big numpy arrays. This should evict the first_object_id from the plasma store.') ...: print('because if the data_transformed is garbage collected properly, it should be unpinned from plasma store') ...: print('and when plasma store is filled by numpy array, first_object_id should be evicted.') ...: for _ in range(40): ...: import numpy as np ...: ray.put(np.zeros(500 * 1024 * 1024, dtype=np.uint8)) ...: print('total ref count from a ray cluster after eviction: {}'.format(ray.worker.global_worker.core_worker.get_all_reference_counts())) ...: # this should fail as first_object_id is already evicted ...: print(ray.get(ray.ObjectID(first_object_id))) [ray] Forcing OMP_NUM_THREADS=1 to avoid performance degradation with many workers (issue #6998). You can override this by explicitly setting OMP_NUM_THREADS. 2020-02-12 00:10:11,932 INFO resource_spec.py:212 -- Starting Ray with 4.35 GiB memory available for workers and up to 2.19 GiB for objects. You can adjust these settings with ray.init(memory=<bytes>, object_store_memory=<bytes>). 2020-02-12 00:10:12,273 INFO services.py:1080 -- View the Ray dashboard at localhost:8265 2020-02-12 00:10:18,522 WARNING worker.py:289 -- OMP_NUM_THREADS=1 is set, this may slow down ray.put() for large objects (issue #6998). ref count to result_id 1 Total number of ref counts in a ray cluster. {ObjectID(ffffffffffffffffffffffff0100008002000000): {'local': 1, 'submitted': 0}, ObjectID(ffffffffffffffffffffffff0100008001000000): {'local': 1, 'submitted': 0}} ref count to result_id 1 Total number of ref counts in a ray cluster. {ObjectID(ffffffffffffffffffffffff0100008003000000): {'local': 1, 'submitted': 0}, ObjectID(ffffffffffffffffffffffff0100008001000000): {'local': 1, 'submitted': 0}} ref count to result_id 1 Total number of ref counts in a ray cluster. {ObjectID(ffffffffffffffffffffffff0100008001000000): {'local': 1, 'submitted': 0}, ObjectID(ffffffffffffffffffffffff0100008004000000): {'local': 1, 'submitted': 0}} ref count to result_id 1 Total number of ref counts in a ray cluster. {ObjectID(ffffffffffffffffffffffff0100008001000000): {'local': 1, 'submitted': 0}, ObjectID(ffffffffffffffffffffffff0100008005000000): {'local': 1, 'submitted': 0}} ref count to result_id 1 Total number of ref counts in a ray cluster. {ObjectID(ffffffffffffffffffffffff0100008006000000): {'local': 1, 'submitted': 0}, ObjectID(ffffffffffffffffffffffff0100008001000000): {'local': 1, 'submitted': 0}} first object id: b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01\x00\x00\x80\x02\x00\x00\x00' fill up plasma store by big numpy arrays. This should evict the first_object_id from the plasma store. because if the data_transformed is garbage collected properly, it should be unpinned from plasma store and when plasma store is filled by numpy array, first_object_id should be evicted. total ref count from a ray cluster after eviction: {ObjectID(ffffffffffffffffffffffff0100008006000000): {'local': 1, 'submitted': 0}, ObjectID(ffffffffffffffffffffffff0100008001000000): {'local': 1, 'submitted': 0}} 2020-02-12 00:10:57,108 WARNING worker.py:1515 -- Local object store memory usage: num clients with quota: 0 quota map size: 0 pinned quota map size: 0 allocated bytes: 2092865189 allocation limit: 2347285708 pinned bytes: 520000477 (global lru) capacity: 2347285708 (global lru) used: 67.0078% (global lru) num objects: 4 (global lru) num evictions: 41 (global lru) bytes evicted: 21446665725 2020-02-12 00:10:57,112 WARNING worker.py:1072 -- The task with ID ffffffffffffffffffffffff0100 is a driver task and so the object created by ray.put could not be reconstructed. --------------------------------------------------------------------------- UnreconstructableError Traceback (most recent call last) <ipython-input-1-184e5836123c> in <module> 63 print('total ref count from a ray cluster after eviction: {}'.format(ray.worker.global_worker.core_worker.get_all_reference_counts())) 64 # this should fail as first_object_id is already evicted ---> 65 print(ray.get(ray.ObjectID(first_object_id))) 66 ~/work/ray/python/ray/worker.py in get(object_ids, timeout) 1517 raise value.as_instanceof_cause() 1518 else: -> 1519 raise value 1520 1521 # Run post processors. UnreconstructableError: Object ffffffffffffffffffffffff0100008002000000 is lost (either LRU evicted or deleted by user) and cannot be reconstructed. Try increasing the object store memory available with ray.init(object_store_memory=<bytes>) or setting object store limits with ray.remote(object_store_memory=<bytes>). See also: https://ray.readthedocs.io/en/latest/memory-management.html

祖安文状元 2020-02-22 10:27:48 0 浏览量 回答数 0

回答

你要算法,从程序中归纳就行了 我想到一种方法,可是有点复杂,要用到树的结构,先给你看个程序,是计算n个元素进栈,可能的出栈系列种数 /*递归求n个元素进栈,可能的出栈系列种数*/ #define N 4 int m=0,a=0,b=N;/*m表示种数,a表示栈中元素个数,b表示外面还有需要进栈的个数*/ main() { inS(a,b);/*首先入栈*/ printf("%d",m); getch(); } int inS(int a,int b)/*入栈*/ { a++;b--;/*入栈栈中元素+1,栈外元素-1 */ if(b>0)/*若栈外有元素,可以入栈*/ inS(a,b); if(a>0)/*若栈中有元素,可以出栈*/ outS(a,b); } int outS(int a,int b)/*出栈*/ { a--;/*出栈栈中元素-1*/ if(a==0&&b==0)/*若栈中元素和栈外元素都为0个*/ { m++;/*则此种情况的序列满足条件,种数+1*/ return; } if(b>0) inS(a,b); if(a>0) outS(a,b); } 若想输出这些序列,可以建立一个二叉树,二叉树的节点为操作(进栈或出栈),从根节点(第一个入栈)到叶子节点(最后一个出栈)的路径就是每个序列的操作序列,每条路径共有2N个节点,分别为每个元素的入栈和出栈操作,然后通过遍历,将这些节点输出即可 建立这棵树可以用上面的递归建立,也可以用下面的方法建立 ①建立一颗深度为2N的满二叉树(根节点深度为1),其中根节点为IN(入栈),其他左子树为IN,右子树为OUT(出栈),这棵树共有2^(2N-1)个叶子节点,用根节点到叶子节点共有2^(2N-1)条路径 ②保留满足下面条件的路径,其他的剔除 1)路径从根到叶出现IN和OUT总次数均为N个 2)路径从根到叶出现 IN次数≥OUT次数(即出栈次数不可能多余入栈次数) 然后输出保留的每条路径上节点类型为OUT的数据,即是出栈序列 剔除方法可由下面方法实现 1根节点赋值为1, 2节点为IN,则此节点赋值为父节点的值+1,节点为OUT,则此节点赋值为父节点的值-1, 3剔除节点的值为负数,或值>N的节点,或叶子节点上的值不=0的路径,剩下的就是满足条件的路径 ------------------------------------------------- 我想到一种方法,可以不用树的结构,只是模拟树,先贴程序 /*从1到N的顺序入栈,输出所有出栈序列*/ #include "math.h" #define N 4 main() { void init(int h[][],int a,int b,int k); int i,j,sum,logo,h[1000][2*N+1],s[N],a,b,n; int M=pow(2,2*N-1);/*共M条路径,每条有2*N个节点*/ /*h[i][]为第i条路径的操作序列,其中h[i][0]为一个标志,标志此序列是否满足条件,是则为1,否为0;从h[1]到h[2*N]为操作序列,1表示入栈,-1表示出栈*/ n=M;/*n为成功的序列计数*/ /*初始化标志和第一个操作,因为第一个操作必定为入栈操作*/ for(i=0;i<M;i++) { h[i][0]=1;/*1表示可以,0表示不可以*/ h[i][1]=1; }/*1表示可以,0表示不可以*/ init(h,0,M-1,2);/*开始初始化第二个操作,不管是否满足条件的序列,都存入数组h中*/ /*剔除不符合要求的序列*/ j=0;/*从第0组至第M组依次检验*/ while(j<M) { logo=0; sum=0;/*计算从h[][1]开始序列的和值*/ for(i=1;i<=2*N;i++) { sum+=h[j][i]; if(sum>N||sum<0)/*若出现入栈次数大于N,或出栈次数多于入栈次数*/ { logo=1; break;/*此序列埠满足条件*/ } } if(logo==1||sum!=0)/*sum和值表示入栈总数减出栈总数,若不为0,即入栈总数不等于出栈总数,则此序列不满足条件*/ { h[j][0]=0;/*当前序列的标志为0,表示不满足条件*/ n--;/*总序列总数-1*/ } j++; } /*输出各序列的出栈序列,s[]是临时模拟栈的,其中变量a表示栈顶(将要插入元素的位置,即栈顶元素的下一位置),b表示将要入栈的元素*/ for(j=0;j<M;j++) { if(h[j][0]==1)/*若序列标志为1*/ { a=0;b=1; for(i=1;i<=2*N;i++) { if(h[j][i]==1&&b<=N)/*若序列操作为1(入栈)*/ { s[a]=b;a++;b++;/*则入栈*/ } if(h[j][i]==-1)/*若序列操作为1(出栈)*/ { printf("%d",s[a-1]);/*输出出栈的元素*/ a--;/*则入栈*/ } } printf("\n"); } } printf("ALL %d !",n);/*所有序列数*/ getch(); } /*递归初始化*/ /*从a到b前一半赋值为1,后一半赋值为-1,由此可得所有的序列*/ /*每步操作(从2到2*N步)都可以任意的为入栈,出栈,然后剔除不满足条件的序列(不满足条件包括栈中没有元素还出栈,或入栈总数超过要出栈的个数,或入栈数与出栈数步相等),剔除的程序段在主函数中*/ void init(int h[1000][2*N+1],int a,int b,int k) { int i,p=a+(b-a)/2; if(k<=2*N) { for(i=a;i<=p;i++) h[i][k]=1; for(i=p+1;i<=b;i++) h[i][k]=-1; init(h,a,p,k+1); init(h,p+1,b,k+1); } }

琴瑟 2019-12-02 01:25:13 0 浏览量 回答数 0

回答

SHA 家族 SHA (Secure Hash Algorithm,译作安全散列算法) 是美国国家安全局 (NSA) 设计,美国国家标准与技术研究院 (NIST) 发布的一系列密码散列函数。正式名称为 SHA 的家族第一个成员发布于 1993年。然而现在的人们给它取了一个非正式的名称 SHA-0 以避免与它的后继者混淆。两年之后, SHA-1,第一个 SHA 的后继者发布了。 另外还有四种变体,曾经发布以提升输出的范围和变更一些细微设计: SHA-224, SHA-256, SHA-384 和 SHA-512 (这些有时候也被称做 SHA-2)。 SHA-0 和 SHA-1 最初载明的算法于 1993年发布,称做安全散列标准 (Secure Hash Standard),FIPS PUB 180。这个版本现在常被称为 "SHA-0"。它在发布之后很快就被 NSA 撤回,并且以 1995年发布的修订版本 FIPS PUB 180-1 (通常称为 "SHA-1") 取代。根据 NSA 的说法,它修正了一个在原始算法中会降低密码安全性的错误。然而 NSA 并没有提供任何进一步的解释或证明该错误已被修正。1998年,在一次对 SHA-0 的攻击中发现这次攻击并不能适用于 SHA-1 — 我们不知道这是否就是 NSA 所发现的错误,但这或许暗示我们这次修正已经提升了安全性。SHA-1 已经被公众密码社群做了非常严密的检验而还没发现到有不安全的地方,它现在被认为是安全的。 SHA-0 和 SHA-1 会从一个最大 2^64 位元的讯息中产生一串 160 位元的摘要然后以设计 MD4 及 MD5 讯息摘要算法的 MIT 教授 Ronald L. Rivest 类似的原理为基础来加密。 SHA-0 的密码分析 在 CRYPTO 98 上,两位法国研究者展示了一次对 SHA-0 的攻击 (Chabaud and Joux, 1998): 散列碰撞可以复杂到 2^61 时被发现;小于 2^80 是理想的相同大小散列函数。 2004年时,Biham 和 Chen 发现了 SHA-0 的近似碰撞 — 两个讯息可以散列出相同的数值;在这种情况之下,142 和 160 位元是一样的。他们也发现了 SHA-0 在 80 次之后减少到 62 位元的完整碰撞。 2004年8月12日,Joux, Carribault, Lemuet 和 Jalby 宣布了完整 SHA-0 算法的散列碰撞。这是归纳 Chabaud 和 Joux 的攻击所完成的结果。发现这个碰撞要复杂到 2^51, 并且用一台有 256 颗 Itanium2 处理器的超级电脑耗时大约 80,000 CPU 工作时 。 2004年8月17日,在 CRYPTO 2004 的 Rump 会议上,Wang, Feng, Lai, 和 Yu 宣布了攻击 MD5、SHA-0 和其他散列函数的初步结果。他们对 SHA-0 攻击复杂到 2^40,这意味着他们攻击的成果比 Joux 还有其他人所做的更好。该次 Rump 会议的简短摘要可以在 这里找到,而他们在 sci.crypt 的讨论,例如: 这些结果建议计划使用 SHA-1 作为新的密码系统的人需要重新考虑。 更长的变种 NIST 发布了三个额外的 SHA 变体,每个都有更长的讯息摘要。以它们的摘要长度 (以位元计算) 加在原名后面来命名:"SHA-256", "SHA-384" 和 "SHA-512"。它们发布于 2001年的 FIPS PUB 180-2 草稿中,随即通过审查和评论。包含 SHA-1 的 FIPS PUB 180-2,于 2002年以官方标准发布。这些新的散列函数并没有接受像 SHA-1 一样的公众密码社群做详细的检验,所以它们的密码安全性还不被大家广泛的信任。2004年2月,发布了一次 FIPS PUB 180-2 的变更通知,加入了一个额外的变种 "SHA-224",定义了符合双金钥 3DES 所需的金钥长度。 Gilbert 和 Handschuh (2003) 研究了新的变种并且没有发现弱点。 SHAd SHAd 函数是一个简单的相同 SHA 函数的重述: SHAd-256(m)=SHA-256(SHA-256(m))。它会克服有关延伸长度攻击的问题。 应用 SHA-1, SHA-224, SHA-256, SHA-384 和 SHA-512 都被需要安全散列算法的美国联邦政府所应用,他们也使用其他的密码算法和协定来保护敏感的未保密资料。FIPS PUB 180-1 也鼓励私人或商业组织使用 SHA-1 加密。Fritz-chip 将很可能使用 SHA-1 散列函数来实现个人电脑上的数位版权管理。 首先推动安全散列算法出版的是已合并的数位签章标准。 SHA 散列函数已被做为 SHACAL 分组密码算法的基础。 SHA-1 的描述 以下是 SHA-1 算法的伪代码: (Initialize variables:) a = h0 = 0x67452301 b = h1 = 0xEFCDAB89 c = h2 = 0x98BADCFE d = h3 = 0x10325476 e = h4 = 0xC3D2E1F0 (Pre-processing:) paddedmessage = (message) append 1 while length(paddedmessage) mod 512 <> 448: paddedmessage = paddedmessage append 0 paddedmessage = paddedmessage append (length(message) in 64-bit format) (Process the message in successive 512-bit chunks:) while 512-bit chunk(s) remain(s): break the current chunk into sixteen 32-bit words w(i), 0 <= i <= 15 (Extend the sixteen 32-bit words into eighty 32-bit words:) for i from 16 to 79: w(i) = (w(i-3) xor w(i-8) xor w(i-14) xor w(i-16)) leftrotate 1 (Main loop:) for i from 0 to 79: temp = (a leftrotate 5) + f(b,c,d) + e + k + w(i) (note: all addition is mod 2^32) where: (0 <= i <= 19): f(b,c,d) = (b and c) or ((not b) and d), k = 0x5A827999 (20 <= i <= 39): f(b,c,d) = (b xor c xor d), k = 0x6ED9EBA1 (40 <= i <= 59): f(b,c,d) = (b and c) or (b and d) or (c and d), k = 0x8F1BBCDC (60 <= i <= 79): f(b,c,d) = (b xor c xor d), k = 0xCA62C1D6 e = d d = c c = b leftrotate 30 b = a a = temp h0 = h0 + a h1 = h1 + b h2 = h2 + c h3 = h3 + d h4 = h4 + e digest = hash = h0 append h1 append h2 append h3 append h4 注意:FIPS PUB 180-1 展示的构想,用以下的公式替代可以增进效能: (0 <= i <= 19): f(b,c,d) = (d xor (b and (c xor d))) (40 <= i <= 59): f(b,c,d) = (b and c) or (d and (b or c)))

琴瑟 2019-12-02 01:26:19 0 浏览量 回答数 0
阿里云大学 云服务器ECS com域名 网站域名whois查询 开发者平台 小程序定制 小程序开发 国内短信套餐包 开发者技术与产品 云数据库 图像识别 开发者问答 阿里云建站 阿里云备案 云市场 万网 阿里云帮助文档 免费套餐 开发者工具 云栖号物联网 小程序开发制作 视频内容分析 企业网站制作 视频集锦 代理记账服务 2020阿里巴巴研发效能峰会 企业建站模板 云效成长地图 高端建站 云栖号弹性计算 阿里云云栖号 云栖号案例 云栖号直播