/** * Load all the hotkeys from the file at filename, marking them as userdefined * if isUserDefined is set. */ static void loadHotkeysFromFile( const char* filename, int isUserDefined, int warnIfNotFound ) { char line[1100]; FILE* f = fopen(filename,"r"); if( !f ) { if( warnIfNotFound ) { fprintf(stderr,_("Failed to open hotkey definition file: %s\n"), filename ); } return; } while ( fgets(line,sizeof(line),f)!=NULL ) { int append = 0; if ( *line=='#' ) continue; char* pt = strchr(line,':'); if ( pt==NULL ) continue; *pt = '\0'; char* keydefinition = pt+1; chomp( keydefinition ); keydefinition = trimspaces( keydefinition ); char* action = line; if( line[0] == '+' ) { append = 1; action++; } hotkeySetFull( action, keydefinition, append, isUserDefined ); } fclose(f); }
int cachecontroltoi(u8* s, u32 l){ u32 ret = -1; u32 p; char buf[1024]; int buflen=1024; if(l >= buflen){ return ret; } memcpy(&buf, s, l); buf[l]=0; //max-age=nn trimspaces(&s, &l); if(l >= 7 && caseinstringcmp(s, 7, (u8*)"max-age", 7) == 0){ //search the = p = getchar((u8*)buf, strlen(buf), '='); if(p > 0){ ret = atoi(buf+p+1); } } return ret; }
int SSDPParser::Parse(struct sockaddr* sender, u8* buf, u32 len){ int linelen; u8* pos = buf; u32 restlen = len; u8* newpos; u32 newlen; u32 colon; int ret = 0; SSDPMessage* msg; std::vector<SSDPMessage*>::const_iterator itmsg; while( (linelen = ReadLine(pos, restlen, &newpos, &newlen)) > 0 ){ if(mType == SSDP_TYPE_UNKNOWN){ //Parse the first line and define the type if( linelen==strlen(SSDP_START_NOTIFY) && memcmp(pos, SSDP_START_NOTIFY, strlen(SSDP_START_NOTIFY)) == 0){ mType = SSDP_TYPE_NOTIFY; }else if( linelen==strlen(SSDP_START_MSEARCH) && memcmp(pos, SSDP_START_MSEARCH, strlen(SSDP_START_MSEARCH)) == 0){ mType = SSDP_TYPE_MSEARCH; }else if( linelen==strlen(SSDP_START_HTTP) && memcmp(pos, SSDP_START_HTTP, strlen(SSDP_START_HTTP)) == 0){ mType = SSDP_TYPE_HTTP; }else{ //unknown goto EXIT; } }else{ //Read the headers //Find the first colon, that is the end of the field name, the rest is the field value colon = 0; while(pos[colon] != ':' && colon < linelen){ colon++; } //Add the header to our collection SSDP_HTTP_HEADER *thisHeader = (SSDP_HTTP_HEADER*)malloc(sizeof(SSDP_HTTP_HEADER)); thisHeader->fieldname = pos; thisHeader->fieldnamelen = colon; thisHeader->fieldvalue = lefttrim(pos+colon+1, linelen-colon-1); thisHeader->fieldvaluelen = (u32)(linelen-(thisHeader->fieldvalue - pos)); //Trim spaces trimspaces(&(thisHeader->fieldname), &(thisHeader->fieldnamelen)); trimspaces(&(thisHeader->fieldvalue), &(thisHeader->fieldvaluelen)); mHeaders.push_back(thisHeader); } pos = newpos; restlen = newlen; } //We have all headers + type, search the message who can process it for(itmsg=mMessages.begin(); itmsg<mMessages.end(); itmsg++){ msg = (SSDPMessage*)*itmsg; if(msg->GetType() == mType){ if(msg->CanProcess(mHeaders) == 1){ //printf("Jeanne: can be process\n"); //Jeanne. 2014.02.26 ret = msg->Process(sender, mHeaders); if(ret != 1){ //0=ok,-1=error,1=not for me, continue... break; } } else{ //printf("Jeanne: can not be process\n"); //Jeanne. 2014.02.26 } } } EXIT: return ret; }