Esempio n. 1
0
// convert to lowercase, possibly extension only
void name2lower (char * s, int ext_only)
{
  if (ext_only)
  {
    char * p;

    if ((p = strrchr(s, '.')) != NULL) str2lower(p);
  }
  else
  {
    str2lower(s);
  }  
}
Esempio n. 2
0
int	my_strcasecmp(char *str1, char *str2)
{
  int	res;
  char	*tstr1;
  char	*tstr2;

  tstr1 = str2lower(str1);
  tstr2 = str2lower(str2);
  res = my_strcmp(tstr1, tstr2);
  free(tstr1);
  free(tstr2);
  return res;
}
Esempio n. 3
0
void make_csv_name_string (unsigned char * dest, unsigned char * s)
{
  char *s1;
  int b;

  strcpy (dest, s);
  str2lower (dest);

  while ((s = strstr (dest+1, "scan")))  // = ist Absicht
  {
    b = s[4] == 's' ? 5 : 4;
    s--;
    do {
      s++;
      *s=s[b];
    } while (*s);  
  }

  s = s1 = dest;
  while (*s)
  {
     if ((*s >= 'a' && *s <= 'z') || (*s >= '0' && *s <= '9'))  *s1++ = *s;
     s++;
  }
  *s1 = 0;
}
Esempio n. 4
0
void CContainerIncludes :: GenerateCode(void)
{
	int iMax;

	iMax = m_Includes.end() - m_Includes.begin();

	CurrentOutput << "\t/*\n\t * Automatically detected headers\n\t */\n";
	for (int i = 0; i < iMax; i++)
	{
		str2lower(m_Includes[i]);
		CurrentOutput << "\t#include \"" << m_Includes[i].c_str() << "\"\n";
	}
}
int hex2bin(char *str, char **hex)
{
	if(!str || !hex)
		return 0;
	
	int len = strlen(str);
	
	if(len % 2 != 0)
		return 0;
	
	int ret = len/2;
	
	*hex = (char *)malloc(ret);
	if((*hex)==0)
		return 0;
	
	char *hexptr = *hex;
	char *lwo = str2lower(str, len);
	char *lw = lwo;
	
	len /= 2;
	
	while(len) {
		int d1 = chr2hex(*lw); lw++;
		int d2 = chr2hex(*lw); lw++;
		
		if(d1<0 || d2<0) {
			free(*hex);
			free(lwo);
			*hex=NULL;
			return -1;
		}
		
		*hexptr = (unsigned char)(d1*16+d2);
		hexptr++;
		len--;
	}
	
	free(lwo);
	return ret;
}
Esempio n. 6
0
int TVars::names_load_from_file(const char *filename){
	FILE *file;
	char buffer[MAX_LEN];
	int type_name;

	if(!(file = fopen(filename, "r"))) return FILE_NOT_OPENED; /*Error: file is no opened*/
	
	while( fscanf(file, "%s", buffer) != -1){
		str2lower(buffer);
		
		if(strstr(buffer, "string" ) != 0) type_name = TYPE_STRING;
		else
			if(strstr(buffer, "int" ) != 0) type_name = TYPE_INT;
			else return TYPE_NOT_RECOGNIZED;	/* invalid variable type (e.c. not int either string) */
		fscanf(file, "%s", buffer);

		var_type[buffer] = type_name;

	}
	fclose(file);
	return 0;
}
Esempio n. 7
0
int main(void) {
    char buff[50];
    DAY the_day = 0x05; /* 오늘 날짜를 구해와 집어넣어 보자. */
/*
    int t_day = 0x05;


    if( (int)the_day == SAT ) {
        puts("a");
    }
    if( t_day == SAT ) {
        puts("b");
    }
*/


    the_day = MON;

/*
    printf("%s\n", xstr( the_day ));        // 이렇게 하면 the_day가 출력되잖아.
*/

    switch ( the_day ) {
        case MON:
            printf("%s\n", str2lower( buff, xstr( MON ), 20 ));    // 이렇게 하면 case마다 동일한 내용이 들어가잖아 //
            break;
        case SUN:
            printf("Sun\n");
            break;
        case SAT:
            printf("Sat\n");
            break;
        default:
            printf("Melong\n");
            break;
    }

    return 0;
}
Esempio n. 8
0
int  __init  logo_setup(char *str)
{

	char	     *ptr=str;
	char 	       sep[2];
	char      *option;
	int     	count=6;
	char	   	find=0;
	logo_object_t	*plogo;


	if(NULL==str)
	{
		return -EINVAL;
	}
	plogo=&aml_logo;
	memset(plogo,0,sizeof(logo_object_t));
	sprintf(plogo->name,LOGO_NAME);
	
	plogo->para.vout_mode = VMODE_INIT_NULL;
	do
	{
		if(!isalpha(*ptr)&&!isdigit(*ptr))
		{
			find=1;
			break;
		}
	}while(*++ptr != '\0');
	if(!find) return -EINVAL;
	sep[0]=*ptr;
	sep[1]='\0' ;
	while((count--) && (option=strsep(&str,sep)))
	{
		str2lower(option);
		install_logo_info(plogo,option); //all has been parsed.
	}
	return 0;
}
Esempio n. 9
0
int main(void) {
    char buff[50];
    DAY the_day;

    the_day = MON;


    switch ( the_day ) {
        case MON:
            printf("%s\n", str2lower( buff, xstr( MON ), 20 ));
            break;
        case SUN:
            printf("Sun\n");
            break;
        case SAT:
            printf("Sat\n");
            break;
        default:
            printf("Melong\n");
            break;
    }

    return 0;
}
Esempio n. 10
0
ItemContent::ItemContent(string json_contents, size_t item_pos, string item_id) {
    ItemId = item_id;
    ItemPos = item_pos;
    vector<string> Genres;
    vector<string> Directors;
    vector<string> Awards;
    vector<string> Actors;
    vector<string> PlotTerms;
    vector<string> Title;

    vector<string> content_values = split(json_contents, "\",\"");
    for (auto raw_token: content_values) {
        string token(raw_token);
        token = str2lower(token);
        token = remove_chars(token, "\"");
        string token_value = get_token_value(token);
        token = remove_chars(token, ",");
        if (token_value != NONE_STR) {
            if (!starts_with(token, "year") && !starts_with(token, "imdbrating"))
                token_value = remove_chars(token_value, INVALID_CHARS);

            if (starts_with(token, "title")) {
                Title = split(token_value, " ");
            }
            else if (starts_with(token, "genre"))
                Genres =  split(token_value, ",");

            /*else if (starts_with(token, "director")) {
                token_value = remove_chars(token_value," ");
                Directors = split(token_value, ",");
            }
            else if (starts_with(token, "actors")) {
                token_value = remove_chars(token_value, " ");
                Actors = split(token_value, ",");
            }*/

            else if (starts_with(token, "country"))
               MainTerms.push_back(token_value);

            else if (starts_with(token, "type")) {
               MainTerms.push_back(token_value);
            }
            
            else if (starts_with(token, "company"))
               MainTerms.push_back(token_value);

            else if (starts_with(token, "awards"))
                Awards = split(token_value, ",");

            else if (starts_with(token, "plot")) {
                token_value = remove_chars(token_value, ",");
                Plot = token_value;
            }
            // Extracting the decade 198X
            else if (starts_with(token, "year")) {
                    Year = stoi(token_value);
                    MainTerms.push_back(token_value.substr(0, token_value.size()-1) + "X");                 
            }
            else if (starts_with(token, "imdbrating")) {
                    imdbRating = stof(token_value);
            }
        }
    }

    
    append_vectors<string>(MainTerms, Title);

    for (size_t i = 0; i <= 5; i++)
        append_vectors<string>(MainTerms, Genres);    

    append_vectors<string>(MainTerms, Awards);


    /*Make the vector too much sparse */

    //append_vectors<string>(MainTerms, Actors);
    
    //append_vectors<string>(MainTerms, Directors);
    

    // Update main terms set to be used during the feature vector build
    for (string term: MainTerms)
        UniqueMainTerms.insert(term);


    // Make a reinforcement of the terms if they exists
    // in the plot too - The bool value stands for reinforcement only
    analyze_terms(PlotTerms, false);

    // Update main terms set to be used during the feature vector build
    append_vectors<string>(MainTerms, PlotTerms);

    for (string term: PlotTerms)
        UniqueMainTerms.insert(term);
    
    Title.clear();
    Genres.clear();
    Directors.clear();
    Actors.clear();
    PlotTerms.clear();
}
Esempio n. 11
0
void ItemContent::analyze_terms(vector<string> &PlotTerms, bool reinforcement_only) {

    unordered_map<string, size_t> terms;
    string top_terms[N_TERMS];

    size_t top_terms_count[N_TERMS];
    // Initilizing
    for (int i = 0; i < N_TERMS; i++) {
        top_terms[i] = EMPTY_STR;
        top_terms_count[i] = SIZE_MAX;
    }

    // Loop through all words in the dictionary
    // Make a reinforcement of the terms if they exists
    // in the plot too
    vector<string> raw_terms = split(Plot, " ");
    for (string term: raw_terms) {
        term = str2lower(term);
        if ( STOP_WORDS.find(term) == STOP_WORDS.end() ) {
    	    if (UniqueMainTerms.find(term) != UniqueMainTerms.end())
                PlotTerms.push_back(term);

            else if (!reinforcement_only) {
                if (terms.find(term) == terms.end()) {
                    terms.insert({term, 1});
                }
                else
                    terms.at(term)++;          
            }  
        }
        
    }

    if (!reinforcement_only) {
        for (auto term_pair: terms) {
            // Looking for the N TERMS with most occurrences
            size_t hold_count = term_pair.second;
            string hold_term = term_pair.first;

            for (int i = 0; i < N_TERMS; i++) {
                if (hold_count < top_terms_count[i]) {
                    // save actual value from the position
                    size_t aux_count = top_terms_count[i];
                    string aux_term = top_terms[i];

                    //switch to the hold_values
                    top_terms_count[i] = hold_count;
                    top_terms[i] = hold_term;

                    //hold the replaced values
                    hold_count = aux_count;
                    hold_term = aux_term;
                }
            }
        }

        // Transferring the most common terms to the attributes
        for (int i = 0; i < N_TERMS; i++)
            if (top_terms[i] != EMPTY_STR){
    //            plot_pair_terms.push_back(make_pair(top_terms[i], top_terms_count[i]));
                PlotTerms.push_back(top_terms[i]);
                //DEBUG_ONLY(cout << i << "th pair: <" << top_terms[i] << ',' << top_terms_count[i] << '>' << endl);
            }
    }
    terms.clear();
    raw_terms.clear();

}
Esempio n. 12
0
/* ------------------------------------------------------------- */
PJXSQL jx_sqlOpen(PUCHAR sqlstmt , PJXNODE pSqlParms)
{

   PNPMPARMLISTADDRP pParms = _NPMPARMLISTADDR();
   // LONG    format   =  (pParms->OpDescList->NbrOfParms >= 3) ? formatP : 0;  // Status & result object

   LONG   attrParm;
   LONG   i;
//   PJXSQL pSQL = jx_sqlNewStatement (pParms->OpDescList->NbrOfParms >= 2 ? pSqlParms  :NULL);
   PJXSQL pSQL = jx_sqlNewStatement (NULL);

   pSQL->rc = SQLAllocStmt(pConnection->hdbc, &pSQL->hstmt);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return NULL; // we have an error
   }

   attrParm = SQL_TRUE;
   pSQL->rc = SQLSetStmtAttr  (pSQL->hstmt, SQL_ATTR_CURSOR_SCROLLABLE , &attrParm  , 0);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return NULL; // we have an error
   }

   /*
   attrParm = SQL_TRUE;
   pSQL->rc = SQLSetStmtAttr  (pSQL->hstmt, SQL_ATTR_EXTENDED_COL_INFO , &attrParm  , 0);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return NULL; // we have an error
   }
   */

   attrParm = SQL_CONCUR_READ_ONLY;
   pSQL->rc = SQLSetStmtAttr  (pSQL->hstmt, SQL_ATTR_CONCURRENCY , &attrParm  , 0);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return NULL; // we have an error
   }

   // run  the  statement in "sqlstr"
   if (pParms->OpDescList->NbrOfParms >= 2 && pSqlParms ) {
      UCHAR sqlTempStmt[32766];
      strFormat(sqlTempStmt , sqlstmt , pSqlParms);
      pSQL->sqlstmt = strdup(sqlTempStmt);
   } else {
      pSQL->sqlstmt = strdup(sqlstmt);
   }

   pSQL->rc = SQLExecDirect (pSQL->hstmt, pSQL->sqlstmt, SQL_NTS);

   if (pSQL->rc != SQL_SUCCESS && pSQL->rc != SQL_NO_DATA_FOUND) {
     check_error (pSQL);
     return NULL; // we have an error
   }


   // Number of rows? .. No does not work :(
   /*
   SQLGetDiagField(SQL_HANDLE_STMT,pSQL->hstmt, 0 ,SQL_DIAG_ROW_COUNT,&pSQL->rowcount,0, NULL);
   */

   /*
   // Row count is only affected row in a "delete" or "update" ..TODO find a solution for select
   pSQL->rc = SQLRowCount (pSQL->hstmt, &pSQL->rowcount);
   if (pSQL->rc != SQL_SUCCESS ) {
     check_error (pSQL);
     return; // we have an error
   }
   */

   pSQL->rc = SQLNumResultCols (pSQL->hstmt, &pSQL->nresultcols);
   if (pSQL->rc != SQL_SUCCESS ) {
      check_error (pSQL);
      return NULL; // we have an error
   }

   for (i = 0; i < pSQL->nresultcols; i++) {
      PJXCOL pCol = &pSQL->cols[i];

      SQLDescribeCol (pSQL->hstmt, i+1, pCol->colname, sizeof (pCol->colname),
          &pCol->colnamelen, &pCol->coltype, &pCol->collen, &pCol->scale, &pCol->nullable);

      pCol->colname[pCol->colnamelen] = '\0';

      if (OFF == jx_IsTrue (pConnection->pOptions ,"uppercasecolname")) {
         str2lower  (pCol->colname , pCol->colname);
      }

      // get display label  for column
      /****************
      pSQL->rc = SQLColAttributes (hstmt, i+1, SQL_DESC_LABEL, Label , sizeof(Label)  , &len , NULL);
      if (pSQL->rc != SQL_SUCCESS ) {
        check_error (pSQL);
        return; // we have an error
      }
      ***********/


      // get display length for column
      SQLColAttributes (pSQL->hstmt, i+1, SQL_DESC_PRECISION, NULL, 0,NULL, &pCol->displaysize);

      // set column length to max of display length, and column name
      //   length.  Plus one byte for null terminator
      // collen[i] = max(displaysize, collen[i]);
      // collen[i] = max(collen[i], strlen((char *) colname) ) + 1;

      // printf ("%-*.*s", collen[i], collen[i], colname);

      // allocate memory to bind column

      // bind columns to program vars, converting all types to CHAR
      //*SQLBindCol (hstmt, i+1, SQL_C_CHAR, data[i], collen[i], &outlen[i]);
      switch( pCol->coltype) {
         case SQL_BLOB:
         case SQL_CLOB:
 //           pCol->collen = pCol->displaysize * 2;
 //           pCol->data = (SQLCHAR *) malloc (pCol->collen);
            pCol->collen = 1048576;  // 1MEGABYTES
            pCol->data = (SQLCHAR *) malloc (pCol->collen);  // 1MEGABYTES
            SQLBindCol (pSQL->hstmt, i+1, SQL_C_BINARY , pCol->data, pCol->collen, &pCol->outlen);
            break;

         case SQL_WCHAR:
         case SQL_WVARCHAR:
         case SQL_GRAPHIC:
         case SQL_VARGRAPHIC:
            pCol->collen = pCol->displaysize * 2;
            pCol->data = (SQLCHAR *) malloc (pCol->collen);
            SQLBindCol (pSQL->hstmt, i+1, pCol->coltype, pCol->data, pCol->collen, &pCol->outlen);
            break;

         default:
            pCol->collen = pCol->displaysize + 3; // + . and , and zero term
            pCol->data = (SQLCHAR *) malloc (pCol->collen);
            SQLBindCol (pSQL->hstmt, i+1, SQL_C_CHAR, pCol->data, pCol->collen, &pCol->outlen);
            break;
      }
      if (pCol->coltype >= SQL_NUMERIC && pCol->coltype <= SQL_DOUBLE) {
         pCol->nodeType = JX_LITERAL;
      } else {
         pCol->nodeType = JX_VALUE;
      }
   }


   return pSQL;

}
Esempio n. 13
0
static int cmd_rtcdev_set_time(struct vmm_chardev *cdev, const char *name,
				int targc, char **targv)
{
	int rc;
	char * s;
	struct rtc_time tm;
	struct rtc_device *rtc = rtc_device_find(name);

	if (!rtc) {
		vmm_cprintf(cdev, "Error: cannot find rtc %s\n", name);
		return VMM_EFAIL;
	}

	s = targv[0];
	rc = 0;
	tm.tm_hour = 0;
	tm.tm_min = 0;
	tm.tm_sec = 0;
	while (*s) {
		if (*s == ':') {
			rc++;
		} else if ('0' <= *s && *s <= '9') {
			switch(rc) {
			case 0:
				tm.tm_hour = tm.tm_hour * 10 + (*s - '0');
				break;
			case 1:
				tm.tm_min = tm.tm_min * 10 + (*s - '0');
				break;
			case 2:
				tm.tm_sec = tm.tm_sec * 10 + (*s - '0');
				break;
			default:
				break;
			};
		}
		s++;
	}
	rc = 0;
	tm.tm_mday = atoi(targv[1]);
	str2lower(targv[2]);
	if (strcmp(targv[2], "jan") == 0) {
		tm.tm_mon = 0;
	} else if (strcmp(targv[2], "feb") == 0) {
		tm.tm_mon = 1;
	} else if (strcmp(targv[2], "mar") == 0) {
		tm.tm_mon = 2;
	} else if (strcmp(targv[2], "apr") == 0) {
		tm.tm_mon = 3;
	} else if (strcmp(targv[2], "may") == 0) {
		tm.tm_mon = 4;
	} else if (strcmp(targv[2], "jun") == 0) {
		tm.tm_mon = 5;
	} else if (strcmp(targv[2], "jul") == 0) {
		tm.tm_mon = 6;
	} else if (strcmp(targv[2], "aug") == 0) {
		tm.tm_mon = 7;
	} else if (strcmp(targv[2], "sep") == 0) {
		tm.tm_mon = 8;
	} else if (strcmp(targv[2], "oct") == 0) {
		tm.tm_mon = 9;
	} else if (strcmp(targv[2], "nov") == 0) {
		tm.tm_mon = 10;
	} else if (strcmp(targv[2], "dec") == 0) {
		tm.tm_mon = 11;
	} else {
		tm.tm_mon = atoi(targv[2]);
	}
	tm.tm_year = atoi(targv[3]) - 1900;

	if (!rtc_valid_tm(&tm)) {
		vmm_cprintf(cdev, "Error: invalid date-time\n");
		return VMM_EFAIL;
	}

	rc = rtc_device_set_time(rtc, &tm);
	if (rc) {
		vmm_cprintf(cdev, "Error: set_time failed for rtc %s\n", name);
		return rc;
	}

	return VMM_OK;
}
Esempio n. 14
0
int parseurl::ParseUrl(char *url, int *protocol, char **host, unsigned int *port, char **playpath, char **app)
{
	assert(url != 0 && protocol != 0 && host != 0 && port != 0 && playpath != 0 && app != 0);

	_log_ptr->Log(LOGDEBUG, "Parsing...");

	*protocol = 0; // default: RTMP

	// Old School Parsing
	char *lw = str2lower(url, 6);
	char *temp;

	// look for usual :// pattern
	char *p = strstr(url, "://");
	int len = (int)(p-url);
	if(p == 0) {
		_log_ptr->Log(LOGWARNING, "RTMP URL: No :// in url!");
		free(lw);
		return 0;
	}

	if(len == 4 && strncmp(lw, "rtmp", 4)==0)
		*protocol = RTMP_PROTOCOL_RTMP;
	else if(len == 5 && strncmp(lw, "rtmpt", 5)==0)
		*protocol = RTMP_PROTOCOL_RTMPT;
	else if(len == 5 && strncmp(lw, "rtmps", 5)==0)
	        *protocol = RTMP_PROTOCOL_RTMPS;
	else if(len == 5 && strncmp(lw, "rtmpe", 5)==0)
	        *protocol = RTMP_PROTOCOL_RTMPE;
	else if(len == 5 && strncmp(lw, "rtmfp", 5)==0)
	        *protocol = RTMP_PROTOCOL_RTMFP;
	else if(len == 6 && strncmp(lw, "rtmpte", 6)==0)
	        *protocol = RTMP_PROTOCOL_RTMPTE;
	else {
		_log_ptr->Log(LOGWARNING, "Unknown protocol!\n");
		goto parsehost;
	}

	_log_ptr->Log(LOGDEBUG, "Parsed protocol: %d", *protocol);

parsehost:
	free(lw);

	// lets get the hostname
	p+=3;

	// check for sudden death
	if(*p==0) {
		_log_ptr->Log(LOGWARNING, "No hostname in URL!");
		return 0;
	}

	int iEnd   = strlen(p);
	int iCol   = iEnd+1;
	int iQues  = iEnd+1;
	int iSlash = iEnd+1;

	if((temp=strstr(p, ":"))!=0)
		iCol = temp-p;
	if((temp=strstr(p, "?"))!=0)
	    iQues = temp-p;
	if((temp=strstr(p, "/"))!=0)
	    iSlash = temp-p;

	int min = iSlash < iEnd ? iSlash : iEnd+1;
	min = iQues   < min ? iQues   : min;

	int hostlen = iCol < min ? iCol : min;

	if(min < 256) {
		*host = (char *)malloc((hostlen+1)*sizeof(char));
		strncpy(*host, p, hostlen);
		(*host)[hostlen]=0;

		_log_ptr->Log(LOGDEBUG, "Parsed host    : %s", *host);
	} else {
		_log_ptr->Log(LOGWARNING, "Hostname exceeds 255 characters!");
	}

	p+=hostlen; iEnd-=hostlen;

	// get the port number if available
	if(*p == ':') {
		p++; iEnd--;

		int portlen = min-hostlen-1;
		if(portlen < 6) {
			char portstr[6];
			strncpy(portstr,p,portlen);
			portstr[portlen]=0;

			*port = atoi(portstr);
			if(*port == 0)
				*port = 1935;

			_log_ptr->Log(LOGDEBUG, "Parsed port    : %d", *port);
		} else {
			_log_ptr->Log(LOGWARNING, "Port number is longer than 5 characters!");
		}

		p+=portlen; iEnd-=portlen;
	}

	if(*p != '/') {
		_log_ptr->Log(LOGWARNING, "No application or playpath in URL!");
		return 1;
	}
	p++; iEnd--;

	// parse application
	//
	// rtmp://host[:port]/app[/appinstance][/...]
	// application = app[/appinstance]
	int iSlash2 = iEnd+1; // 2nd slash
    int iSlash3 = iEnd+1; // 3rd slash

    if((temp=strstr(p, "/"))!=0)
      	iSlash2 = temp-p;

	if((temp=strstr(p, "?"))!=0)
	    iQues = temp-p;

	if(iSlash2 < iEnd)
		if((temp=strstr(p+iSlash2+1, "/"))!=0)
			iSlash3 = temp-p;

	//Log(LOGDEBUG, "p:%s, iEnd: %d\niSlash : %d\niSlash2: %d\niSlash3: %d", p, iEnd, iSlash, iSlash2, iSlash3);

	int applen = iEnd+1; // ondemand, pass all parameters as app
	int appnamelen = 8; // ondemand length

	if(iQues < iEnd && strstr(p, "slist=")) { // whatever it is, the '?' and slist= means we need to use everything as app and parse plapath from slist=
		appnamelen = iQues;
		applen = iEnd+1; // pass the parameters as well
	} else if(strncmp(p, "ondemand/", 9)==0) {
		// app = ondemand/foobar, only pass app=ondemand
		applen = 8;
        }
	else { // app!=ondemand, so app is app[/appinstance]
		appnamelen = iSlash2 < iEnd ? iSlash2 : iEnd;
        if(iSlash3 < iEnd)
            appnamelen = iSlash3;

		applen = appnamelen;
	}

	*app = (char *)malloc((applen+1)*sizeof(char));
	strncpy(*app, p, applen);
	(*app)[applen]=0;
	_log_ptr->Log(LOGDEBUG, "Parsed app     : %s", *app);

	p += appnamelen;
	iEnd -= appnamelen;

	if (*p == '/') {
		p += 1;
		iEnd -= 1;
	}

	*playpath = ParsePlaypath(p);

    return 1;
}
Esempio n. 15
0
int search_ALGO(char *ALGO_NAME[], char* algo)  {
	int i;
	for(i=0; i<NumAlgo; i++)
		if(ALGO_NAME[i] && !strcmp(str2lower(ALGO_NAME[i]),str2lower(algo))) return i;
	return -1;
}
Esempio n. 16
0
bool ParseUrl(char *url, int *protocol, char **host, unsigned int *port, char **playpath, char **app)
{
	assert(url != 0 && protocol != 0 && host != 0 && port != 0 && playpath != 0 && app != 0);
	
	Log(LOGDEBUG, "Parsing...");
	
	*protocol = 0; // default: RTMP
	
	// Old School Parsing
	char *lw = str2lower(url, 6);
	char *temp;
	
	// look for usual :// pattern
	char *p = strstr(url, "://");
	int len = (int)(p-url);
	if(p == 0) {
		Log(LOGWARNING, "RTMP URL: No :// in url!");
		free(lw);
		return false;
	}
	
	if(len == 4 && strncmp(lw, "rtmp", 4)==0)
		*protocol = RTMP_PROTOCOL_RTMP;
	else if(len == 5 && strncmp(lw, "rtmpt", 5)==0)
		*protocol = RTMP_PROTOCOL_RTMPT;
	else if(len == 5 && strncmp(lw, "rtmps", 5)==0)
		*protocol = RTMP_PROTOCOL_RTMPS;
	else if(len == 5 && strncmp(lw, "rtmpe", 5)==0)
		*protocol = RTMP_PROTOCOL_RTMPE;
	else if(len == 5 && strncmp(lw, "rtmfp", 5)==0)
		*protocol = RTMP_PROTOCOL_RTMFP;
	else if(len == 6 && strncmp(lw, "rtmpte", 6)==0)
		*protocol = RTMP_PROTOCOL_RTMPTE;
	else {
		Log(LOGWARNING, "Unknown protocol!\n");
		goto parsehost;
	}
	
	Log(LOGDEBUG, "Parsed protocol: %d", *protocol);
	
parsehost:
	free(lw);
	
	// lets get the hostname
	p+=3;
	
	// check for sudden death
	if(*p==0) {
		Log(LOGWARNING, "No hostname in URL!");		
		return false;
	}
	
	int iEnd   = strlen(p);
	int iCol   = iEnd+1; 
	int iQues  = iEnd+1;
	int iSlash = iEnd+1;
	
	if((temp=strstr(p, ":"))!=0)
		iCol = temp-p;
	if((temp=strstr(p, "?"))!=0)
		iQues = temp-p;
	if((temp=strstr(p, "/"))!=0)
		iSlash = temp-p;
	
	int min = iSlash < iEnd ? iSlash : iEnd+1;
	min = iQues   < min ? iQues   : min;
	
	int hostlen = iCol < min ? iCol : min;
	
	if(min < 256) {
		*host = (char *)malloc((hostlen+1)*sizeof(char));
		strncpy(*host, p, hostlen);
		(*host)[hostlen]=0;
		
		Log(LOGDEBUG, "Parsed host    : %s", *host);
	} else {
		Log(LOGWARNING, "Hostname exceeds 255 characters!");
	}
	
	p+=hostlen; iEnd-=hostlen;
	
	// get the port number if available
	if(*p == ':') {
		p++; iEnd--;
		
		int portlen = min-hostlen-1;
		if(portlen < 6) {
			char portstr[6];
			strncpy(portstr,p,portlen);
			portstr[portlen]=0;
			
			*port = atoi(portstr);
			if(*port == 0)
				*port = 1935;
			
			Log(LOGDEBUG, "Parsed port    : %d", *port);
		} else {
			Log(LOGWARNING, "Port number is longer than 5 characters!");
		}
		
		p+=portlen; iEnd-=portlen;
	}
	
	if(*p != '/') {
		Log(LOGWARNING, "No application or playpath in URL!");
		return true;
	}
	p++; iEnd--;
	
	// parse application
	//
	// rtmp://host[:port]/app[/appinstance][/...]
	// application = app[/appinstance]
	int iSlash2 = iEnd+1; // 2nd slash
	int iSlash3 = iEnd+1; // 3rd slash
	
	if((temp=strstr(p, "/"))!=0)
		iSlash2 = temp-p;
	
	if((temp=strstr(p, "?"))!=0)
		iQues = temp-p;
	
	if(iSlash2 < iEnd)
		if((temp=strstr(p+iSlash2+1, "/"))!=0)
			iSlash3 = temp-p;
	
	//Log(LOGDEBUG, "p:%s, iEnd: %d\niSlash : %d\niSlash2: %d\niSlash3: %d", p, iEnd, iSlash, iSlash2, iSlash3);
	
	int applen = iEnd+1; // ondemand, pass all parameters as app
	int appnamelen = 8; // ondemand length
	
	if(iQues < iEnd && strstr(p, "slist=")) { // whatever it is, the '?' and slist= means we need to use everything as app and parse plapath from slist=
		appnamelen = iQues;
		applen = iEnd+1; // pass the parameters as well
	}
	else if(strncmp(p, "ondemand/", 9)==0) {
		// app = ondemand/foobar, only pass app=ondemand
		applen = 8;
	}
	else { // app!=ondemand, so app is app[/appinstance]
		appnamelen = iSlash2 < iEnd ? iSlash2 : iEnd;
		if(iSlash3 < iEnd)
			appnamelen = iSlash3;
		
		applen = appnamelen;
	}
	
	*app = (char *)malloc((applen+1)*sizeof(char));
	strncpy(*app, p, applen);
	(*app)[applen]=0;
	Log(LOGDEBUG, "Parsed app     : %s", *app);
	
	p += appnamelen; 
	iEnd -= appnamelen;
	
	// parse playpath
	int iPlaypathPos = -1;
	int iPlaypathLen = -1;
	
	bool bAddMP4 = false; // used to add at the end mp4: in front of the playpath
	
	// here filter out semicolon added parameters, e.g. slist=bla...;abc=def
	//if((temp=strstr(p, ";"))!=0)
	//	iEnd = temp-p-1;
	
	if(*p=='?' && (temp=strstr(p, "slist="))!=0) {
		iPlaypathPos = temp-p+6;
		
		int iAnd = iEnd+1;
		if((temp=strstr(p+iPlaypathPos, "&"))!=0)
			iAnd = temp-p;
		if(iAnd < iEnd)
			iPlaypathLen = iAnd-iPlaypathPos;
		else
			iPlaypathLen = iEnd-iPlaypathPos; // +1
	} else { // no slist parameter, so take string after applen 
		if(iEnd > 0) {
			iPlaypathPos = 1;
			iPlaypathLen = iEnd-iPlaypathPos;//+1;
			
			// filter .flv from playpath specified with slashes: rtmp://host/app/path.flv
			if(iPlaypathLen >=4) {
				if(strncmp(&p[iPlaypathPos+iPlaypathLen-4], ".f4v", 4)==0 || strncmp(&p[iPlaypathPos+iPlaypathLen-4], ".mp4", 4)==0) {
					bAddMP4 = true;
				} else if(strncmp(&p[iPlaypathPos+iPlaypathLen-4], ".flv", 4)==0) {
					iPlaypathLen-=4;
				}
			}
		} else {
			Log(LOGERROR, "No playpath found!");
		}
	}
	
	if(iPlaypathLen > -1) {
		*playpath = (char *)malloc((iPlaypathLen+(bAddMP4?4:0)+1)*sizeof(char));
		char *playpathptr = *playpath;
		
		if(bAddMP4 && strncmp(&p[iPlaypathPos], "mp4:", 4)!=0) {
			strcpy(playpathptr, "mp4:");
			playpathptr+=4;
		}
		
		strncpy(playpathptr, &p[iPlaypathPos], iPlaypathLen);
		playpathptr[iPlaypathLen]=0;
		
		Log(LOGDEBUG, "Parsed playpath: %s", *playpath);
	} else {
		Log(LOGWARNING, "No playpath in URL!");
	}
	
	return true;
}
Esempio n. 17
0
static int cmd_wallclock_set_time(struct vmm_chardev *cdev, 
				  int targc, char **targv)
{
	int rc;
	char * s;
	struct vmm_timeinfo ti;
	struct vmm_timeval tv;
	struct vmm_timezone tz;

	if (targc > 4) {
		s = targv[4];
		rc = 0;
		tz.tz_minuteswest = 0;
		tz.tz_dsttime = 0;
		if (*s == '-' || *s == '+') {
			s++;
		}
		while (*s) {
			if (*s == ':') {
				rc++;
			} else if ('0' <= *s && *s <= '9') {
				switch(rc) {
				case 0:
					tz.tz_dsttime = 
					tz.tz_dsttime * 10 + (*s - '0');
					break;
				case 1:
					tz.tz_minuteswest = 
					tz.tz_minuteswest * 10 + (*s - '0');
					break;
				default:
					break;
				};
			}
			s++;
		}
		rc = 0;
		tz.tz_minuteswest += tz.tz_dsttime * 60;
		tz.tz_dsttime = 0;
		s = targv[4];
		if (*s == '-') {
			tz.tz_minuteswest *= -1;
		}

		if ((rc = vmm_wallclock_set_timezone(&tz))) {
			vmm_cprintf(cdev, "Error: set_timezone failed\n");
			return rc;
		}
	}

	s = targv[0];
	rc = 0;
	ti.tm_hour = 0;
	ti.tm_min = 0;
	ti.tm_sec = 0;
	while (*s) {
		if (*s == ':') {
			rc++;
		} else if ('0' <= *s && *s <= '9') {
			switch(rc) {
			case 0:
				ti.tm_hour = ti.tm_hour * 10 + (*s - '0');
				break;
			case 1:
				ti.tm_min = ti.tm_min * 10 + (*s - '0');
				break;
			case 2:
				ti.tm_sec = ti.tm_sec * 10 + (*s - '0');
				break;
			default:
				break;
			};
		}
		s++;
	}
	rc = 0;
	ti.tm_mday = atoi(targv[1]);
	str2lower(targv[2]);
	if (strcmp(targv[2], "jan") == 0) {
		ti.tm_mon = 0;
	} else if (strcmp(targv[2], "feb") == 0) {
		ti.tm_mon = 1;
	} else if (strcmp(targv[2], "mar") == 0) {
		ti.tm_mon = 2;
	} else if (strcmp(targv[2], "apr") == 0) {
		ti.tm_mon = 3;
	} else if (strcmp(targv[2], "may") == 0) {
		ti.tm_mon = 4;
	} else if (strcmp(targv[2], "jun") == 0) {
		ti.tm_mon = 5;
	} else if (strcmp(targv[2], "jul") == 0) {
		ti.tm_mon = 6;
	} else if (strcmp(targv[2], "aug") == 0) {
		ti.tm_mon = 7;
	} else if (strcmp(targv[2], "sep") == 0) {
		ti.tm_mon = 8;
	} else if (strcmp(targv[2], "oct") == 0) {
		ti.tm_mon = 9;
	} else if (strcmp(targv[2], "nov") == 0) {
		ti.tm_mon = 10;
	} else if (strcmp(targv[2], "dec") == 0) {
		ti.tm_mon = 11;
	} else {
		ti.tm_mon = atoi(targv[2]);
		/* Directly entered month will have range 1-12. */
		ti.tm_mon--;
	}
	ti.tm_year = atoi(targv[3]) - 1900;

	tv.tv_sec = vmm_wallclock_mktime(ti.tm_year + 1900, 
					 ti.tm_mon + 1, 
					 ti.tm_mday, 
					 ti.tm_hour, 
					 ti.tm_min, 
					 ti.tm_sec);
	tv.tv_nsec = 0;

	if ((rc = vmm_wallclock_set_local_time(&tv))) {
		vmm_cprintf(cdev, "Error: set_local_time failed\n");
		return rc;
	}

	return VMM_OK;
}